swad-core/swad_account.c

1120 lines
40 KiB
C
Raw Normal View History

2014-12-12 22:39:55 +01:00
// swad_account.c: user's account
/*
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.
Copyright (C) 1999-2024 Antonio Ca<EFBFBD>as Vargas
2014-12-12 22:39:55 +01:00
This program is free software: you can redistribute it and/or modify
it under the terms of the GNU Affero General 3 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 *********************************/
/*****************************************************************************/
#define _GNU_SOURCE // For asprintf
#include <stdio.h> // For asprintf
#include <stdlib.h> // For free
2014-12-12 22:39:55 +01:00
#include <string.h> // For string functions
#include "swad_account.h"
#include "swad_account_database.h"
#include "swad_action_list.h"
#include "swad_admin_database.h"
#include "swad_agenda_database.h"
#include "swad_announcement_database.h"
#include "swad_attendance_database.h"
2017-06-10 21:38:10 +02:00
#include "swad_box.h"
#include "swad_browser_database.h"
2015-11-21 20:23:28 +01:00
#include "swad_calendar.h"
#include "swad_connected_database.h"
2014-12-12 22:39:55 +01:00
#include "swad_database.h"
#include "swad_duplicate_database.h"
#include "swad_enrolment_database.h"
#include "swad_error.h"
#include "swad_exam_database.h"
2015-12-12 02:01:20 +01:00
#include "swad_follow.h"
2018-11-09 20:47:39 +01:00
#include "swad_form.h"
#include "swad_forum_database.h"
2014-12-12 22:39:55 +01:00
#include "swad_global.h"
2019-10-23 19:05:05 +02:00
#include "swad_HTML.h"
2014-12-12 22:39:55 +01:00
#include "swad_ID.h"
#include "swad_ID_database.h"
2017-05-07 18:06:34 +02:00
#include "swad_language.h"
#include "swad_mail_database.h"
2020-05-18 22:59:07 +02:00
#include "swad_match.h"
2020-04-14 17:15:17 +02:00
#include "swad_message.h"
#include "swad_message_database.h"
#include "swad_network.h"
2018-10-16 01:36:13 +02:00
#include "swad_nickname.h"
#include "swad_nickname_database.h"
2014-12-12 22:39:55 +01:00
#include "swad_notification.h"
#include "swad_notification_database.h"
2014-12-12 22:39:55 +01:00
#include "swad_parameter.h"
#include "swad_photo_database.h"
2015-03-14 17:39:04 +01:00
#include "swad_profile.h"
#include "swad_profile_database.h"
2020-04-14 17:15:17 +02:00
#include "swad_project.h"
#include "swad_record_database.h"
2016-10-06 22:18:33 +02:00
#include "swad_report.h"
#include "swad_session_database.h"
#include "swad_setting.h"
#include "swad_setting_database.h"
2020-05-07 18:33:26 +02:00
#include "swad_test_print.h"
2019-03-12 21:25:55 +01:00
#include "swad_timeline.h"
#include "swad_user.h"
#include "swad_user_database.h"
2014-12-12 22:39:55 +01:00
/*****************************************************************************/
/************** External global variables from others modules ****************/
/*****************************************************************************/
extern struct Globals Gbl;
/*****************************************************************************/
/***************************** Private prototypes ****************************/
/*****************************************************************************/
2016-09-26 11:49:18 +02:00
static void Acc_ShowFormCheckIfIHaveAccount (const char *Title);
static void Acc_WriteRowEmptyAccount (unsigned NumUsr,const char *ID,struct Usr_Data *UsrDat);
static void Acc_ShowFormRequestNewAccountWithPars (const char *NewNickWithoutArr,
const char *NewEmail);
static bool Acc_GetParsNewAccount (char NewNickWithoutArr[Nck_MAX_BYTES_NICK_WITHOUT_ARROBA + 1],
char NewEmail[Cns_MAX_BYTES_EMAIL_ADDRESS + 1],
char NewEncryptedPassword[Pwd_BYTES_ENCRYPTED_PASSWORD + 1]);
static void Acc_CreateNewEncryptedUsrCod (struct Usr_Data *UsrDat);
2014-12-12 22:39:55 +01:00
static void Acc_PutParsToRemoveMyAccount (void *EncryptedUsrCod);
2015-04-02 18:39:49 +02:00
static void Acc_AskIfRemoveUsrAccount (Usr_MeOrOther_t MeOrOther);
2015-09-16 00:15:20 +02:00
static void Acc_AskIfRemoveOtherUsrAccount (void);
2014-12-12 22:39:55 +01:00
static void Acc_RemoveUsrBriefcase (struct Usr_Data *UsrDat);
2014-12-12 22:39:55 +01:00
2016-03-01 03:16:29 +01:00
/*****************************************************************************/
/******************** Put link to create a new account ***********************/
/*****************************************************************************/
void Acc_PutLinkToCreateAccount (void)
{
extern const char *Txt_Actions[ActLst_NUM_ACTIONS];
2016-03-01 03:16:29 +01:00
2020-03-26 02:54:30 +01:00
Lay_PutContextualLinkIconText (ActFrmMyAcc,NULL,
NULL,NULL,
"at.svg",Ico_BLACK,
Txt_Actions[ActCreUsrAcc],NULL);
2016-03-01 03:16:29 +01:00
}
2014-12-12 22:39:55 +01:00
/*****************************************************************************/
/******** Show form to change my account or to create a new account **********/
/*****************************************************************************/
2016-10-12 14:02:56 +02:00
void Acc_ShowFormMyAccount (void)
2014-12-12 22:39:55 +01:00
{
2017-06-10 20:56:50 +02:00
extern const char *Txt_Before_creating_a_new_account_check_if_you_have_been_already_registered;
2016-09-26 12:05:28 +02:00
2014-12-12 22:39:55 +01:00
if (Gbl.Usrs.Me.Logged)
2018-10-15 14:07:12 +02:00
Acc_ShowFormChgMyAccount ();
2016-09-26 12:05:28 +02:00
else // Not logged
2015-06-15 12:30:09 +02:00
{
2019-10-24 09:46:20 +02:00
/***** Contextual menu *****/
Mnu_ContextMenuBegin ();
Usr_PutLinkToLogin ();
Pwd_PutLinkToSendNewPasswd ();
Lan_PutLinkToChangeLanguage ();
2019-10-24 09:46:20 +02:00
Mnu_ContextMenuEnd ();
2015-06-15 12:30:09 +02:00
2016-09-22 13:33:42 +02:00
/**** Show form to check if I have an account *****/
2017-06-10 20:56:50 +02:00
Acc_ShowFormCheckIfIHaveAccount (Txt_Before_creating_a_new_account_check_if_you_have_been_already_registered);
2015-06-15 12:30:09 +02:00
}
2014-12-12 22:39:55 +01:00
}
2016-09-22 13:33:42 +02:00
/*****************************************************************************/
/***************** Show form to check if I have an account *******************/
/*****************************************************************************/
2016-09-26 11:49:18 +02:00
static void Acc_ShowFormCheckIfIHaveAccount (const char *Title)
2016-09-22 13:33:42 +02:00
{
2017-03-02 21:18:52 +01:00
extern const char *Hlp_PROFILE_SignUp;
2017-06-10 20:56:50 +02:00
extern const char *Txt_If_you_think_you_may_have_been_registered_;
2016-09-22 13:33:42 +02:00
extern const char *Txt_ID;
extern const char *Txt_ID_identity_number;
2016-09-26 12:18:08 +02:00
extern const char *Txt_Check;
2019-07-04 10:13:51 +02:00
extern const char *Txt_Skip_this_step;
2016-09-22 13:33:42 +02:00
2019-10-26 02:19:42 +02:00
/***** Begin box *****/
Box_BoxBegin (Title, NULL,NULL,Hlp_PROFILE_SignUp,Box_NOT_CLOSABLE);
2017-06-10 20:56:50 +02:00
/***** Help alert *****/
Ale_ShowAlert (Ale_INFO,Txt_If_you_think_you_may_have_been_registered_);
2016-09-22 13:33:42 +02:00
/***** Form to request user's ID for possible account already created *****/
Frm_BeginForm (ActChkUsrAcc);
HTM_LABEL_Begin ("class=\"FORM_IN_%s\"",The_GetSuffix ());
HTM_TxtColonNBSP (Txt_ID);
HTM_INPUT_TEXT ("ID",ID_MAX_CHARS_USR_ID,"",
HTM_DONT_SUBMIT_ON_CHANGE,
"size=\"16\" placeholder=\"%s\" class=\"INPUT_%s\""
" required=\"required\"",
Txt_ID_identity_number,The_GetSuffix ());
HTM_LABEL_End ();
Btn_PutCreateButtonInline (Txt_Check);
Frm_EndForm ();
2016-09-22 13:33:42 +02:00
/***** Form to skip this step *****/
Frm_BeginForm (ActCreMyAcc);
Btn_PutConfirmButton (Txt_Skip_this_step);
Frm_EndForm ();
2019-07-04 10:13:51 +02:00
2017-06-12 14:16:33 +02:00
/***** End box *****/
2019-10-25 22:48:34 +02:00
Box_BoxEnd ();
2016-09-22 13:33:42 +02:00
}
/*****************************************************************************/
/* Check if already exists a new account without password associated to a ID */
/*****************************************************************************/
void Acc_CheckIfEmptyAccountExists (void)
{
2016-09-26 14:30:23 +02:00
extern const char *Txt_Do_you_think_you_are_this_user;
extern const char *Txt_Do_you_think_you_are_one_of_these_users;
2017-06-10 20:56:50 +02:00
extern const char *Txt_There_is_no_empty_account_associated_with_your_ID_X;
2016-09-26 14:47:07 +02:00
extern const char *Txt_Check_another_ID;
2016-09-26 16:43:39 +02:00
extern const char *Txt_Please_enter_your_ID;
2017-06-10 20:56:50 +02:00
extern const char *Txt_Before_creating_a_new_account_check_if_you_have_been_already_registered;
2017-03-07 01:56:41 +01:00
char ID[ID_MAX_BYTES_USR_ID + 1];
2016-09-22 18:04:25 +02:00
unsigned NumUsrs;
2016-09-22 13:33:42 +02:00
unsigned NumUsr;
struct Usr_Data UsrDat;
2016-09-22 18:04:25 +02:00
MYSQL_RES *mysql_res;
2016-09-22 13:33:42 +02:00
2019-10-24 09:46:20 +02:00
/***** Contextual menu *****/
Mnu_ContextMenuBegin ();
Usr_PutLinkToLogin ();
Pwd_PutLinkToSendNewPasswd ();
Lan_PutLinkToChangeLanguage ();
2019-10-24 09:46:20 +02:00
Mnu_ContextMenuEnd ();
2016-09-26 11:49:18 +02:00
2016-09-22 13:33:42 +02:00
/***** Get new user's ID from form *****/
Par_GetParText ("ID",ID,ID_MAX_BYTES_USR_ID);
2016-09-22 13:33:42 +02:00
// Users' IDs are always stored internally in capitals and without leading zeros
2016-09-26 11:49:18 +02:00
Str_RemoveLeadingZeros (ID);
Str_ConvertToUpperText (ID);
2016-09-22 13:33:42 +02:00
/***** Check if there are users with this user's ID *****/
2016-09-26 11:49:18 +02:00
if (ID_CheckIfUsrIDIsValid (ID))
2016-09-22 18:04:25 +02:00
{
if ((NumUsrs = Acc_DB_GetUsrsWithID (&mysql_res,ID)))
2016-09-22 13:33:42 +02:00
{
2019-10-26 02:19:42 +02:00
/***** Begin box and table *****/
Box_BoxTableBegin (NumUsrs == 1 ? Txt_Do_you_think_you_are_this_user :
Txt_Do_you_think_you_are_one_of_these_users,
2020-03-26 02:54:30 +01:00
NULL,NULL,
2017-06-12 15:03:29 +02:00
NULL,Box_CLOSABLE,5);
2016-09-26 11:49:18 +02:00
/***** Initialize structure with user's data *****/
Usr_UsrDataConstructor (&UsrDat);
2016-09-22 18:04:25 +02:00
/***** List users found *****/
for (NumUsr = 1, The_ResetRowColor ();
2016-09-22 22:09:24 +02:00
NumUsr <= NumUsrs;
NumUsr++, The_ChangeRowColor ())
2016-09-22 18:04:25 +02:00
{
2016-09-26 11:49:18 +02:00
/***** Get user's data from query result *****/
2016-09-23 15:03:25 +02:00
/* Get user's code */
UsrDat.UsrCod = DB_GetNextCode (mysql_res);
2016-09-22 13:33:42 +02:00
2016-09-26 11:49:18 +02:00
/* Get user's data */
Usr_GetAllUsrDataFromUsrCod (&UsrDat,
Usr_DONT_GET_PREFS,
Usr_DONT_GET_ROLE_IN_CRS);
2016-09-23 15:03:25 +02:00
2016-09-26 18:09:19 +02:00
/***** Write row with data of empty account *****/
Acc_WriteRowEmptyAccount (NumUsr,ID,&UsrDat);
2016-09-22 18:04:25 +02:00
}
2016-09-26 11:49:18 +02:00
/***** Free memory used for user's data *****/
Usr_UsrDataDestructor (&UsrDat);
2017-06-12 14:16:33 +02:00
/***** End table and box *****/
2019-11-25 23:18:08 +01:00
Box_BoxTableEnd ();
2016-09-22 13:33:42 +02:00
}
2016-09-22 18:04:25 +02:00
else
2019-02-16 14:37:34 +01:00
Ale_ShowAlert (Ale_INFO,Txt_There_is_no_empty_account_associated_with_your_ID_X,
2019-02-15 23:38:44 +01:00
ID);
2016-09-22 18:04:25 +02:00
/***** Free structure that stores the query result *****/
DB_FreeMySQLResult (&mysql_res);
2016-09-26 11:49:18 +02:00
/**** Show form to check if I have an account *****/
2016-09-26 14:47:07 +02:00
Acc_ShowFormCheckIfIHaveAccount (Txt_Check_another_ID);
2016-09-22 18:04:25 +02:00
}
2016-09-26 11:49:18 +02:00
else // ID not valid
{
/**** Show again form to check if I have an account *****/
2019-02-16 14:37:34 +01:00
Ale_ShowAlert (Ale_WARNING,Txt_Please_enter_your_ID);
2016-09-22 18:04:25 +02:00
2017-06-10 20:56:50 +02:00
Acc_ShowFormCheckIfIHaveAccount (Txt_Before_creating_a_new_account_check_if_you_have_been_already_registered);
2016-09-26 11:49:18 +02:00
}
2016-09-22 13:33:42 +02:00
}
2016-09-26 18:09:19 +02:00
/*****************************************************************************/
/************************ Write data of empty account ************************/
/*****************************************************************************/
static void Acc_WriteRowEmptyAccount (unsigned NumUsr,const char *ID,struct Usr_Data *UsrDat)
2016-09-26 18:09:19 +02:00
{
extern const char *Txt_ID;
extern const char *Txt_Name;
extern const char *Txt_yet_unnamed;
extern const char *Txt_Its_me;
/***** Begin 1st table row *****/
2019-10-23 19:05:05 +02:00
HTM_TR_Begin (NULL);
2019-10-07 22:28:16 +02:00
/***** Write number of user in the list *****/
HTM_TD_Begin ("rowspan=\"2\" class=\"RT USR_LIST_NUM_N_%s %s\"",
The_GetSuffix (),
The_GetColorRows ());
HTM_Unsigned (NumUsr);
HTM_TD_End ();
/***** Write user's ID and name *****/
HTM_TD_Begin ("class=\"LT DAT_STRONG_%s %s\"",
The_GetSuffix (),
The_GetColorRows ());
HTM_TxtColon (Txt_ID);
HTM_NBSPTxt (ID);
HTM_BR ();
HTM_TxtColonNBSP (Txt_Name);
if (UsrDat->FullName[0])
{
HTM_STRONG_Begin ();
HTM_Txt (UsrDat->FullName);
HTM_STRONG_End ();
}
else
{
HTM_EM_Begin ();
HTM_Txt (Txt_yet_unnamed);
HTM_EM_End ();
}
HTM_TD_End ();
2016-09-26 18:09:19 +02:00
/***** Button to login with this account *****/
HTM_TD_Begin ("class=\"RT %s\"",The_GetColorRows ());
Frm_BeginForm (ActLogInNew);
Usr_PutParUsrCodEncrypted (UsrDat->EnUsrCod);
Btn_PutCreateButtonInline (Txt_Its_me);
Frm_EndForm ();
HTM_TD_End ();
2019-10-07 22:28:16 +02:00
/***** End 1st table row *****/
2019-10-23 19:05:05 +02:00
HTM_TR_End ();
/***** Begin 2nd table row *****/
2019-10-23 19:05:05 +02:00
HTM_TR_Begin (NULL);
2016-09-26 18:09:19 +02:00
/***** Courses of this user *****/
HTM_TD_Begin ("colspan=\"2\" class=\"LT %s\"",The_GetColorRows ());
UsrDat->Sex = Usr_SEX_UNKNOWN;
Crs_GetAndWriteCrssOfAUsr (UsrDat,Rol_TCH);
Crs_GetAndWriteCrssOfAUsr (UsrDat,Rol_NET);
Crs_GetAndWriteCrssOfAUsr (UsrDat,Rol_STD);
HTM_TD_End ();
2019-10-07 22:28:16 +02:00
/***** End 2nd table row *****/
2019-10-23 19:05:05 +02:00
HTM_TR_End ();
2016-09-26 18:09:19 +02:00
}
2019-07-04 10:39:42 +02:00
/*****************************************************************************/
/********************* Show form to create a new account *********************/
/*****************************************************************************/
void Acc_ShowFormCreateMyAccount (void)
{
2019-10-24 09:46:20 +02:00
/***** Contextual menu *****/
Mnu_ContextMenuBegin ();
Usr_PutLinkToLogin ();
Pwd_PutLinkToSendNewPasswd ();
Lan_PutLinkToChangeLanguage ();
2019-10-24 09:46:20 +02:00
Mnu_ContextMenuEnd ();
2019-07-04 12:58:15 +02:00
2019-07-04 10:39:42 +02:00
/**** Show form to create a new account *****/
Acc_ShowFormRequestNewAccountWithPars ("","");
2019-07-04 10:39:42 +02:00
}
2016-02-29 16:22:11 +01:00
/*****************************************************************************/
/************ Show form to create a new account using parameters *************/
/*****************************************************************************/
static void Acc_ShowFormRequestNewAccountWithPars (const char *NewNickWithoutArr,
const char *NewEmail)
2014-12-12 22:39:55 +01:00
{
2017-03-02 21:18:52 +01:00
extern const char *Hlp_PROFILE_SignUp;
extern const char *Txt_Actions[ActLst_NUM_ACTIONS];
extern const char *Txt_Create;
2014-12-12 22:39:55 +01:00
2019-10-20 22:00:28 +02:00
/***** Begin form to enter some data of the new user *****/
Frm_BeginForm (ActCreUsrAcc);
2017-06-12 14:16:33 +02:00
/***** Begin box and table *****/
Box_BoxTableBegin (Txt_Actions[ActCreUsrAcc],NULL,NULL,
Hlp_PROFILE_SignUp,Box_NOT_CLOSABLE,2);
2014-12-12 22:39:55 +01:00
/***** Nickname *****/
Nck_PutFormToGetNewNickname (NewNickWithoutArr);
/***** Email *****/
Mai_PutFormToGetNewEmail (NewEmail);
/***** Password *****/
Pwd_PutFormToGetNewPasswordOnce ();
2014-12-12 22:39:55 +01:00
/***** End table, send button and end box *****/
Box_BoxTableWithButtonEnd (Btn_CREATE_BUTTON,Txt_Create);
2017-06-12 14:16:33 +02:00
/***** End form *****/
2018-11-09 20:47:39 +01:00
Frm_EndForm ();
2014-12-12 22:39:55 +01:00
}
2016-03-21 19:52:40 +01:00
/*****************************************************************************/
/********* Show form to go to request the creation of a new account **********/
/*****************************************************************************/
void Acc_ShowFormGoToRequestNewAccount (void)
{
2017-03-02 21:18:52 +01:00
extern const char *Hlp_PROFILE_SignUp;
2016-03-21 19:52:40 +01:00
extern const char *Txt_New_on_PLATFORM_Sign_up;
extern const char *Txt_Actions[ActLst_NUM_ACTIONS];
char *Title;
2016-03-21 19:52:40 +01:00
2019-10-26 02:19:42 +02:00
/***** Begin box *****/
if (asprintf (&Title,Txt_New_on_PLATFORM_Sign_up,Cfg_PLATFORM_SHORT_NAME) < 0)
Err_NotEnoughMemoryExit ();
Box_BoxBegin (Title,NULL,NULL,Hlp_PROFILE_SignUp,Box_NOT_CLOSABLE);
free (Title);
2016-03-21 19:52:40 +01:00
/***** Button to go to request the creation of a new account *****/
Frm_BeginForm (ActFrmMyAcc);
Btn_PutCreateButton (Txt_Actions[ActCreUsrAcc]);
Frm_EndForm ();
2016-03-21 19:52:40 +01:00
2017-06-12 14:16:33 +02:00
/***** End box *****/
2019-10-25 22:48:34 +02:00
Box_BoxEnd ();
2016-03-21 19:52:40 +01:00
}
2014-12-12 22:39:55 +01:00
/*****************************************************************************/
/*********************** Show form to change my account **********************/
/*****************************************************************************/
2018-10-15 14:07:12 +02:00
void Acc_ShowFormChgMyAccount (void)
2014-12-12 22:39:55 +01:00
{
2018-10-25 14:29:38 +02:00
extern const char *Txt_Before_going_to_any_other_option_you_must_create_your_password;
extern const char *Txt_Before_going_to_any_other_option_you_must_fill_your_nickname;
2019-02-15 21:09:18 +01:00
extern const char *Txt_Before_going_to_any_other_option_you_must_fill_in_your_email_address;
bool IMustCreateMyPasswordNow = false;
bool IMustCreateMyNicknameNow = false;
bool IMustFillInMyEmailNow = false;
bool IShouldConfirmMyEmailNow = false;
bool IShouldFillInMyIDNow = false;
2014-12-12 22:39:55 +01:00
2016-11-16 23:19:52 +01:00
/***** Get current user's nickname and email address
It's necessary because current nickname or email could be just updated *****/
Nck_DB_GetNicknameFromUsrCod (Gbl.Usrs.Me.UsrDat.UsrCod,Gbl.Usrs.Me.UsrDat.Nickname);
2015-11-16 14:54:12 +01:00
Mai_GetEmailFromUsrCod (&Gbl.Usrs.Me.UsrDat);
2014-12-12 22:39:55 +01:00
2016-11-16 23:19:52 +01:00
/***** Check nickname, email and ID *****/
2019-02-15 21:09:18 +01:00
IMustCreateMyPasswordNow = (Gbl.Usrs.Me.UsrDat.Password[0] == '\0');
if (IMustCreateMyPasswordNow)
2019-02-16 14:37:34 +01:00
Ale_ShowAlert (Ale_WARNING,Txt_Before_going_to_any_other_option_you_must_create_your_password);
2019-02-15 21:09:18 +01:00
else
{
IMustCreateMyNicknameNow = (Gbl.Usrs.Me.UsrDat.Nickname[0] == '\0');
if (IMustCreateMyNicknameNow)
2019-02-16 14:37:34 +01:00
Ale_ShowAlert (Ale_WARNING,Txt_Before_going_to_any_other_option_you_must_fill_your_nickname);
2019-02-15 21:09:18 +01:00
else
{
IMustFillInMyEmailNow = (Gbl.Usrs.Me.UsrDat.Email[0] == '\0');
if (IMustFillInMyEmailNow)
2019-02-16 14:37:34 +01:00
Ale_ShowAlert (Ale_WARNING,Txt_Before_going_to_any_other_option_you_must_fill_in_your_email_address);
2019-02-15 21:09:18 +01:00
else
{
IShouldConfirmMyEmailNow = (!Gbl.Usrs.Me.UsrDat.EmailConfirmed && // Email not yet confirmed
!Gbl.Usrs.Me.ConfirmEmailJustSent); // Do not ask for email confirmation when confirmation email is just sent
IShouldFillInMyIDNow = (Gbl.Usrs.Me.UsrDat.IDs.Num == 0);
}
}
}
2014-12-12 22:39:55 +01:00
/***** Begin container for this user *****/
2019-10-23 21:37:01 +02:00
HTM_DIV_Begin ("class=\"REC_USR\"");
2014-12-12 22:39:55 +01:00
/***** Show form to change my password and my nickname ****/
HTM_DIV_Begin ("class=\"REC_LEFT\"");
Pwd_ShowFormChgMyPwd ();
Nck_ShowFormChangeMyNickname (IMustCreateMyNicknameNow);
HTM_DIV_End ();
2014-12-12 22:39:55 +01:00
/***** Show form to change my email and my ID *****/
HTM_DIV_Begin ("class=\"REC_RIGHT\"");
Mai_ShowFormChangeMyEmail (IMustFillInMyEmailNow,IShouldConfirmMyEmailNow);
ID_ShowFormChangeMyID (IShouldFillInMyIDNow);
HTM_DIV_End ();
2014-12-12 22:39:55 +01:00
/***** Begin container for this user *****/
2019-10-23 20:07:56 +02:00
HTM_DIV_End ();
2014-12-12 22:39:55 +01:00
}
2018-10-16 01:36:13 +02:00
/*****************************************************************************/
/***************** Show form to change another user's account ****************/
/*****************************************************************************/
void Acc_ShowFormChgOtherUsrAccount (void)
{
/***** Get user whose account must be changed *****/
if (Usr_GetParOtherUsrCodEncryptedAndGetUsrData ())
switch (Usr_CheckIfICanEditOtherUsr (&Gbl.Usrs.Other.UsrDat))
{
case Usr_CAN:
/***** Get user's nickname and email address
It's necessary because nickname or email could be just updated *****/
Nck_DB_GetNicknameFromUsrCod (Gbl.Usrs.Other.UsrDat.UsrCod,Gbl.Usrs.Other.UsrDat.Nickname);
Mai_GetEmailFromUsrCod (&Gbl.Usrs.Other.UsrDat);
/***** Show user's record *****/
Rec_ShowSharedUsrRecord (Rec_SHA_RECORD_LIST,
&Gbl.Usrs.Other.UsrDat,NULL);
/***** Begin container for this user *****/
HTM_DIV_Begin ("class=\"REC_USR\"");
/***** Show form to change password and nickname *****/
HTM_DIV_Begin ("class=\"REC_LEFT\"");
Pwd_ShowFormChgOtherUsrPwd ();
Nck_ShowFormChangeOtherUsrNickname ();
HTM_DIV_End ();
/***** Show form to change email and ID *****/
HTM_DIV_Begin ("class=\"REC_RIGHT\"");
Mai_ShowFormChangeOtherUsrEmail ();
ID_ShowFormChangeOtherUsrID ();
HTM_DIV_End ();
/***** End container for this user *****/
HTM_DIV_End ();
break;
case Usr_CAN_NOT:
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
}
2014-12-12 22:39:55 +01:00
/*****************************************************************************/
2018-10-09 20:40:41 +02:00
/************* Put an icon (form) to request removing my account *************/
2014-12-12 22:39:55 +01:00
/*****************************************************************************/
2020-04-08 13:40:21 +02:00
void Acc_PutLinkToRemoveMyAccount (__attribute__((unused)) void *Args)
2014-12-12 22:39:55 +01:00
{
if (Acc_CheckIfICanEliminateAccount (Gbl.Usrs.Me.UsrDat.UsrCod) == Usr_CAN)
2020-04-08 13:40:21 +02:00
Lay_PutContextualLinkOnlyIcon (ActReqRemMyAcc,NULL,
Acc_PutParsToRemoveMyAccount,Gbl.Usrs.Me.UsrDat.EnUsrCod,
"trash.svg",Ico_RED);
2015-04-02 18:39:49 +02:00
}
static void Acc_PutParsToRemoveMyAccount (void *EncryptedUsrCod)
2015-04-02 18:39:49 +02:00
{
Usr_PutParMyUsrCodEncrypted (EncryptedUsrCod);
Par_PutParUnsigned (NULL,"RegRemAction",
(unsigned) Enr_ELIMINATE_ONE_USR_FROM_PLATFORM);
2014-12-12 22:39:55 +01:00
}
/*****************************************************************************/
/*************** Create new user account with an ID and login ****************/
/*****************************************************************************/
// Return true if no error and user can be logged in
// Return false on error
2016-11-08 00:58:32 +01:00
bool Acc_CreateMyNewAccountAndLogIn (void)
2014-12-12 22:39:55 +01:00
{
char NewNickWithoutArr[Nck_MAX_BYTES_NICK_WITHOUT_ARROBA + 1];
2017-03-13 13:17:53 +01:00
char NewEmail[Cns_MAX_BYTES_EMAIL_ADDRESS + 1];
2017-03-13 14:22:36 +01:00
char NewEncryptedPassword[Pwd_BYTES_ENCRYPTED_PASSWORD + 1];
2014-12-12 22:39:55 +01:00
if (Acc_GetParsNewAccount (NewNickWithoutArr,NewEmail,NewEncryptedPassword))
2014-12-12 22:39:55 +01:00
{
/***** User's has no ID *****/
Gbl.Usrs.Me.UsrDat.IDs.Num = 0;
Gbl.Usrs.Me.UsrDat.IDs.List = NULL;
/***** Set password to the password typed by the user *****/
2017-01-15 18:02:52 +01:00
Str_Copy (Gbl.Usrs.Me.UsrDat.Password,NewEncryptedPassword,
sizeof (Gbl.Usrs.Me.UsrDat.Password) - 1);
2014-12-12 22:39:55 +01:00
/***** User does not exist in the platform, so create him/her! *****/
Acc_CreateNewUsr (&Gbl.Usrs.Me.UsrDat,Usr_ME);
2014-12-12 22:39:55 +01:00
/***** Save nickname *****/
Nck_DB_UpdateNick (Gbl.Usrs.Me.UsrDat.UsrCod,NewNickWithoutArr);
Str_Copy (Gbl.Usrs.Me.UsrDat.Nickname,NewNickWithoutArr,
sizeof (Gbl.Usrs.Me.UsrDat.Nickname) - 1);
2014-12-12 22:39:55 +01:00
2016-11-16 23:19:52 +01:00
/***** Save email *****/
2014-12-12 22:39:55 +01:00
if (Mai_UpdateEmailInDB (&Gbl.Usrs.Me.UsrDat,NewEmail))
{
2016-11-16 23:19:52 +01:00
/* Email updated sucessfully */
2017-01-17 03:10:43 +01:00
Str_Copy (Gbl.Usrs.Me.UsrDat.Email,NewEmail,
sizeof (Gbl.Usrs.Me.UsrDat.Email) - 1);
2017-01-13 01:51:23 +01:00
2014-12-12 22:39:55 +01:00
Gbl.Usrs.Me.UsrDat.EmailConfirmed = false;
}
return true;
}
else
{
/***** Show form again ******/
Acc_ShowFormRequestNewAccountWithPars (NewNickWithoutArr,NewEmail);
2014-12-12 22:39:55 +01:00
return false;
}
}
/*****************************************************************************/
/************* Get parameters for the creation of a new account **************/
/*****************************************************************************/
// Return false on error
static bool Acc_GetParsNewAccount (char NewNickWithoutArr[Nck_MAX_BYTES_NICK_WITHOUT_ARROBA + 1],
char NewEmail[Cns_MAX_BYTES_EMAIL_ADDRESS + 1],
char NewEncryptedPassword[Pwd_BYTES_ENCRYPTED_PASSWORD + 1])
2014-12-12 22:39:55 +01:00
{
extern const char *Txt_The_nickname_had_been_registered_by_another_user;
extern const char *Txt_The_nickname_is_not_valid_;
2014-12-12 22:39:55 +01:00
extern const char *Txt_The_email_address_X_had_been_registered_by_another_user;
extern const char *Txt_The_email_address_entered_X_is_not_valid;
char NewNick[Nck_MAX_BYTES_NICK_WITH_ARROBA + 1];
2017-03-07 01:56:41 +01:00
char NewPlainPassword[Pwd_MAX_BYTES_PLAIN_PASSWORD + 1];
2014-12-12 22:39:55 +01:00
bool Error = false;
/***** Step 1/3: Get new nickname from form *****/
Par_GetParText ("NewNick",NewNick,sizeof (NewNick) - 1);
2016-03-21 19:52:40 +01:00
/* Remove arrobas at the beginning */
Str_RemoveLeadingArrobas (NewNick);
Str_Copy (NewNickWithoutArr,NewNick,sizeof (NewNick) - 1);
2016-03-21 19:52:40 +01:00
/* Create a new version of the nickname with arroba */
snprintf (NewNick,sizeof (NewNick),"@%s",
NewNickWithoutArr);
2014-12-12 22:39:55 +01:00
if (Nck_CheckIfNickWithArrIsValid (NewNick)) // If new nickname is valid
2014-12-12 22:39:55 +01:00
{
2016-03-21 19:52:40 +01:00
/* Check if the new nickname
matches any of the nicknames of other users */
if (Acc_DB_CheckIfNicknameAlreadyExists (NewNickWithoutArr))
2014-12-12 22:39:55 +01:00
{
Error = true;
Ale_ShowAlert (Ale_WARNING,Txt_The_nickname_had_been_registered_by_another_user);
2014-12-12 22:39:55 +01:00
}
}
else // New nickname is not valid
{
Error = true;
Ale_ShowAlert (Ale_WARNING,Txt_The_nickname_is_not_valid_,
Nck_MIN_CHARS_NICK_WITHOUT_ARROBA,
Nck_MAX_CHARS_NICK_WITHOUT_ARROBA);
2014-12-12 22:39:55 +01:00
}
2016-11-16 23:19:52 +01:00
/***** Step 2/3: Get new email from form *****/
Par_GetParText ("NewEmail",NewEmail,Cns_MAX_BYTES_EMAIL_ADDRESS);
2014-12-12 22:39:55 +01:00
2016-11-16 23:19:52 +01:00
if (Mai_CheckIfEmailIsValid (NewEmail)) // New email is valid
2014-12-12 22:39:55 +01:00
{
2016-11-16 23:19:52 +01:00
/* Check if the new email matches
any of the confirmed emails of other users */
if (Acc_DB_CheckIfEmailAlreadyExists (NewEmail)) // An email of another user is the same that my email
2014-12-12 22:39:55 +01:00
{
Error = true;
2019-02-16 14:37:34 +01:00
Ale_ShowAlert (Ale_WARNING,Txt_The_email_address_X_had_been_registered_by_another_user,
2019-02-15 23:38:44 +01:00
NewEmail);
2014-12-12 22:39:55 +01:00
}
}
2016-11-16 23:19:52 +01:00
else // New email is not valid
2014-12-12 22:39:55 +01:00
{
Error = true;
2019-02-16 14:37:34 +01:00
Ale_ShowAlert (Ale_WARNING,Txt_The_email_address_entered_X_is_not_valid,
2019-02-15 23:38:44 +01:00
NewEmail);
2014-12-12 22:39:55 +01:00
}
2015-07-13 12:34:26 +02:00
/***** Step 3/3: Get new password from form *****/
Par_GetParText ("Paswd",NewPlainPassword,Pwd_MAX_BYTES_PLAIN_PASSWORD);
2015-11-20 21:11:33 +01:00
Cry_EncryptSHA512Base64 (NewPlainPassword,NewEncryptedPassword);
if (!Pwd_SlowCheckIfPasswordIsGood (NewPlainPassword,NewEncryptedPassword,-1L)) // New password is good?
2014-12-12 22:39:55 +01:00
{
Error = true;
2019-03-09 20:12:44 +01:00
Ale_ShowAlerts (NULL); // Error message is set in Pwd_SlowCheckIfPasswordIsGood
2014-12-12 22:39:55 +01:00
}
return !Error;
}
/*****************************************************************************/
/****************************** Create new user ******************************/
/*****************************************************************************/
// UsrDat->UsrCod must be <= 0
// UsrDat->UsrDat.IDs must contain a list of IDs for the new user
void Acc_CreateNewUsr (struct Usr_Data *UsrDat,Usr_MeOrOther_t MeOrOther)
2014-12-12 22:39:55 +01:00
{
2017-01-28 15:58:46 +01:00
char PathRelUsr[PATH_MAX + 1];
2014-12-12 22:39:55 +01:00
unsigned NumID;
/***** Trivial check: user's code should be <= 0 *****/
2014-12-12 22:39:55 +01:00
if (UsrDat->UsrCod > 0)
Err_ShowErrorAndExit ("Can not create new user.");
2014-12-12 22:39:55 +01:00
/***** Create encrypted user's code *****/
Acc_CreateNewEncryptedUsrCod (UsrDat);
/***** Filter some user's data before inserting */
Usr_FilterUsrBirthday (&UsrDat->Birthday);
2014-12-12 22:39:55 +01:00
/***** Insert new user in database *****/
/* Insert user's data */
UsrDat->UsrCod = Acc_DB_CreateNewUsr (UsrDat);
2014-12-12 22:39:55 +01:00
/* Insert user's IDs as confirmed */
for (NumID = 0;
NumID < UsrDat->IDs.Num;
NumID++)
{
Str_ConvertToUpperText (UsrDat->IDs.List[NumID].ID);
ID_DB_InsertANewUsrID (UsrDat->UsrCod,
UsrDat->IDs.List[NumID].ID,
UsrDat->IDs.List[NumID].Confirmed);
2014-12-12 22:39:55 +01:00
}
/***** Create directory for the user, if not exists *****/
Usr_ConstructPathUsr (UsrDat->UsrCod,PathRelUsr);
Fil_CreateDirIfNotExists (PathRelUsr);
2015-03-28 18:34:08 +01:00
/***** Create user's figures *****/
Prf_CreateNewUsrFigures (UsrDat->UsrCod,MeOrOther);
2014-12-12 22:39:55 +01:00
}
/*****************************************************************************/
/******************** Create a new encrypted user's code *********************/
/*****************************************************************************/
#define LENGTH_RANDOM_STR 32
#define MAX_TRY 10
static void Acc_CreateNewEncryptedUsrCod (struct Usr_Data *UsrDat)
2014-12-12 22:39:55 +01:00
{
2017-01-28 15:58:46 +01:00
char RandomStr[LENGTH_RANDOM_STR + 1];
2014-12-12 22:39:55 +01:00
unsigned NumTry;
for (NumTry = 0;
NumTry < MAX_TRY;
NumTry++)
{
Str_CreateRandomAlphanumStr (RandomStr,LENGTH_RANDOM_STR);
Cry_EncryptSHA256Base64 (RandomStr,UsrDat->EnUsrCod);
if (Usr_DB_GetUsrCodFromEncryptedUsrCod (UsrDat->EnUsrCod) <= 0)
break;
2014-12-12 22:39:55 +01:00
}
if (NumTry == MAX_TRY)
Err_ShowErrorAndExit ("Can not create a new encrypted user's code.");
2014-12-12 22:39:55 +01:00
}
/*****************************************************************************/
/***************** Message after creation of a new account *******************/
/*****************************************************************************/
void Acc_AfterCreationNewAccount (void)
{
2015-04-15 19:48:33 +02:00
extern const char *Txt_Congratulations_You_have_created_your_account_X_Now_Y_will_request_you_;
2014-12-12 22:39:55 +01:00
if (Gbl.Usrs.Me.Logged) // If account has been created without problem, I am logged
{
/***** Show message of success *****/
2019-02-16 14:37:34 +01:00
Ale_ShowAlert (Ale_SUCCESS,Txt_Congratulations_You_have_created_your_account_X_Now_Y_will_request_you_,
2019-02-15 23:38:44 +01:00
Gbl.Usrs.Me.UsrDat.Nickname,
Cfg_PLATFORM_SHORT_NAME);
2014-12-12 22:39:55 +01:00
/***** Show form with account data *****/
2018-10-15 14:07:12 +02:00
Acc_ShowFormChgMyAccount ();
2014-12-12 22:39:55 +01:00
}
}
/*****************************************************************************/
/************** Definite removing of a user from the platform ****************/
/*****************************************************************************/
2016-06-17 23:38:32 +02:00
void Acc_GetUsrCodAndRemUsrGbl (void)
2014-12-12 22:39:55 +01:00
{
2016-12-18 19:06:48 +01:00
bool Error = false;
2016-06-17 23:38:32 +02:00
if (Usr_GetParOtherUsrCodEncryptedAndGetUsrData ())
switch (Acc_CheckIfICanEliminateAccount (Gbl.Usrs.Other.UsrDat.UsrCod))
{
case Usr_CAN:
Acc_ReqRemAccountOrRemAccount (Acc_REMOVE_USR);
break;
case Usr_CAN_NOT:
default:
Error = true;
break;
}
else // User not found
2016-12-18 19:06:48 +01:00
Error = true;
if (Error)
2019-03-09 20:12:44 +01:00
Ale_ShowAlertUserNotFoundOrYouDoNotHavePermission ();
2014-12-12 22:39:55 +01:00
}
/*****************************************************************************/
2016-12-18 19:06:48 +01:00
/*************************** Remove a user account ***************************/
2014-12-12 22:39:55 +01:00
/*****************************************************************************/
2016-06-17 23:38:32 +02:00
void Acc_ReqRemAccountOrRemAccount (Acc_ReqOrRemUsr_t RequestOrRemove)
2014-12-12 22:39:55 +01:00
{
Usr_MeOrOther_t MeOrOther = Usr_ItsMe (Gbl.Usrs.Other.UsrDat.UsrCod);
2018-10-09 22:15:12 +02:00
2016-12-18 19:06:48 +01:00
switch (RequestOrRemove)
{
case Acc_REQUEST_REMOVE_USR: // Ask if eliminate completely the user from the platform
Acc_AskIfRemoveUsrAccount (MeOrOther);
2016-12-18 19:06:48 +01:00
break;
case Acc_REMOVE_USR: // Eliminate completely the user from the platform
if (Pwd_GetConfirmationOnDangerousAction ())
{
Acc_CompletelyEliminateAccount (&Gbl.Usrs.Other.UsrDat,Cns_VERBOSE);
2014-12-12 22:39:55 +01:00
2016-12-18 19:06:48 +01:00
/***** Move unused contents of messages to table of deleted contents of messages *****/
Msg_DB_MoveUnusedMsgsContentToDeleted ();
2016-12-18 19:06:48 +01:00
}
2018-10-09 22:15:12 +02:00
else
Acc_AskIfRemoveUsrAccount (MeOrOther);
2016-12-18 19:06:48 +01:00
break;
}
2014-12-12 22:39:55 +01:00
}
/*****************************************************************************/
/******** Check if I can eliminate completely another user's account *********/
/*****************************************************************************/
Usr_Can_t Acc_CheckIfICanEliminateAccount (long UsrCod)
2014-12-12 22:39:55 +01:00
{
Usr_MeOrOther_t MeOrOther = Usr_ItsMe (UsrCod);
2016-06-17 23:38:32 +02:00
2014-12-12 22:39:55 +01:00
// A user logged as superuser can eliminate any user except her/him
// Other users only can eliminate themselves
switch (MeOrOther)
{
case Usr_ME:
// A system admin can not eliminate him/herself
return ((Gbl.Usrs.Me.Role.Available & (1 << Rol_SYS_ADM)) == 0) ? Usr_CAN :
Usr_CAN_NOT;
case Usr_OTHER:
// Only a system admin can eliminate other's account
return Gbl.Usrs.Me.Role.Logged == Rol_SYS_ADM ? Usr_CAN :
Usr_CAN_NOT;
}
return Usr_CAN_NOT;
2014-12-12 22:39:55 +01:00
}
/*****************************************************************************/
/*********** Ask if really wanted to eliminate completely a user *************/
/*****************************************************************************/
static void Acc_AskIfRemoveUsrAccount (Usr_MeOrOther_t MeOrOther)
2015-09-16 00:15:20 +02:00
{
static void (*FuncAskIfRemoveUsrAccount[Usr_NUM_ME_OR_OTHER]) (void) =
{
[Usr_ME ] = Acc_AskIfRemoveMyAccount,
[Usr_OTHER] = Acc_AskIfRemoveOtherUsrAccount
};
FuncAskIfRemoveUsrAccount[MeOrOther] ();
2015-09-16 00:15:20 +02:00
}
void Acc_AskIfRemoveMyAccount (void)
2014-12-12 22:39:55 +01:00
{
extern const char *Txt_Do_you_really_want_to_completely_eliminate_your_user_account;
2015-03-28 18:34:08 +01:00
extern const char *Txt_Eliminate_my_user_account;
2015-09-16 00:15:20 +02:00
2017-04-28 00:13:28 +02:00
/***** Show question and button to remove my user account *****/
/* Begin alert */
Ale_ShowAlertAndButtonBegin (Ale_QUESTION,Txt_Do_you_really_want_to_completely_eliminate_your_user_account);
2015-09-16 00:15:20 +02:00
2017-04-28 00:13:28 +02:00
/* Show my record */
2016-11-18 01:07:00 +01:00
Rec_ShowSharedRecordUnmodifiable (&Gbl.Usrs.Me.UsrDat);
2015-09-16 00:15:20 +02:00
2017-04-28 00:13:28 +02:00
/* Show form to request confirmation */
Frm_BeginForm (ActRemMyAcc);
Pwd_AskForConfirmationOnDangerousAction ();
Btn_PutRemoveButton (Txt_Eliminate_my_user_account);
2018-11-09 20:47:39 +01:00
Frm_EndForm ();
2017-04-28 00:13:28 +02:00
/* End alert */
Ale_ShowAlertAndButtonEnd (ActUnk,NULL,NULL,
2020-03-26 02:54:30 +01:00
NULL,NULL,
Btn_NO_BUTTON,NULL);
2018-10-09 20:40:41 +02:00
2018-10-15 14:07:12 +02:00
/***** Show forms to change my account *****/
Acc_ShowFormChgMyAccount ();
2015-09-16 00:15:20 +02:00
}
static void Acc_AskIfRemoveOtherUsrAccount (void)
{
extern const char *Txt_Do_you_really_want_to_completely_eliminate_the_following_user;
2015-03-28 18:34:08 +01:00
extern const char *Txt_Eliminate_user_account;
2014-12-12 22:39:55 +01:00
if (Usr_DB_ChkIfUsrCodExists (Gbl.Usrs.Other.UsrDat.UsrCod))
2014-12-12 22:39:55 +01:00
{
2017-04-28 00:13:28 +02:00
/***** Show question and button to remove user account *****/
/* Begin alert */
Ale_ShowAlertAndButtonBegin (Ale_QUESTION,Txt_Do_you_really_want_to_completely_eliminate_the_following_user);
2014-12-12 22:39:55 +01:00
2017-04-27 23:54:29 +02:00
/* Show user's record */
2016-11-18 01:07:00 +01:00
Rec_ShowSharedRecordUnmodifiable (&Gbl.Usrs.Other.UsrDat);
2014-12-12 22:39:55 +01:00
2017-04-27 23:54:29 +02:00
/* Show form to request confirmation */
Frm_BeginForm (ActRemUsrGbl);
Usr_PutParOtherUsrCodEncrypted (Gbl.Usrs.Other.UsrDat.EnUsrCod);
Pwd_AskForConfirmationOnDangerousAction ();
Btn_PutRemoveButton (Txt_Eliminate_user_account);
2018-11-09 20:47:39 +01:00
Frm_EndForm ();
2017-04-27 23:54:29 +02:00
/* End alert */
Ale_ShowAlertAndButtonEnd (ActUnk,NULL,NULL,
2020-03-26 02:54:30 +01:00
NULL,NULL,
Btn_NO_BUTTON,NULL);
2014-12-12 22:39:55 +01:00
}
else
2019-03-09 20:12:44 +01:00
Ale_ShowAlertUserNotFoundOrYouDoNotHavePermission ();
2014-12-12 22:39:55 +01:00
}
/*****************************************************************************/
/************* Remove completely a user from the whole platform **************/
/*****************************************************************************/
2015-09-16 00:15:20 +02:00
void Acc_RemoveMyAccount (void)
{
if (Pwd_GetConfirmationOnDangerousAction ())
{
Acc_CompletelyEliminateAccount (&Gbl.Usrs.Me.UsrDat,Cns_VERBOSE);
/***** Move unused contents of messages to table of deleted contents of messages *****/
Msg_DB_MoveUnusedMsgsContentToDeleted ();
2015-09-16 00:15:20 +02:00
}
2018-10-09 22:15:12 +02:00
else
Acc_AskIfRemoveUsrAccount (Usr_ME);
2015-09-16 00:15:20 +02:00
}
void Acc_CompletelyEliminateAccount (struct Usr_Data *UsrDat,
2014-12-12 22:39:55 +01:00
Cns_QuietOrVerbose_t QuietOrVerbose)
{
extern const char *Txt_THE_USER_X_has_been_removed_from_all_his_her_courses;
extern const char *Txt_THE_USER_X_has_been_removed_as_administrator;
extern const char *Txt_Messages_of_THE_USER_X_have_been_deleted;
2016-11-05 12:30:41 +01:00
extern const char *Txt_Briefcase_of_THE_USER_X_has_been_removed;
2014-12-12 22:39:55 +01:00
extern const char *Txt_Photo_of_THE_USER_X_has_been_removed;
extern const char *Txt_Record_card_of_THE_USER_X_has_been_removed;
bool PhotoRemoved = false;
/***** Remove the works zones of the user in all courses *****/
2017-06-04 15:11:41 +02:00
Brw_RemoveUsrWorksInAllCrss (UsrDat); // Make this before of removing the user from the courses
2014-12-12 22:39:55 +01:00
/***** Remove the fields of course record in all courses *****/
Rec_DB_RemoveAllFieldContentsFromUsrRecords (UsrDat->UsrCod);
2014-12-12 22:39:55 +01:00
2017-09-24 22:35:18 +02:00
/***** Remove user from all his/her projects *****/
Prj_RemoveUsrFromProjects (UsrDat->UsrCod);
/***** Remove user from all attendance events *****/
Att_DB_RemoveUsrFromAllEvents (UsrDat->UsrCod);
2014-12-12 22:39:55 +01:00
/***** Remove user from all groups of all courses *****/
2017-06-20 14:43:26 +02:00
Grp_RemUsrFromAllGrps (UsrDat->UsrCod);
2014-12-12 22:39:55 +01:00
/***** Remove user's requests for enrolment *****/
Enr_DB_RemUsrRequests (UsrDat->UsrCod);
2014-12-12 22:39:55 +01:00
2016-06-15 14:52:43 +02:00
/***** Remove user from possible duplicate users *****/
Dup_DB_RemoveUsrFromDuplicated (UsrDat->UsrCod);
2016-06-15 14:52:43 +02:00
2020-04-30 01:55:23 +02:00
/***** Remove user from the tables of courses and users *****/
Set_DB_RemUsrFromAllCrssSettings (UsrDat->UsrCod);
Enr_DB_RemUsrFromAllCrss (UsrDat->UsrCod);
2014-12-12 22:39:55 +01:00
if (QuietOrVerbose == Cns_VERBOSE)
2019-02-16 14:37:34 +01:00
Ale_ShowAlert (Ale_SUCCESS,Txt_THE_USER_X_has_been_removed_from_all_his_her_courses,
2019-02-15 23:38:44 +01:00
UsrDat->FullName);
2014-12-12 22:39:55 +01:00
/***** Remove user as administrator of any degree/center/institution *****/
Adm_DB_RemUsrAsAdmin (UsrDat->UsrCod);
2014-12-12 22:39:55 +01:00
if (QuietOrVerbose == Cns_VERBOSE)
2019-02-16 14:37:34 +01:00
Ale_ShowAlert (Ale_SUCCESS,Txt_THE_USER_X_has_been_removed_as_administrator,
2019-02-15 23:38:44 +01:00
UsrDat->FullName);
2014-12-12 22:39:55 +01:00
2015-01-25 18:50:43 +01:00
/***** Remove user's clipboard in forums *****/
For_DB_RemoveUsrFromClipboard (UsrDat->UsrCod);
2014-12-12 22:39:55 +01:00
2015-01-25 18:50:43 +01:00
/***** Remove some files of the user's from database *****/
Brw_DB_RemoveUsrFiles (UsrDat->UsrCod);
2015-01-25 18:50:43 +01:00
/***** Remove the file tree of a user *****/
Acc_RemoveUsrBriefcase (UsrDat);
if (QuietOrVerbose == Cns_VERBOSE)
2019-02-16 14:37:34 +01:00
Ale_ShowAlert (Ale_SUCCESS,Txt_Briefcase_of_THE_USER_X_has_been_removed,
2019-02-15 23:38:44 +01:00
UsrDat->FullName);
2014-12-12 22:39:55 +01:00
2020-05-18 22:59:07 +02:00
/***** Remove test, exams and matches made by user in all courses *****/
2020-05-18 14:34:31 +02:00
TstPrn_RemovePrintsMadeByUsrInAllCrss (UsrDat->UsrCod);
Exa_DB_RemovePrintQstsMadeByUsrInAllCrss (UsrDat->UsrCod);
Exa_DB_RemoveAllPrintsMadeByUsrInAllCrss (UsrDat->UsrCod);
2020-05-18 22:59:07 +02:00
Mch_RemoveMatchesMadeByUsrInAllCrss (UsrDat->UsrCod);
2014-12-12 22:39:55 +01:00
/***** Remove user's notifications *****/
Ntf_DB_RemoveUsrNtfs (UsrDat->UsrCod);
2014-12-12 22:39:55 +01:00
/***** Delete user's messages sent and received *****/
Msg_DB_RemoveAllRecAndSntMsgsUsr (UsrDat->UsrCod);
2014-12-12 22:39:55 +01:00
if (QuietOrVerbose == Cns_VERBOSE)
2019-02-16 14:37:34 +01:00
Ale_ShowAlert (Ale_SUCCESS,Txt_Messages_of_THE_USER_X_have_been_deleted,
2019-02-15 23:38:44 +01:00
UsrDat->FullName);
2014-12-12 22:39:55 +01:00
2015-03-29 01:06:00 +01:00
/***** Remove user from tables of banned users *****/
Prf_DB_RemoveUsrFromBanned (UsrDat->UsrCod);
Msg_DB_RemoveUsrFromBanned (UsrDat->UsrCod);
2014-12-12 22:39:55 +01:00
/***** Delete thread read status for this user *****/
For_DB_RemoveUsrFromReadThrs (UsrDat->UsrCod);
2014-12-12 22:39:55 +01:00
/***** Remove user from table of seen announcements *****/
Ann_DB_RemoveUsrFromSeenAnnouncements (UsrDat->UsrCod);
2014-12-12 22:39:55 +01:00
/***** Remove user from table of connected users *****/
Con_DB_RemoveUsrFromConnected (UsrDat->UsrCod);
2014-12-12 22:39:55 +01:00
/***** Remove all sessions of this user *****/
Ses_DB_RemoveUsrSessions (UsrDat->UsrCod);
2014-12-12 22:39:55 +01:00
2016-01-08 10:13:28 +01:00
/***** Remove social content associated to the user *****/
TmlUsr_RemoveUsrContent (UsrDat->UsrCod);
2016-01-08 10:13:28 +01:00
2015-03-11 12:48:41 +01:00
/***** Remove user's figures *****/
Prf_DB_RemoveUsrFigures (UsrDat->UsrCod);
2015-03-11 12:48:41 +01:00
2015-12-12 02:01:20 +01:00
/***** Remove user from table of followers *****/
Fol_RemoveUsrFromUsrFollow (UsrDat->UsrCod);
2016-12-03 19:34:43 +01:00
/***** Remove user's usage reports *****/
Rep_RemoveUsrUsageReports (UsrDat->UsrCod);
/***** Remove user's agenda *****/
Agd_DB_RemoveUsrEvents (UsrDat->UsrCod);
2016-12-03 19:34:43 +01:00
2014-12-12 22:39:55 +01:00
/***** Remove the user from the list of users without photo *****/
Pho_DB_RemoveUsrFromTableClicksWithoutPhoto (UsrDat->UsrCod);
2014-12-12 22:39:55 +01:00
/***** Remove user's photo *****/
PhotoRemoved = Pho_RemovePhoto (UsrDat);
if (PhotoRemoved && QuietOrVerbose == Cns_VERBOSE)
2019-02-16 14:37:34 +01:00
Ale_ShowAlert (Ale_SUCCESS,Txt_Photo_of_THE_USER_X_has_been_removed,
2019-02-15 23:38:44 +01:00
UsrDat->FullName);
2014-12-12 22:39:55 +01:00
/***** Remove user's webs / social networks *****/
Net_DB_RemoveUsrWebs (UsrDat->UsrCod);
/***** Remove user's nicknames *****/
Nck_DB_RemoveUsrNicknames (UsrDat->UsrCod);
/***** Remove user's emails *****/
Mai_DB_RemoveUsrPendingEmails (UsrDat->UsrCod);
Mai_DB_RemoveUsrEmails (UsrDat->UsrCod);
/***** Remove user's IDs *****/
ID_DB_RemoveUsrIDs (UsrDat->UsrCod);
/***** Remove user's last data *****/
Usr_DB_RemoveUsrLastData (UsrDat->UsrCod);
/***** Remove user's data *****/
Usr_DB_RemoveUsrData (UsrDat->UsrCod);
2014-12-12 22:39:55 +01:00
if (QuietOrVerbose == Cns_VERBOSE)
2019-02-16 14:37:34 +01:00
Ale_ShowAlert (Ale_SUCCESS,Txt_Record_card_of_THE_USER_X_has_been_removed,
2019-02-15 23:38:44 +01:00
UsrDat->FullName);
2014-12-12 22:39:55 +01:00
}
/*****************************************************************************/
/********************** Remove the briefcase of a user ***********************/
/*****************************************************************************/
static void Acc_RemoveUsrBriefcase (struct Usr_Data *UsrDat)
2014-12-12 22:39:55 +01:00
{
2017-01-28 15:58:46 +01:00
char PathRelUsr[PATH_MAX + 1];
2014-12-12 22:39:55 +01:00
2015-01-25 18:50:43 +01:00
/***** Remove files of the user's briefcase from disc *****/
2014-12-12 22:39:55 +01:00
Usr_ConstructPathUsr (UsrDat->UsrCod,PathRelUsr);
2016-10-06 22:18:33 +02:00
Fil_RemoveTree (PathRelUsr);
2014-12-12 22:39:55 +01:00
}
2018-10-16 01:36:13 +02:00
/*****************************************************************************/
/********* Put an icon to the action used to manage user's account ***********/
/*****************************************************************************/
void Acc_PutIconToChangeUsrAccount (struct Usr_Data *UsrDat)
2018-10-16 01:36:13 +02:00
{
static Act_Action_t NextAction[Rol_NUM_ROLES] =
{
[Rol_UNK ] = ActFrmAccOth,
[Rol_GST ] = ActFrmAccOth,
[Rol_USR ] = ActFrmAccOth,
[Rol_STD ] = ActFrmAccStd,
[Rol_NET ] = ActFrmAccTch,
[Rol_TCH ] = ActFrmAccTch,
[Rol_DEG_ADM] = ActFrmAccOth,
[Rol_CTR_ADM] = ActFrmAccOth,
[Rol_INS_ADM] = ActFrmAccOth,
[Rol_SYS_ADM] = ActFrmAccOth,
};
2018-10-16 01:36:13 +02:00
/***** Link for changing the account *****/
switch (Usr_ItsMe (UsrDat->UsrCod))
{
case Usr_ME:
Lay_PutContextualLinkOnlyIcon (ActFrmMyAcc,NULL,
NULL,NULL,
"at.svg",Ico_BLACK);
break;
case Usr_OTHER:
if (Usr_CheckIfICanEditOtherUsr (UsrDat) == Usr_CAN)
Lay_PutContextualLinkOnlyIcon (NextAction[UsrDat->Roles.InCurrentCrs],NULL,
Rec_PutParUsrCodEncrypted,NULL,
"at.svg",Ico_BLACK);
break;
}
2018-10-16 01:36:13 +02:00
}