2014-12-01 23:55:08 +01:00
|
|
|
|
// swad_nickname.c: Users' nicknames
|
|
|
|
|
|
|
|
|
|
/*
|
|
|
|
|
SWAD (Shared Workspace At a Distance),
|
|
|
|
|
is a web platform developed at the University of Granada (Spain),
|
|
|
|
|
and used to support university teaching.
|
|
|
|
|
|
|
|
|
|
This file is part of SWAD core.
|
2024-02-07 00:40:28 +01:00
|
|
|
|
Copyright (C) 1999-2024 Antonio Ca<EFBFBD>as Vargas
|
2014-12-01 23:55:08 +01:00
|
|
|
|
|
|
|
|
|
This program is free software: you can redistribute it and/or modify
|
|
|
|
|
it under the terms of the GNU Affero General Public License as
|
|
|
|
|
published by the Free Software Foundation, either version 3 of the
|
|
|
|
|
License, or (at your option) any later version.
|
|
|
|
|
|
|
|
|
|
This program is distributed in the hope that it will be useful,
|
|
|
|
|
but WITHOUT ANY WARRANTY; without even the implied warranty of
|
|
|
|
|
MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
|
|
|
|
|
GNU Affero General Public License for more details.
|
|
|
|
|
|
|
|
|
|
You should have received a copy of the GNU Affero General Public License
|
|
|
|
|
along with this program. If not, see <http://www.gnu.org/licenses/>.
|
|
|
|
|
*/
|
|
|
|
|
/*****************************************************************************/
|
|
|
|
|
/********************************* Headers ***********************************/
|
|
|
|
|
/*****************************************************************************/
|
|
|
|
|
|
|
|
|
|
#include <string.h> // For string functions
|
|
|
|
|
|
2014-12-12 22:39:55 +01:00
|
|
|
|
#include "swad_account.h"
|
2022-11-06 18:11:10 +01:00
|
|
|
|
#include "swad_action_list.h"
|
2022-10-19 18:07:49 +02:00
|
|
|
|
#include "swad_alert.h"
|
2018-10-15 14:07:12 +02:00
|
|
|
|
#include "swad_box.h"
|
2014-12-01 23:55:08 +01:00
|
|
|
|
#include "swad_database.h"
|
2018-11-09 20:47:39 +01:00
|
|
|
|
#include "swad_form.h"
|
2014-12-01 23:55:08 +01:00
|
|
|
|
#include "swad_global.h"
|
2019-10-23 19:05:05 +02:00
|
|
|
|
#include "swad_HTML.h"
|
2021-09-30 00:04:29 +02:00
|
|
|
|
#include "swad_nickname_database.h"
|
2014-12-01 23:55:08 +01:00
|
|
|
|
#include "swad_parameter.h"
|
|
|
|
|
#include "swad_QR.h"
|
|
|
|
|
#include "swad_user.h"
|
|
|
|
|
|
|
|
|
|
/*****************************************************************************/
|
|
|
|
|
/************** External global variables from others modules ****************/
|
|
|
|
|
/*****************************************************************************/
|
|
|
|
|
|
|
|
|
|
extern struct Globals Gbl;
|
|
|
|
|
|
|
|
|
|
/*****************************************************************************/
|
|
|
|
|
/***************************** Private variables *****************************/
|
|
|
|
|
/*****************************************************************************/
|
|
|
|
|
|
2018-10-16 01:36:13 +02:00
|
|
|
|
const char *Nck_NICKNAME_SECTION_ID = "nickname_section";
|
|
|
|
|
|
2014-12-01 23:55:08 +01:00
|
|
|
|
/*****************************************************************************/
|
|
|
|
|
/***************************** Private prototypes ****************************/
|
|
|
|
|
/*****************************************************************************/
|
|
|
|
|
|
2023-04-04 13:46:51 +02:00
|
|
|
|
static void Nck_ShowFormChangeUsrNickname (Usr_MeOrOther_t MeOrOther,
|
2018-10-16 01:36:13 +02:00
|
|
|
|
bool IMustFillNickname);
|
2023-03-10 00:13:55 +01:00
|
|
|
|
static void Nck_PutParsRemoveMyNick (void *Nick);
|
|
|
|
|
static void Nck_PutParsRemoveOtherNick (void *Nick);
|
2018-10-15 14:07:12 +02:00
|
|
|
|
|
2023-04-04 13:46:51 +02:00
|
|
|
|
static void Nck_ChangeUsrNick (struct Usr_Data *UsrDat);
|
2014-12-01 23:55:08 +01:00
|
|
|
|
|
|
|
|
|
/*****************************************************************************/
|
|
|
|
|
/********* Check whether a nickname (with initial arroba) if valid ***********/
|
|
|
|
|
/*****************************************************************************/
|
|
|
|
|
|
2021-02-15 22:49:44 +01:00
|
|
|
|
bool Nck_CheckIfNickWithArrIsValid (const char *NickWithArr)
|
2014-12-01 23:55:08 +01:00
|
|
|
|
{
|
2021-10-21 20:33:55 +02:00
|
|
|
|
char CopyOfNick[Nck_MAX_BYTES_NICK_WITH_ARROBA + 1];
|
2014-12-01 23:55:08 +01:00
|
|
|
|
unsigned Length;
|
|
|
|
|
const char *Ptr;
|
|
|
|
|
|
|
|
|
|
/***** A nickname must start by '@' *****/
|
2021-02-15 22:49:44 +01:00
|
|
|
|
if (NickWithArr[0] != '@') // It's not a nickname
|
2014-12-01 23:55:08 +01:00
|
|
|
|
return false;
|
|
|
|
|
|
|
|
|
|
/***** Make a copy of nickname *****/
|
2021-10-21 20:33:55 +02:00
|
|
|
|
Str_Copy (CopyOfNick,NickWithArr,sizeof (CopyOfNick) - 1);
|
|
|
|
|
Str_RemoveLeadingArrobas (CopyOfNick);
|
|
|
|
|
Length = strlen (CopyOfNick); // Leading arrobas already removed
|
2014-12-01 23:55:08 +01:00
|
|
|
|
|
|
|
|
|
/***** A nick (without arroba) must have a number of characters
|
2021-10-21 20:33:55 +02:00
|
|
|
|
Nck_MIN_CHARS_NICK_WITHOUT_ARROBA <= Length <= Nck_MAX_CHARS_NICK_WITHOUT_ARROBA *****/
|
|
|
|
|
if (Length < Nck_MIN_CHARS_NICK_WITHOUT_ARROBA ||
|
|
|
|
|
Length > Nck_MAX_CHARS_NICK_WITHOUT_ARROBA)
|
2014-12-01 23:55:08 +01:00
|
|
|
|
return false;
|
|
|
|
|
|
|
|
|
|
/***** A nick can have digits, letters and '_' *****/
|
2021-10-21 20:33:55 +02:00
|
|
|
|
for (Ptr = CopyOfNick; // Leading arrobas already removed
|
2014-12-01 23:55:08 +01:00
|
|
|
|
*Ptr;
|
|
|
|
|
Ptr++)
|
2021-11-24 20:54:54 +01:00
|
|
|
|
if (!Str_ChIsAlphaNum (*Ptr))
|
2014-12-01 23:55:08 +01:00
|
|
|
|
return false;
|
|
|
|
|
|
|
|
|
|
return true;
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
/*****************************************************************************/
|
|
|
|
|
/************** Get user's code of a user from his/her nickname **************/
|
|
|
|
|
/*****************************************************************************/
|
2015-03-05 01:55:46 +01:00
|
|
|
|
// Nickname may have leading '@'
|
2014-12-01 23:55:08 +01:00
|
|
|
|
// Returns true if nickname found in database
|
|
|
|
|
|
2023-02-08 14:25:42 +01:00
|
|
|
|
long Nck_GetUsrCodFromNickname (const char *NickWithArr)
|
2014-12-01 23:55:08 +01:00
|
|
|
|
{
|
2021-10-21 20:33:55 +02:00
|
|
|
|
char CopyOfNick[Nck_MAX_BYTES_NICK_WITH_ARROBA + 1];
|
2021-04-05 23:45:24 +02:00
|
|
|
|
|
|
|
|
|
/***** Trivial check 1: nickname should be not null *****/
|
2021-10-21 20:33:55 +02:00
|
|
|
|
if (!NickWithArr)
|
2021-04-05 23:45:24 +02:00
|
|
|
|
return -1L;
|
|
|
|
|
|
|
|
|
|
/***** Trivial check 2: nickname should be not empty *****/
|
2021-10-21 20:33:55 +02:00
|
|
|
|
if (!NickWithArr[0])
|
2021-04-05 23:45:24 +02:00
|
|
|
|
return -1L;
|
|
|
|
|
|
2021-09-30 20:11:00 +02:00
|
|
|
|
/***** Remove leading arrobas *****/
|
2021-10-21 20:33:55 +02:00
|
|
|
|
Str_Copy (CopyOfNick,NickWithArr,sizeof (CopyOfNick) - 1);
|
|
|
|
|
Str_RemoveLeadingArrobas (CopyOfNick);
|
2021-04-05 23:45:24 +02:00
|
|
|
|
|
|
|
|
|
/***** Get user's code from database *****/
|
2021-10-21 20:33:55 +02:00
|
|
|
|
return Nck_DB_GetUsrCodFromNickname (CopyOfNick);
|
2014-12-01 23:55:08 +01:00
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
/*****************************************************************************/
|
2024-01-30 00:20:11 +01:00
|
|
|
|
/******************* Put form to request the new nickname ********************/
|
|
|
|
|
/*****************************************************************************/
|
|
|
|
|
|
|
|
|
|
void Nck_PutFormToGetNewNickname (const char *NewNickWithoutArr)
|
|
|
|
|
{
|
|
|
|
|
extern const char *Txt_Nickname;
|
|
|
|
|
extern const char *Txt_HELP_nickname;
|
|
|
|
|
char NewNickWithArr[Nck_MAX_BYTES_NICK_WITH_ARROBA + 1];
|
|
|
|
|
|
|
|
|
|
/***** Nickname *****/
|
|
|
|
|
HTM_TR_Begin (NULL);
|
|
|
|
|
|
|
|
|
|
/* Label */
|
2024-01-30 15:08:53 +01:00
|
|
|
|
Frm_LabelColumn ("Frm_C1 RM","NewNick",Txt_Nickname);
|
2024-01-30 00:20:11 +01:00
|
|
|
|
|
|
|
|
|
/* Data */
|
2024-01-30 15:08:53 +01:00
|
|
|
|
HTM_TD_Begin ("class=\"Frm_C2 LM\"");
|
2024-01-30 00:20:11 +01:00
|
|
|
|
if (NewNickWithoutArr[0])
|
|
|
|
|
snprintf (NewNickWithArr,sizeof (NewNickWithArr),"@%s",
|
|
|
|
|
NewNickWithoutArr);
|
|
|
|
|
else
|
|
|
|
|
NewNickWithArr[0] = '\0';
|
|
|
|
|
HTM_INPUT_TEXT ("NewNick",1 + Nck_MAX_CHARS_NICK_WITHOUT_ARROBA,
|
2024-05-09 19:11:16 +02:00
|
|
|
|
NewNickWithArr,
|
2024-06-07 10:44:31 +02:00
|
|
|
|
HTM_REQUIRED,
|
2024-01-30 00:20:11 +01:00
|
|
|
|
"id=\"NewNick\" size=\"16\" placeholder=\"%s\""
|
2024-05-14 10:19:48 +02:00
|
|
|
|
" class=\"Frm_C2_INPUT INPUT_%s\"",
|
|
|
|
|
Txt_HELP_nickname,The_GetSuffix ());
|
2024-01-30 00:20:11 +01:00
|
|
|
|
HTM_TD_End ();
|
|
|
|
|
|
|
|
|
|
HTM_TR_End ();
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
/*****************************************************************************/
|
2014-12-01 23:55:08 +01:00
|
|
|
|
/*********************** Show form to change my nickname *********************/
|
|
|
|
|
/*****************************************************************************/
|
|
|
|
|
|
2018-10-15 14:07:12 +02:00
|
|
|
|
void Nck_ShowFormChangeMyNickname (bool IMustFillNickname)
|
2014-12-01 23:55:08 +01:00
|
|
|
|
{
|
2023-04-04 13:46:51 +02:00
|
|
|
|
Nck_ShowFormChangeUsrNickname (Usr_ME,
|
2018-10-16 01:36:13 +02:00
|
|
|
|
IMustFillNickname);
|
2018-10-15 14:07:12 +02:00
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
/*****************************************************************************/
|
|
|
|
|
/*********************** Show form to change my nickname *********************/
|
|
|
|
|
/*****************************************************************************/
|
|
|
|
|
|
|
|
|
|
void Nck_ShowFormChangeOtherUsrNickname (void)
|
|
|
|
|
{
|
2023-04-04 13:46:51 +02:00
|
|
|
|
Nck_ShowFormChangeUsrNickname (Usr_OTHER,
|
2018-10-16 01:36:13 +02:00
|
|
|
|
false); // IMustFillNickname
|
2018-10-15 14:07:12 +02:00
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
/*****************************************************************************/
|
|
|
|
|
/*********************** Show form to change my nickname *********************/
|
|
|
|
|
/*****************************************************************************/
|
|
|
|
|
|
2023-04-04 13:46:51 +02:00
|
|
|
|
static void Nck_ShowFormChangeUsrNickname (Usr_MeOrOther_t MeOrOther,
|
2018-10-16 01:36:13 +02:00
|
|
|
|
bool IMustFillNickname)
|
2018-10-15 14:07:12 +02:00
|
|
|
|
{
|
|
|
|
|
extern const char *Hlp_PROFILE_Account;
|
|
|
|
|
extern const char *Txt_Nickname;
|
|
|
|
|
extern const char *Txt_Before_going_to_any_other_option_you_must_fill_your_nickname;
|
2014-12-01 23:55:08 +01:00
|
|
|
|
extern const char *Txt_Current_nickname;
|
|
|
|
|
extern const char *Txt_Other_nicknames;
|
|
|
|
|
extern const char *Txt_Use_this_nickname;
|
|
|
|
|
extern const char *Txt_New_nickname;
|
|
|
|
|
extern const char *Txt_Change_nickname;
|
2019-02-18 18:27:45 +01:00
|
|
|
|
extern const char *Txt_Save_changes;
|
2024-09-12 08:39:17 +02:00
|
|
|
|
extern struct Usr_Data *Usr_UsrDat[Usr_NUM_ME_OR_OTHER];
|
2021-11-10 23:05:08 +01:00
|
|
|
|
static const struct
|
|
|
|
|
{
|
|
|
|
|
Act_Action_t Remove;
|
|
|
|
|
Act_Action_t Change;
|
|
|
|
|
} NextAction[Rol_NUM_ROLES] =
|
|
|
|
|
{
|
2023-04-04 13:46:51 +02:00
|
|
|
|
[Rol_UNK ] = {ActRemNicOth,ActChgNicOth},
|
|
|
|
|
[Rol_GST ] = {ActRemNicOth,ActChgNicOth},
|
|
|
|
|
[Rol_USR ] = {ActRemNicOth,ActChgNicOth},
|
|
|
|
|
[Rol_STD ] = {ActRemNicStd,ActChgNicStd},
|
|
|
|
|
[Rol_NET ] = {ActRemNicTch,ActChgNicTch},
|
|
|
|
|
[Rol_TCH ] = {ActRemNicTch,ActChgNicTch},
|
|
|
|
|
[Rol_DEG_ADM] = {ActRemNicOth,ActChgNicOth},
|
|
|
|
|
[Rol_CTR_ADM] = {ActRemNicOth,ActChgNicOth},
|
|
|
|
|
[Rol_INS_ADM] = {ActRemNicOth,ActChgNicOth},
|
|
|
|
|
[Rol_SYS_ADM] = {ActRemNicOth,ActChgNicOth},
|
2021-11-10 23:05:08 +01:00
|
|
|
|
};
|
2014-12-01 23:55:08 +01:00
|
|
|
|
MYSQL_RES *mysql_res;
|
|
|
|
|
MYSQL_ROW row;
|
|
|
|
|
unsigned NumNicks;
|
|
|
|
|
unsigned NumNick;
|
2021-10-21 20:33:55 +02:00
|
|
|
|
char NickWithArr[Nck_MAX_BYTES_NICK_WITH_ARROBA + 1];
|
2023-04-04 13:46:51 +02:00
|
|
|
|
static void (*FuncParsRemove[Usr_NUM_ME_OR_OTHER]) (void *ID) =
|
|
|
|
|
{
|
|
|
|
|
[Usr_ME ] = Nck_PutParsRemoveMyNick,
|
|
|
|
|
[Usr_OTHER] = Nck_PutParsRemoveOtherNick
|
|
|
|
|
};
|
|
|
|
|
struct
|
|
|
|
|
{
|
|
|
|
|
Act_Action_t Remove;
|
|
|
|
|
Act_Action_t Change;
|
|
|
|
|
} ActNck[Rol_NUM_ROLES] =
|
|
|
|
|
{
|
|
|
|
|
[Usr_ME ] = {.Remove = ActRemMyNck,
|
|
|
|
|
.Change = ActChgMyNck},
|
|
|
|
|
[Usr_OTHER] = {.Remove = NextAction[Gbl.Usrs.Other.UsrDat.Roles.InCurrentCrs].Remove,
|
|
|
|
|
.Change = NextAction[Gbl.Usrs.Other.UsrDat.Roles.InCurrentCrs].Change}
|
|
|
|
|
};
|
2014-12-01 23:55:08 +01:00
|
|
|
|
|
2021-03-02 00:54:26 +01:00
|
|
|
|
/***** Begin section *****/
|
2019-10-26 01:56:36 +02:00
|
|
|
|
HTM_SECTION_Begin (Nck_NICKNAME_SECTION_ID);
|
2018-10-15 14:07:12 +02:00
|
|
|
|
|
2021-06-29 15:25:42 +02:00
|
|
|
|
/***** Get my nicknames *****/
|
2024-09-11 21:35:09 +02:00
|
|
|
|
NumNicks = Nck_DB_GetUsrNicknames (&mysql_res,Usr_UsrDat[MeOrOther]->UsrCod);
|
2021-06-29 15:25:42 +02:00
|
|
|
|
|
|
|
|
|
/***** Begin box *****/
|
2024-01-29 09:45:28 +01:00
|
|
|
|
Box_BoxBegin (Txt_Nickname,Acc_PutLinkToRemoveMyAccount,NULL,
|
2023-11-27 08:56:16 +01:00
|
|
|
|
Hlp_PROFILE_Account,Box_NOT_CLOSABLE);
|
2021-06-29 15:25:42 +02:00
|
|
|
|
|
2023-11-27 08:56:16 +01:00
|
|
|
|
/***** Show possible alerts *****/
|
|
|
|
|
Ale_ShowAlerts (Nck_NICKNAME_SECTION_ID);
|
2021-06-29 15:25:42 +02:00
|
|
|
|
|
2023-11-27 08:56:16 +01:00
|
|
|
|
/***** Help message *****/
|
|
|
|
|
if (IMustFillNickname)
|
|
|
|
|
Ale_ShowAlert (Ale_WARNING,Txt_Before_going_to_any_other_option_you_must_fill_your_nickname);
|
2023-11-24 14:37:55 +01:00
|
|
|
|
|
2023-11-27 08:56:16 +01:00
|
|
|
|
/***** Begin table *****/
|
2024-01-29 00:11:10 +01:00
|
|
|
|
HTM_TABLE_BeginPadding (2);
|
2023-11-24 14:37:55 +01:00
|
|
|
|
|
2023-11-27 08:56:16 +01:00
|
|
|
|
/***** List nicknames *****/
|
|
|
|
|
for (NumNick = 1;
|
|
|
|
|
NumNick <= NumNicks;
|
|
|
|
|
NumNick++)
|
|
|
|
|
{
|
|
|
|
|
/* Get nickname */
|
|
|
|
|
row = mysql_fetch_row (mysql_res);
|
|
|
|
|
|
|
|
|
|
if (NumNick == 1)
|
2021-06-29 15:25:42 +02:00
|
|
|
|
{
|
2023-11-27 08:56:16 +01:00
|
|
|
|
/* The first nickname is the current one */
|
|
|
|
|
HTM_TR_Begin (NULL);
|
|
|
|
|
|
|
|
|
|
/* Label */
|
2024-01-30 15:08:53 +01:00
|
|
|
|
Frm_LabelColumn ("Frm_C1 RT",NULL,Txt_Current_nickname);
|
2023-11-24 14:37:55 +01:00
|
|
|
|
|
2023-11-27 08:56:16 +01:00
|
|
|
|
/* Data */
|
2024-01-30 15:08:53 +01:00
|
|
|
|
HTM_TD_Begin ("class=\"Frm_C2 LT DAT_STRONG_%s\"",
|
2023-11-27 08:56:16 +01:00
|
|
|
|
The_GetSuffix ());
|
|
|
|
|
}
|
|
|
|
|
else // NumNick >= 2
|
|
|
|
|
{
|
|
|
|
|
if (NumNick == 2)
|
2021-06-29 15:25:42 +02:00
|
|
|
|
{
|
|
|
|
|
HTM_TR_Begin (NULL);
|
|
|
|
|
|
2021-11-10 23:05:08 +01:00
|
|
|
|
/* Label */
|
2024-01-30 15:08:53 +01:00
|
|
|
|
Frm_LabelColumn ("Frm_C1 RT",NULL,Txt_Other_nicknames);
|
2021-06-29 15:25:42 +02:00
|
|
|
|
|
2021-11-10 23:05:08 +01:00
|
|
|
|
/* Data */
|
2024-01-30 15:08:53 +01:00
|
|
|
|
HTM_TD_Begin ("class=\"Frm_C2 LT DAT_%s\"",
|
2023-11-24 14:37:55 +01:00
|
|
|
|
The_GetSuffix ());
|
2021-06-29 15:25:42 +02:00
|
|
|
|
}
|
|
|
|
|
|
2023-11-27 08:56:16 +01:00
|
|
|
|
/* Form to remove old nickname */
|
|
|
|
|
Ico_PutContextualIconToRemove (ActNck[MeOrOther].Remove,Nck_NICKNAME_SECTION_ID,
|
|
|
|
|
FuncParsRemove[MeOrOther],row[0]);
|
|
|
|
|
}
|
2021-06-29 15:25:42 +02:00
|
|
|
|
|
2023-11-27 08:56:16 +01:00
|
|
|
|
/* Nickname */
|
|
|
|
|
HTM_TxtF ("@%s",row[0]);
|
2021-06-29 15:25:42 +02:00
|
|
|
|
|
2023-11-27 08:56:16 +01:00
|
|
|
|
/* Link to QR code */
|
2024-09-11 21:35:09 +02:00
|
|
|
|
if (NumNick == 1 && Usr_UsrDat[MeOrOther]->Nickname[0])
|
2023-11-27 08:56:16 +01:00
|
|
|
|
QR_PutLinkToPrintQRCode (ActPrnUsrQR,
|
2024-09-11 21:35:09 +02:00
|
|
|
|
Usr_PutParOtherUsrCodEncrypted,Usr_UsrDat[MeOrOther]->EnUsrCod);
|
2021-06-29 15:25:42 +02:00
|
|
|
|
|
2023-11-27 08:56:16 +01:00
|
|
|
|
/* Form to change the nickname */
|
|
|
|
|
if (NumNick > 1)
|
|
|
|
|
{
|
|
|
|
|
HTM_BR ();
|
|
|
|
|
Frm_BeginFormAnchor (ActNck[MeOrOther].Change,Nck_NICKNAME_SECTION_ID);
|
|
|
|
|
if (MeOrOther == Usr_OTHER)
|
|
|
|
|
Usr_PutParUsrCodEncrypted (Gbl.Usrs.Other.UsrDat.EnUsrCod);
|
|
|
|
|
snprintf (NickWithArr,sizeof (NickWithArr),"@%s",row[0]);
|
|
|
|
|
Par_PutParString (NULL,"NewNick",NickWithArr); // Nickname
|
|
|
|
|
Btn_PutConfirmButtonInline (Txt_Use_this_nickname);
|
|
|
|
|
Frm_EndForm ();
|
|
|
|
|
}
|
2023-11-24 14:37:55 +01:00
|
|
|
|
|
2023-11-27 08:56:16 +01:00
|
|
|
|
if (NumNick == 1 ||
|
|
|
|
|
NumNick == NumNicks)
|
|
|
|
|
{
|
|
|
|
|
HTM_TD_End ();
|
|
|
|
|
HTM_TR_End ();
|
|
|
|
|
}
|
|
|
|
|
else
|
|
|
|
|
HTM_BR ();
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
/***** Form to enter new nickname *****/
|
|
|
|
|
HTM_TR_Begin (NULL);
|
|
|
|
|
|
|
|
|
|
/* Label */
|
2024-01-30 15:08:53 +01:00
|
|
|
|
Frm_LabelColumn ("Frm_C1 RT","NewNick",
|
2023-11-27 08:56:16 +01:00
|
|
|
|
NumNicks ? Txt_New_nickname : // A new nickname
|
|
|
|
|
Txt_Nickname); // The first nickname
|
|
|
|
|
|
|
|
|
|
/* Data */
|
2024-01-30 15:08:53 +01:00
|
|
|
|
HTM_TD_Begin ("class=\"Frm_C2 LT DAT_%s\"",The_GetSuffix ());
|
2023-11-27 08:56:16 +01:00
|
|
|
|
Frm_BeginFormAnchor (ActNck[MeOrOther].Change,Nck_NICKNAME_SECTION_ID);
|
|
|
|
|
if (MeOrOther == Usr_OTHER)
|
|
|
|
|
Usr_PutParUsrCodEncrypted (Gbl.Usrs.Other.UsrDat.EnUsrCod);
|
|
|
|
|
snprintf (NickWithArr,sizeof (NickWithArr),"@%s",
|
2024-09-11 21:35:09 +02:00
|
|
|
|
Usr_UsrDat[MeOrOther]->Nickname);
|
2023-11-27 08:56:16 +01:00
|
|
|
|
HTM_INPUT_TEXT ("NewNick",1 + Nck_MAX_CHARS_NICK_WITHOUT_ARROBA,
|
2024-05-09 19:11:16 +02:00
|
|
|
|
NickWithArr,
|
2024-06-07 10:44:31 +02:00
|
|
|
|
HTM_NO_ATTR,
|
2023-12-07 22:55:39 +01:00
|
|
|
|
"id=\"NewNick\""
|
2024-01-30 15:08:53 +01:00
|
|
|
|
" class=\"Frm_C2_INPUT INPUT_%s\""
|
2024-06-07 10:44:31 +02:00
|
|
|
|
" size=\"16\"",The_GetSuffix ());
|
2021-12-01 01:43:13 +01:00
|
|
|
|
HTM_BR ();
|
2023-11-27 08:56:16 +01:00
|
|
|
|
Btn_PutCreateButtonInline (NumNicks ? Txt_Change_nickname : // I already have a nickname
|
|
|
|
|
Txt_Save_changes); // I have no nickname yet);
|
|
|
|
|
Frm_EndForm ();
|
|
|
|
|
HTM_TD_End ();
|
2021-06-29 15:25:42 +02:00
|
|
|
|
|
2023-11-27 08:56:16 +01:00
|
|
|
|
HTM_TR_End ();
|
2021-06-29 15:25:42 +02:00
|
|
|
|
|
2023-11-27 08:56:16 +01:00
|
|
|
|
/***** End table and box *****/
|
|
|
|
|
Box_BoxTableEnd ();
|
2018-10-15 14:07:12 +02:00
|
|
|
|
|
|
|
|
|
/***** End section *****/
|
2019-10-26 01:56:36 +02:00
|
|
|
|
HTM_SECTION_End ();
|
2014-12-01 23:55:08 +01:00
|
|
|
|
}
|
|
|
|
|
|
2023-03-10 00:13:55 +01:00
|
|
|
|
static void Nck_PutParsRemoveMyNick (void *Nick)
|
2020-10-14 00:59:24 +02:00
|
|
|
|
{
|
|
|
|
|
if (Nick)
|
2023-03-07 09:55:39 +01:00
|
|
|
|
Par_PutParString (NULL,"Nick",Nick);
|
2020-10-14 00:59:24 +02:00
|
|
|
|
}
|
|
|
|
|
|
2023-03-10 00:13:55 +01:00
|
|
|
|
static void Nck_PutParsRemoveOtherNick (void *Nick)
|
2020-10-14 00:59:24 +02:00
|
|
|
|
{
|
|
|
|
|
if (Nick)
|
|
|
|
|
{
|
2023-03-10 00:13:55 +01:00
|
|
|
|
Usr_PutParUsrCodEncrypted (Gbl.Usrs.Other.UsrDat.EnUsrCod);
|
2023-03-07 09:55:39 +01:00
|
|
|
|
Par_PutParString (NULL,"Nick",Nick);
|
2020-10-14 00:59:24 +02:00
|
|
|
|
}
|
|
|
|
|
}
|
|
|
|
|
|
2014-12-01 23:55:08 +01:00
|
|
|
|
/*****************************************************************************/
|
2018-10-16 01:36:13 +02:00
|
|
|
|
/***************************** Remove my nickname ****************************/
|
2014-12-01 23:55:08 +01:00
|
|
|
|
/*****************************************************************************/
|
|
|
|
|
|
2018-10-16 01:36:13 +02:00
|
|
|
|
void Nck_RemoveMyNick (void)
|
2014-12-01 23:55:08 +01:00
|
|
|
|
{
|
|
|
|
|
extern const char *Txt_Nickname_X_removed;
|
|
|
|
|
extern const char *Txt_You_can_not_delete_your_current_nickname;
|
2021-02-15 22:49:44 +01:00
|
|
|
|
char NickWithoutArr[Nck_MAX_BYTES_NICK_WITHOUT_ARROBA + 1];
|
2014-12-01 23:55:08 +01:00
|
|
|
|
|
2018-10-16 01:36:13 +02:00
|
|
|
|
/***** Get nickname from form *****/
|
2023-03-07 09:55:39 +01:00
|
|
|
|
Par_GetParText ("Nick",NickWithoutArr,
|
2021-02-15 22:49:44 +01:00
|
|
|
|
Nck_MAX_BYTES_NICK_WITHOUT_ARROBA);
|
2014-12-01 23:55:08 +01:00
|
|
|
|
|
2021-02-15 22:49:44 +01:00
|
|
|
|
if (strcasecmp (NickWithoutArr,Gbl.Usrs.Me.UsrDat.Nickname)) // Only if not my current nickname
|
2014-12-01 23:55:08 +01:00
|
|
|
|
{
|
|
|
|
|
/***** Remove one of my old nicknames *****/
|
2021-06-29 15:25:42 +02:00
|
|
|
|
Nck_DB_RemoveNickname (Gbl.Usrs.Me.UsrDat.UsrCod,NickWithoutArr);
|
2014-12-01 23:55:08 +01:00
|
|
|
|
|
|
|
|
|
/***** Show message *****/
|
2019-03-09 20:12:44 +01:00
|
|
|
|
Ale_CreateAlert (Ale_SUCCESS,Nck_NICKNAME_SECTION_ID,
|
|
|
|
|
Txt_Nickname_X_removed,
|
2021-02-15 22:49:44 +01:00
|
|
|
|
NickWithoutArr);
|
2014-12-01 23:55:08 +01:00
|
|
|
|
}
|
|
|
|
|
else
|
2019-03-09 20:12:44 +01:00
|
|
|
|
Ale_CreateAlert (Ale_WARNING,Nck_NICKNAME_SECTION_ID,
|
|
|
|
|
Txt_You_can_not_delete_your_current_nickname);
|
2014-12-01 23:55:08 +01:00
|
|
|
|
|
|
|
|
|
/***** Show my account again *****/
|
2018-10-15 14:07:12 +02:00
|
|
|
|
Acc_ShowFormChgMyAccount ();
|
2014-12-01 23:55:08 +01:00
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
/*****************************************************************************/
|
2018-10-16 01:36:13 +02:00
|
|
|
|
/********************* Remove another user's nickname ************************/
|
2014-12-01 23:55:08 +01:00
|
|
|
|
/*****************************************************************************/
|
|
|
|
|
|
2018-10-16 01:36:13 +02:00
|
|
|
|
void Nck_RemoveOtherUsrNick (void)
|
|
|
|
|
{
|
|
|
|
|
extern const char *Txt_Nickname_X_removed;
|
2021-02-15 22:49:44 +01:00
|
|
|
|
char NickWithoutArr[Nck_MAX_BYTES_NICK_WITHOUT_ARROBA + 1];
|
2018-10-16 01:36:13 +02:00
|
|
|
|
|
|
|
|
|
/***** Get user whose nick must be removed *****/
|
2023-03-10 00:13:55 +01:00
|
|
|
|
if (Usr_GetParOtherUsrCodEncryptedAndGetUsrData ())
|
2024-04-06 21:23:53 +02:00
|
|
|
|
switch (Usr_CheckIfICanEditOtherUsr (&Gbl.Usrs.Other.UsrDat))
|
2018-10-16 01:36:13 +02:00
|
|
|
|
{
|
2024-04-19 12:00:30 +02:00
|
|
|
|
case Usr_CAN:
|
2024-04-06 21:23:53 +02:00
|
|
|
|
/***** Get nickname from form *****/
|
|
|
|
|
Par_GetParText ("Nick",NickWithoutArr,
|
|
|
|
|
Nck_MAX_BYTES_NICK_WITHOUT_ARROBA);
|
|
|
|
|
|
|
|
|
|
/***** Remove one of the old nicknames *****/
|
|
|
|
|
Nck_DB_RemoveNickname (Gbl.Usrs.Other.UsrDat.UsrCod,NickWithoutArr);
|
|
|
|
|
|
|
|
|
|
/***** Show message *****/
|
|
|
|
|
Ale_CreateAlert (Ale_SUCCESS,Nck_NICKNAME_SECTION_ID,
|
|
|
|
|
Txt_Nickname_X_removed,
|
|
|
|
|
NickWithoutArr);
|
|
|
|
|
|
|
|
|
|
/***** Show user's account again *****/
|
|
|
|
|
Acc_ShowFormChgOtherUsrAccount ();
|
|
|
|
|
break;
|
2024-04-19 12:00:30 +02:00
|
|
|
|
case Usr_CAN_NOT:
|
2024-04-06 21:23:53 +02:00
|
|
|
|
default:
|
|
|
|
|
Ale_ShowAlertUserNotFoundOrYouDoNotHavePermission ();
|
|
|
|
|
break;
|
2018-10-16 01:36:13 +02:00
|
|
|
|
}
|
|
|
|
|
else // User not found
|
2019-03-09 20:12:44 +01:00
|
|
|
|
Ale_ShowAlertUserNotFoundOrYouDoNotHavePermission ();
|
2018-10-16 01:36:13 +02:00
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
/*****************************************************************************/
|
|
|
|
|
/***************************** Update my nickname ****************************/
|
|
|
|
|
/*****************************************************************************/
|
|
|
|
|
|
|
|
|
|
void Nck_UpdateMyNick (void)
|
|
|
|
|
{
|
|
|
|
|
/***** Update my nickname *****/
|
2023-04-04 13:46:51 +02:00
|
|
|
|
Nck_ChangeUsrNick (&Gbl.Usrs.Me.UsrDat);
|
2018-10-16 01:36:13 +02:00
|
|
|
|
|
|
|
|
|
/***** Show my account again *****/
|
|
|
|
|
Acc_ShowFormChgMyAccount ();
|
2014-12-01 23:55:08 +01:00
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
/*****************************************************************************/
|
2023-04-04 13:46:51 +02:00
|
|
|
|
/*********************** Change another user's nickname **********************/
|
2014-12-01 23:55:08 +01:00
|
|
|
|
/*****************************************************************************/
|
|
|
|
|
|
2023-04-04 13:46:51 +02:00
|
|
|
|
void Nck_ChangeOtherUsrNick (void)
|
2018-10-16 01:36:13 +02:00
|
|
|
|
{
|
|
|
|
|
/***** Get user whose nick must be changed *****/
|
2023-03-10 00:13:55 +01:00
|
|
|
|
if (Usr_GetParOtherUsrCodEncryptedAndGetUsrData ())
|
2024-04-06 21:23:53 +02:00
|
|
|
|
switch (Usr_CheckIfICanEditOtherUsr (&Gbl.Usrs.Other.UsrDat))
|
2018-10-16 01:36:13 +02:00
|
|
|
|
{
|
2024-04-19 12:00:30 +02:00
|
|
|
|
case Usr_CAN:
|
2024-04-06 21:23:53 +02:00
|
|
|
|
/***** Update user's nickname *****/
|
|
|
|
|
Nck_ChangeUsrNick (&Gbl.Usrs.Other.UsrDat);
|
|
|
|
|
|
|
|
|
|
/***** Show user's account again *****/
|
|
|
|
|
Acc_ShowFormChgOtherUsrAccount ();
|
|
|
|
|
break;
|
2024-04-19 12:00:30 +02:00
|
|
|
|
case Usr_CAN_NOT:
|
2024-04-06 21:23:53 +02:00
|
|
|
|
default:
|
|
|
|
|
Ale_ShowAlertUserNotFoundOrYouDoNotHavePermission ();
|
|
|
|
|
break;
|
2018-10-16 01:36:13 +02:00
|
|
|
|
}
|
|
|
|
|
else // User not found
|
2019-03-09 20:12:44 +01:00
|
|
|
|
Ale_ShowAlertUserNotFoundOrYouDoNotHavePermission ();
|
2018-10-16 01:36:13 +02:00
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
/*****************************************************************************/
|
2023-04-04 13:46:51 +02:00
|
|
|
|
/*************************** Change user's nickname **************************/
|
2018-10-16 01:36:13 +02:00
|
|
|
|
/*****************************************************************************/
|
|
|
|
|
|
2023-04-04 13:46:51 +02:00
|
|
|
|
static void Nck_ChangeUsrNick (struct Usr_Data *UsrDat)
|
2014-12-01 23:55:08 +01:00
|
|
|
|
{
|
2021-10-21 20:33:55 +02:00
|
|
|
|
extern const char *Txt_The_nickname_matches_the_one_you_had_previously_registered;
|
|
|
|
|
extern const char *Txt_The_nickname_had_been_registered_by_another_user;
|
|
|
|
|
extern const char *Txt_The_nickname_has_been_registered_successfully;
|
|
|
|
|
extern const char *Txt_The_nickname_is_not_valid_;
|
|
|
|
|
char NewNick[Nck_MAX_BYTES_NICK_WITH_ARROBA + 1];
|
2014-12-01 23:55:08 +01:00
|
|
|
|
|
|
|
|
|
/***** Get new nickname from form *****/
|
2023-03-07 09:55:39 +01:00
|
|
|
|
Par_GetParText ("NewNick",NewNick,sizeof (NewNick) - 1);
|
2021-10-21 20:33:55 +02:00
|
|
|
|
|
|
|
|
|
if (Nck_CheckIfNickWithArrIsValid (NewNick)) // If new nickname is valid
|
2014-12-01 23:55:08 +01:00
|
|
|
|
{
|
|
|
|
|
/***** Remove arrobas at the beginning *****/
|
2021-10-21 20:33:55 +02:00
|
|
|
|
Str_RemoveLeadingArrobas (NewNick);
|
2014-12-01 23:55:08 +01:00
|
|
|
|
|
|
|
|
|
/***** Check if new nickname exists in database *****/
|
2021-10-21 20:33:55 +02:00
|
|
|
|
if (!strcmp (UsrDat->Nickname,NewNick)) // User's nickname match exactly the new nickname
|
2019-03-09 20:12:44 +01:00
|
|
|
|
Ale_CreateAlert (Ale_WARNING,Nck_NICKNAME_SECTION_ID,
|
2021-10-21 20:33:55 +02:00
|
|
|
|
Txt_The_nickname_matches_the_one_you_had_previously_registered);
|
|
|
|
|
else if (strcasecmp (UsrDat->Nickname,NewNick)) // User's nickname does not match, not even case insensitive, the new nickname
|
2014-12-01 23:55:08 +01:00
|
|
|
|
{
|
|
|
|
|
/***** Check if the new nickname matches any of my old nicknames *****/
|
2021-10-21 20:33:55 +02:00
|
|
|
|
if (!Nck_DB_CheckIfNickMatchesAnyUsrNick (UsrDat->UsrCod,NewNick)) // No matches
|
2014-12-01 23:55:08 +01:00
|
|
|
|
/***** Check if the new nickname matches any of the nicknames of other users *****/
|
2021-10-21 20:33:55 +02:00
|
|
|
|
if (Nck_DB_CheckIfNickMatchesAnyOtherUsrsNicks (UsrDat->UsrCod,NewNick)) // A nickname of another user is the same that user's nickname
|
2019-03-09 20:12:44 +01:00
|
|
|
|
Ale_CreateAlert (Ale_WARNING,Nck_NICKNAME_SECTION_ID,
|
2021-10-21 20:33:55 +02:00
|
|
|
|
Txt_The_nickname_had_been_registered_by_another_user);
|
2014-12-01 23:55:08 +01:00
|
|
|
|
}
|
2019-03-09 20:12:44 +01:00
|
|
|
|
if (Ale_GetNumAlerts () == 0) // No problems
|
2014-12-01 23:55:08 +01:00
|
|
|
|
{
|
2018-10-16 01:36:13 +02:00
|
|
|
|
// Now we know the new nickname is not already in database
|
|
|
|
|
// and is diffent to the current one
|
2021-10-21 20:33:55 +02:00
|
|
|
|
Nck_DB_UpdateNick (UsrDat->UsrCod,NewNick); // Leading arrobas already removed
|
|
|
|
|
Str_Copy (UsrDat->Nickname,NewNick,sizeof (UsrDat->Nickname) - 1);
|
2014-12-01 23:55:08 +01:00
|
|
|
|
|
2019-03-09 20:12:44 +01:00
|
|
|
|
Ale_CreateAlert (Ale_SUCCESS,Nck_NICKNAME_SECTION_ID,
|
2021-10-21 20:33:55 +02:00
|
|
|
|
Txt_The_nickname_has_been_registered_successfully);
|
2014-12-01 23:55:08 +01:00
|
|
|
|
}
|
|
|
|
|
}
|
|
|
|
|
else // New nickname is not valid
|
2019-03-09 20:12:44 +01:00
|
|
|
|
Ale_CreateAlert (Ale_WARNING,Nck_NICKNAME_SECTION_ID,
|
2021-10-21 20:33:55 +02:00
|
|
|
|
Txt_The_nickname_is_not_valid_,
|
2021-02-15 22:49:44 +01:00
|
|
|
|
Nck_MIN_CHARS_NICK_WITHOUT_ARROBA,
|
|
|
|
|
Nck_MAX_CHARS_NICK_WITHOUT_ARROBA);
|
2014-12-01 23:55:08 +01:00
|
|
|
|
}
|