swad-core/swad_account.c

1209 lines
44 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.
2019-01-07 21:52:19 +01:00
Copyright (C) 1999-2019 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 *********************************/
/*****************************************************************************/
#include <string.h> // For string functions
#include "swad_account.h"
#include "swad_announcement.h"
2017-06-10 21:38:10 +02:00
#include "swad_box.h"
2015-11-21 20:23:28 +01:00
#include "swad_calendar.h"
2014-12-12 22:39:55 +01:00
#include "swad_database.h"
2016-06-16 19:30:29 +02:00
#include "swad_duplicate.h"
2017-03-30 11:20:06 +02:00
#include "swad_enrolment.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"
2014-12-12 22:39:55 +01:00
#include "swad_global.h"
#include "swad_ID.h"
2017-05-07 18:06:34 +02:00
#include "swad_language.h"
2018-10-16 01:36:13 +02:00
#include "swad_nickname.h"
2014-12-12 22:39:55 +01:00
#include "swad_notification.h"
#include "swad_parameter.h"
2015-03-14 17:39:04 +01:00
#include "swad_profile.h"
2016-10-06 22:18:33 +02:00
#include "swad_report.h"
2019-03-12 21:25:55 +01:00
#include "swad_timeline.h"
2014-12-12 22:39:55 +01:00
/*****************************************************************************/
/****************************** Public constants *****************************/
/*****************************************************************************/
/*****************************************************************************/
/***************************** Private constants *****************************/
/*****************************************************************************/
/*****************************************************************************/
/****************************** Internal types *******************************/
/*****************************************************************************/
/*****************************************************************************/
/************** External global variables from others modules ****************/
/*****************************************************************************/
extern struct Globals Gbl;
/*****************************************************************************/
/************************* Internal global variables *************************/
/*****************************************************************************/
/*****************************************************************************/
/***************************** Private prototypes ****************************/
/*****************************************************************************/
2016-09-26 11:49:18 +02:00
static void Acc_ShowFormCheckIfIHaveAccount (const char *Title);
2016-09-26 18:09:19 +02:00
static void Acc_WriteRowEmptyAccount (unsigned NumUsr,const char *ID,struct UsrData *UsrDat);
2014-12-12 22:39:55 +01:00
static void Acc_ShowFormRequestNewAccountWithParams (const char *NewNicknameWithoutArroba,
const char *NewEmail);
2017-01-17 03:10:43 +01:00
static bool Acc_GetParamsNewAccount (char NewNicknameWithoutArroba[Nck_MAX_BYTES_NICKNAME_FROM_FORM + 1],
2014-12-12 22:39:55 +01:00
char *NewEmail,
char *NewEncryptedPassword);
static void Acc_CreateNewEncryptedUsrCod (struct UsrData *UsrDat);
2016-11-06 15:36:26 +01:00
static void Acc_PutParamsToRemoveMyAccount (void);
2015-04-02 18:39:49 +02:00
2015-09-16 00:15:20 +02:00
static void Acc_AskIfRemoveUsrAccount (bool ItsMe);
static void Acc_AskIfRemoveOtherUsrAccount (void);
2014-12-12 22:39:55 +01:00
static void Acc_RemoveUsrBriefcase (struct UsrData *UsrDat);
static void Acc_RemoveUsr (struct UsrData *UsrDat);
2016-03-01 03:16:29 +01:00
/*****************************************************************************/
/******************** Put link to create a new account ***********************/
/*****************************************************************************/
void Acc_PutLinkToCreateAccount (void)
{
extern const char *Txt_Create_account;
2019-01-12 03:00:59 +01:00
Lay_PutContextualLinkIconText (ActFrmMyAcc,NULL,NULL,
"at.svg",
Txt_Create_account);
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
{
2016-09-26 12:05:28 +02:00
/***** Links to other actions *****/
2016-02-29 16:22:11 +01:00
fprintf (Gbl.F.Out,"<div class=\"CONTEXT_MENU\">");
Usr_PutLinkToLogin ();
2017-05-07 18:06:34 +02:00
Lan_PutLinkToChangeLanguage ();
2016-02-29 16:22:11 +01:00
fprintf (Gbl.F.Out,"</div>");
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);
2016-09-28 00:10:41 +02:00
/**** Show form to create a new account *****/
Acc_ShowFormRequestNewAccountWithParams ("","");
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;
2019-02-22 21:47:50 +01:00
extern const char *The_ClassFormInBox[The_NUM_THEMES];
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;
2016-09-26 12:18:08 +02:00
extern const char *Txt_Check;
2016-09-22 13:33:42 +02:00
2017-06-12 14:16:33 +02:00
/***** Start box *****/
2017-06-10 21:38:10 +02:00
Box_StartBox (NULL,Title,NULL,
2017-06-12 15:03:29 +02:00
Hlp_PROFILE_SignUp,Box_CLOSABLE);
2017-06-10 20:56:50 +02:00
/***** Help alert *****/
2019-02-16 14:37:34 +01:00
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 *****/
2018-11-09 20:47:39 +01:00
Frm_StartForm (ActChkUsrAcc);
2016-09-22 13:33:42 +02:00
fprintf (Gbl.F.Out,"<label class=\"%s\">"
"%s:&nbsp;"
"<input type=\"text\" name=\"ID\""
2017-02-11 15:26:41 +01:00
" size=\"18\" maxlength=\"%u\" value=\"\""
" required=\"required\" />"
2016-12-20 02:18:50 +01:00
"</label>",
2019-02-22 21:47:50 +01:00
The_ClassFormInBox[Gbl.Prefs.Theme],Txt_ID,
2017-03-07 01:56:41 +01:00
ID_MAX_CHARS_USR_ID);
2017-06-11 19:02:40 +02:00
Btn_PutConfirmButton (Txt_Check);
2018-11-09 20:47:39 +01:00
Frm_EndForm ();
2016-09-22 13:33:42 +02:00
2017-06-12 14:16:33 +02:00
/***** End box *****/
2017-06-10 21:38:10 +02:00
Box_EndBox ();
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;
2016-09-22 18:04:25 +02:00
struct UsrData UsrDat;
MYSQL_RES *mysql_res;
MYSQL_ROW row;
2016-09-22 13:33:42 +02:00
2016-09-26 11:49:18 +02:00
/***** Links to other actions *****/
fprintf (Gbl.F.Out,"<div class=\"CONTEXT_MENU\">");
Usr_PutLinkToLogin ();
Pwd_PutLinkToSendNewPasswd ();
2017-05-07 18:06:34 +02:00
Lan_PutLinkToChangeLanguage ();
2016-09-26 11:49:18 +02:00
fprintf (Gbl.F.Out,"</div>");
2016-09-22 13:33:42 +02:00
/***** Get new user's ID from form *****/
2017-03-07 01:56:41 +01:00
Par_GetParToText ("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
{
2018-11-14 11:49:41 +01:00
NumUsrs = (unsigned) DB_QuerySELECT (&mysql_res,"can not get user's codes",
2018-10-30 09:02:14 +01:00
"SELECT usr_IDs.UsrCod"
" FROM usr_IDs,usr_data"
" WHERE usr_IDs.UsrID='%s'"
" AND usr_IDs.UsrCod=usr_data.UsrCod"
" AND usr_data.Password=''",
ID);
2016-09-22 18:04:25 +02:00
if (NumUsrs)
2016-09-22 13:33:42 +02:00
{
2017-06-12 14:16:33 +02:00
/***** Start box and table *****/
2017-06-10 21:38:10 +02:00
Box_StartBoxTable (NULL,
2017-06-11 22:26:40 +02:00
(NumUsrs == 1) ? Txt_Do_you_think_you_are_this_user :
Txt_Do_you_think_you_are_one_of_these_users,
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 *****/
2016-09-22 22:09:24 +02:00
for (NumUsr = 1, Gbl.RowEvenOdd = 0;
NumUsr <= NumUsrs;
NumUsr++, Gbl.RowEvenOdd = 1 - Gbl.RowEvenOdd)
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-22 18:04:25 +02:00
row = mysql_fetch_row (mysql_res);
2016-09-23 15:03:25 +02:00
/* Get user's code */
2016-09-22 18:04:25 +02:00
UsrDat.UsrCod = Str_ConvertStrCodToLongCod (row[0]);
2016-09-22 13:33:42 +02:00
2016-09-26 11:49:18 +02:00
/* Get user's data */
2019-03-19 13:22:14 +01:00
Usr_GetAllUsrDataFromUsrCod (&UsrDat,Usr_DONT_GET_PREFS);
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 *****/
2017-06-10 21:38:10 +02:00
Box_EndBoxTable ();
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-28 00:10:41 +02:00
/**** Show form to create a new account *****/
Acc_ShowFormRequestNewAccountWithParams ("","");
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 UsrData *UsrDat)
{
extern const char *Txt_ID;
extern const char *Txt_Name;
extern const char *Txt_yet_unnamed;
extern const char *Txt_Its_me;
/***** Write number of user in the list *****/
fprintf (Gbl.F.Out,"<tr>"
"<td rowspan=\"2\""
" class=\"USR_LIST_NUM_N RIGHT_TOP COLOR%u\">"
"%u"
"</td>",
Gbl.RowEvenOdd,NumUsr);
/***** Write user's ID and name *****/
fprintf (Gbl.F.Out,"<td class=\"DAT_N LEFT_TOP COLOR%u\">"
"%s: %s<br />"
"%s: ",
Gbl.RowEvenOdd,
Txt_ID,ID,
Txt_Name);
if (UsrDat->FullName[0])
fprintf (Gbl.F.Out,"<strong>%s</strong>",UsrDat->FullName);
else
fprintf (Gbl.F.Out,"<em>%s</em>",Txt_yet_unnamed);
fprintf (Gbl.F.Out,"</td>");
/***** Button to login with this account *****/
fprintf (Gbl.F.Out,"<td class=\"RIGHT_TOP COLOR%u\">",
Gbl.RowEvenOdd);
2018-11-09 20:47:39 +01:00
Frm_StartForm (ActLogInNew);
2016-09-26 18:09:19 +02:00
Usr_PutParamUsrCodEncrypted (UsrDat->EncryptedUsrCod);
2017-06-11 19:02:40 +02:00
Btn_PutCreateButtonInline (Txt_Its_me);
2018-11-09 20:47:39 +01:00
Frm_EndForm ();
2016-09-26 18:09:19 +02:00
fprintf (Gbl.F.Out,"</td>"
"</tr>");
/***** Courses of this user *****/
fprintf (Gbl.F.Out,"<tr>"
"<td colspan=\"2\" class=\"LEFT_TOP COLOR%u\">",
Gbl.RowEvenOdd);
UsrDat->Sex = Usr_SEX_UNKNOWN;
2017-05-18 19:13:41 +02:00
Crs_GetAndWriteCrssOfAUsr (UsrDat,Rol_TCH);
2017-05-21 21:23:13 +02:00
Crs_GetAndWriteCrssOfAUsr (UsrDat,Rol_NET);
2017-05-18 19:13:41 +02:00
Crs_GetAndWriteCrssOfAUsr (UsrDat,Rol_STD);
2016-09-26 18:09:19 +02:00
fprintf (Gbl.F.Out,"</td>"
"</tr>");
}
2016-02-29 16:22:11 +01:00
/*****************************************************************************/
/************ Show form to create a new account using parameters *************/
/*****************************************************************************/
2014-12-12 22:39:55 +01:00
static void Acc_ShowFormRequestNewAccountWithParams (const char *NewNicknameWithoutArroba,
const char *NewEmail)
{
2017-03-02 21:18:52 +01:00
extern const char *Hlp_PROFILE_SignUp;
2019-02-22 21:47:50 +01:00
extern const char *The_ClassFormInBox[The_NUM_THEMES];
2016-12-10 18:32:35 +01:00
extern const char *Txt_Create_account;
2014-12-12 22:39:55 +01:00
extern const char *Txt_Nickname;
2015-03-27 20:52:14 +01:00
extern const char *Txt_HELP_nickname;
extern const char *Txt_HELP_email;
2014-12-12 22:39:55 +01:00
extern const char *Txt_Email;
2017-01-28 15:58:46 +01:00
char NewNicknameWithArroba[Nck_MAX_BYTES_NICKNAME_FROM_FORM + 1];
2014-12-12 22:39:55 +01:00
2017-06-12 14:16:33 +02:00
/***** Start form to enter some data of the new user *****/
2018-11-09 20:47:39 +01:00
Frm_StartForm (ActCreUsrAcc);
2017-06-12 14:16:33 +02:00
/***** Start box and table *****/
2017-06-10 21:38:10 +02:00
Box_StartBoxTable (NULL,Txt_Create_account,NULL,
2017-06-12 15:03:29 +02:00
Hlp_PROFILE_SignUp,Box_NOT_CLOSABLE,2);
2014-12-12 22:39:55 +01:00
/***** Nickname *****/
2015-03-27 20:52:14 +01:00
if (NewNicknameWithoutArroba[0])
2018-10-17 01:08:42 +02:00
snprintf (NewNicknameWithArroba,sizeof (NewNicknameWithArroba),
"@%s",
NewNicknameWithoutArroba);
2015-03-27 20:52:14 +01:00
else
NewNicknameWithArroba[0] = '\0';
2016-11-14 10:05:41 +01:00
fprintf (Gbl.F.Out,"<tr>"
2016-12-20 20:48:53 +01:00
"<td class=\"RIGHT_MIDDLE\">"
"<label for=\"NewNick\" class=\"%s\">%s:</label>"
2015-07-27 21:25:45 +02:00
"</td>"
2015-07-28 00:51:32 +02:00
"<td class=\"LEFT_MIDDLE\">"
2016-12-20 20:48:53 +01:00
"<input type=\"text\" id=\"NewNick\" name=\"NewNick\""
2016-12-10 18:32:35 +01:00
" size=\"18\" maxlength=\"%u\""
2016-11-19 02:04:39 +01:00
" placeholder=\"%s\" value=\"%s\""
" required=\"required\" />"
2014-12-12 22:39:55 +01:00
"</td>"
"</tr>",
2019-02-22 21:47:50 +01:00
The_ClassFormInBox[Gbl.Prefs.Theme],
2014-12-12 22:39:55 +01:00
Txt_Nickname,
2017-03-07 01:56:41 +01:00
1 + Nck_MAX_CHARS_NICKNAME_WITHOUT_ARROBA,
2015-03-27 20:52:14 +01:00
Txt_HELP_nickname,
NewNicknameWithArroba);
2014-12-12 22:39:55 +01:00
2016-11-16 23:19:52 +01:00
/***** Email *****/
2014-12-12 22:39:55 +01:00
fprintf (Gbl.F.Out,"<tr>"
2016-12-20 20:48:53 +01:00
"<td class=\"RIGHT_MIDDLE\">"
"<label for=\"NewEmail\" class=\"%s\">%s:</label>"
2015-07-27 21:25:45 +02:00
"</td>"
2015-07-28 00:51:32 +02:00
"<td class=\"LEFT_MIDDLE\">"
2016-12-20 20:48:53 +01:00
"<input type=\"email\" id=\"NewEmail\" name=\"NewEmail\""
2016-12-10 18:32:35 +01:00
" size=\"18\" maxlength=\"%u\""
2016-11-19 02:04:39 +01:00
" placeholder=\"%s\" value=\"%s\""
" required=\"required\" />"
2014-12-12 22:39:55 +01:00
"</td>"
"</tr>",
2019-02-22 21:47:50 +01:00
The_ClassFormInBox[Gbl.Prefs.Theme],
2014-12-12 22:39:55 +01:00
Txt_Email,
2017-03-13 13:17:53 +01:00
Cns_MAX_CHARS_EMAIL_ADDRESS,
2015-03-27 20:52:14 +01:00
Txt_HELP_email,
2014-12-12 22:39:55 +01:00
NewEmail);
/***** Password *****/
2015-11-20 21:11:33 +01:00
Pwd_PutFormToGetNewPasswordOnce ();
2014-12-12 22:39:55 +01:00
2017-06-12 14:16:33 +02:00
/***** End table, send button and end box *****/
2017-06-11 19:02:40 +02:00
Box_EndBoxTableWithButton (Btn_CREATE_BUTTON,Txt_Create_account);
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;
2016-12-10 18:32:35 +01:00
extern const char *Txt_Create_account;
2016-03-21 19:52:40 +01:00
2017-06-12 14:16:33 +02:00
/***** Start box *****/
2018-10-17 01:08:42 +02:00
snprintf (Gbl.Title,sizeof (Gbl.Title),
Txt_New_on_PLATFORM_Sign_up,
Cfg_PLATFORM_SHORT_NAME);
2017-06-10 21:38:10 +02:00
Box_StartBox (NULL,Gbl.Title,NULL,
2017-06-12 15:03:29 +02:00
Hlp_PROFILE_SignUp,Box_NOT_CLOSABLE);
2016-03-21 19:52:40 +01:00
/***** Button to go to request the creation of a new account *****/
2018-11-09 20:47:39 +01:00
Frm_StartForm (ActFrmMyAcc);
2017-06-11 19:02:40 +02:00
Btn_PutCreateButton (Txt_Create_account);
2018-11-09 20:47:39 +01:00
Frm_EndForm ();
2016-03-21 19:52:40 +01:00
2017-06-12 14:16:33 +02:00
/***** End box *****/
2017-06-10 21:38:10 +02:00
Box_EndBox ();
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 *****/
2014-12-12 22:39:55 +01:00
Nck_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
2018-10-15 14:07:12 +02:00
/***** Start container for this user *****/
fprintf (Gbl.F.Out,"<div class=\"REC_USR\">");
2014-12-12 22:39:55 +01:00
2019-02-18 18:27:45 +01:00
/***** Show form to change my password and my nickname ****/
2018-10-15 14:07:12 +02:00
fprintf (Gbl.F.Out,"<div class=\"REC_LEFT\">");
2019-02-15 21:09:18 +01:00
Pwd_ShowFormChgMyPwd ();
2019-02-18 18:27:45 +01:00
Nck_ShowFormChangeMyNickname (IMustCreateMyNicknameNow);
2018-10-15 14:07:12 +02:00
fprintf (Gbl.F.Out,"</div>");
2014-12-12 22:39:55 +01:00
2019-02-18 18:27:45 +01:00
/***** Show form to change my email and my ID *****/
2018-10-15 14:07:12 +02:00
fprintf (Gbl.F.Out,"<div class=\"REC_RIGHT\">");
2019-02-15 21:09:18 +01:00
Mai_ShowFormChangeMyEmail (IMustFillInMyEmailNow,IShouldConfirmMyEmailNow);
ID_ShowFormChangeMyID (IShouldFillInMyIDNow);
2018-10-15 14:07:12 +02:00
fprintf (Gbl.F.Out,"</div>");
2014-12-12 22:39:55 +01:00
2018-10-15 14:07:12 +02:00
/***** Start container for this user *****/
fprintf (Gbl.F.Out,"</div>");
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_GetParamOtherUsrCodEncryptedAndGetUsrData ())
{
if (Usr_ICanEditOtherUsr (&Gbl.Usrs.Other.UsrDat))
{
/***** Get user's nickname and email address
It's necessary because nickname or email could be just updated *****/
Nck_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);
/***** Start container for this user *****/
fprintf (Gbl.F.Out,"<div class=\"REC_USR\">");
2019-02-18 18:27:45 +01:00
/***** Show form to change password and nickname *****/
2018-10-16 01:36:13 +02:00
fprintf (Gbl.F.Out,"<div class=\"REC_LEFT\">");
2019-02-18 18:27:45 +01:00
Pwd_ShowFormChgOtherUsrPwd ();
2018-10-16 01:36:13 +02:00
Nck_ShowFormChangeOtherUsrNickname ();
fprintf (Gbl.F.Out,"</div>");
2019-02-18 18:27:45 +01:00
/***** Show form to change email and ID *****/
2018-10-16 01:36:13 +02:00
fprintf (Gbl.F.Out,"<div class=\"REC_RIGHT\">");
2019-02-18 18:27:45 +01:00
Mai_ShowFormChangeOtherUsrEmail ();
2018-10-16 01:36:13 +02:00
ID_ShowFormChangeOtherUsrID ();
fprintf (Gbl.F.Out,"</div>");
/***** Start container for this user *****/
fprintf (Gbl.F.Out,"</div>");
}
else
2019-03-09 20:12:44 +01:00
Ale_ShowAlertUserNotFoundOrYouDoNotHavePermission ();
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
/*****************************************************************************/
2018-10-15 14:07:12 +02:00
void Acc_PutLinkToRemoveMyAccount (void)
2014-12-12 22:39:55 +01:00
{
extern const char *Txt_Remove_account;
2018-10-09 20:40:41 +02:00
if (Acc_CheckIfICanEliminateAccount (Gbl.Usrs.Me.UsrDat.UsrCod))
2019-01-12 03:00:59 +01:00
Lay_PutContextualLinkOnlyIcon (ActReqRemMyAcc,NULL,
Acc_PutParamsToRemoveMyAccount,
"trash.svg",
Txt_Remove_account);
2015-04-02 18:39:49 +02:00
}
2016-11-06 15:36:26 +01:00
static void Acc_PutParamsToRemoveMyAccount (void)
2015-04-02 18:39:49 +02:00
{
2017-03-01 18:53:51 +01:00
Usr_PutParamMyUsrCodEncrypted ();
Par_PutHiddenParamUnsigned ("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
{
2017-01-17 03:10:43 +01:00
char NewNicknameWithoutArroba[Nck_MAX_BYTES_NICKNAME_FROM_FORM + 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_GetParamsNewAccount (NewNicknameWithoutArroba,NewEmail,NewEncryptedPassword))
{
/***** 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,
2017-03-13 14:22:36 +01:00
Pwd_BYTES_ENCRYPTED_PASSWORD);
2014-12-12 22:39:55 +01:00
/***** User does not exist in the platform, so create him/her! *****/
2016-11-08 00:58:32 +01:00
Acc_CreateNewUsr (&Gbl.Usrs.Me.UsrDat,
true); // I am creating my own account
2014-12-12 22:39:55 +01:00
/***** Save nickname *****/
2018-10-16 01:36:13 +02:00
Nck_UpdateNickInDB (Gbl.Usrs.Me.UsrDat.UsrCod,NewNicknameWithoutArroba);
2017-01-15 18:02:52 +01:00
Str_Copy (Gbl.Usrs.Me.UsrDat.Nickname,NewNicknameWithoutArroba,
2017-03-07 01:56:41 +01:00
Nck_MAX_BYTES_NICKNAME_WITHOUT_ARROBA);
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,
2017-03-13 13:17:53 +01:00
Cns_MAX_BYTES_EMAIL_ADDRESS);
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_ShowFormRequestNewAccountWithParams (NewNicknameWithoutArroba,NewEmail);
return false;
}
}
/*****************************************************************************/
/************* Get parameters for the creation of a new account **************/
/*****************************************************************************/
// Return false on error
2017-01-17 03:10:43 +01:00
static bool Acc_GetParamsNewAccount (char NewNicknameWithoutArroba[Nck_MAX_BYTES_NICKNAME_FROM_FORM + 1],
2014-12-12 22:39:55 +01:00
char *NewEmail,
char *NewEncryptedPassword)
{
extern const char *Txt_The_nickname_X_had_been_registered_by_another_user;
extern const char *Txt_The_nickname_entered_X_is_not_valid_;
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;
2017-01-17 03:10:43 +01:00
char NewNicknameWithArroba[Nck_MAX_BYTES_NICKNAME_FROM_FORM + 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 *****/
2017-01-17 03:10:43 +01:00
Par_GetParToText ("NewNick",NewNicknameWithArroba,
Nck_MAX_BYTES_NICKNAME_FROM_FORM);
2016-03-21 19:52:40 +01:00
/* Remove arrobas at the beginning */
2017-01-15 18:02:52 +01:00
Str_Copy (NewNicknameWithoutArroba,NewNicknameWithArroba,
2017-01-17 03:10:43 +01:00
Nck_MAX_BYTES_NICKNAME_FROM_FORM);
2016-03-21 19:52:40 +01:00
Str_RemoveLeadingArrobas (NewNicknameWithoutArroba);
/* Create a new version of the nickname with arroba */
2018-10-17 01:08:42 +02:00
snprintf (NewNicknameWithArroba,sizeof (NewNicknameWithArroba),
"@%s",
NewNicknameWithoutArroba);
2014-12-12 22:39:55 +01:00
if (Nck_CheckIfNickWithArrobaIsValid (NewNicknameWithArroba)) // If new nickname is valid
{
2016-03-21 19:52:40 +01:00
/* Check if the new nickname
matches any of the nicknames of other users */
2018-11-03 13:13:11 +01:00
if (DB_QueryCOUNT ("can not check if nickname already existed",
"SELECT COUNT(*) FROM usr_nicknames"
" WHERE Nickname='%s' AND UsrCod<>%ld",
NewNicknameWithoutArroba,
Gbl.Usrs.Me.UsrDat.UsrCod)) // A nickname of another user is the same that this nickname
2014-12-12 22:39:55 +01:00
{
Error = true;
2019-02-16 14:37:34 +01:00
Ale_ShowAlert (Ale_WARNING,Txt_The_nickname_X_had_been_registered_by_another_user,
2019-02-15 23:38:44 +01:00
NewNicknameWithoutArroba);
2014-12-12 22:39:55 +01:00
}
}
else // New nickname is not valid
{
Error = true;
2019-02-16 14:37:34 +01:00
Ale_ShowAlert (Ale_WARNING,Txt_The_nickname_entered_X_is_not_valid_,
2019-02-15 23:38:44 +01:00
NewNicknameWithArroba,
Nck_MIN_CHARS_NICKNAME_WITHOUT_ARROBA,
Nck_MAX_CHARS_NICKNAME_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 *****/
2017-03-13 13:17:53 +01:00
Par_GetParToText ("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 */
2018-11-03 13:13:11 +01:00
if (DB_QueryCOUNT ("can not check if email already existed",
"SELECT COUNT(*) FROM usr_emails"
" WHERE E_mail='%s' AND Confirmed='Y'",
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 *****/
2017-03-07 01:56:41 +01:00
Par_GetParToText ("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
2016-11-08 00:58:32 +01:00
void Acc_CreateNewUsr (struct UsrData *UsrDat,bool CreatingMyOwnAccount)
2014-12-12 22:39:55 +01:00
{
extern const char *The_ThemeId[The_NUM_THEMES];
2015-03-06 14:11:11 +01:00
extern const char *Ico_IconSetId[Ico_NUM_ICON_SETS];
2015-03-06 22:36:29 +01:00
extern const char *Pri_VisibilityDB[Pri_NUM_OPTIONS_PRIVACY];
2018-12-08 16:43:13 +01:00
extern const char *Lan_STR_LANG_ID[1 + Lan_NUM_LANGUAGES];
2014-12-12 22:39:55 +01:00
extern const char *Usr_StringsSexDB[Usr_NUM_SEXS];
2017-01-15 22:58:26 +01:00
char BirthdayStrDB[Usr_BIRTHDAY_STR_DB_LENGTH + 1];
2018-10-04 21:57:25 +02:00
size_t CommentsLength;
2017-01-28 15:58:46 +01:00
char PathRelUsr[PATH_MAX + 1];
2014-12-12 22:39:55 +01:00
unsigned NumID;
/***** Check if user's code is initialized *****/
if (UsrDat->UsrCod > 0)
Lay_ShowErrorAndExit ("Can not create new user.");
/***** Create encrypted user's code *****/
Acc_CreateNewEncryptedUsrCod (UsrDat);
/***** Filter some user's data before inserting */
Enr_FilterUsrDat (UsrDat);
/***** Insert new user in database *****/
/* Insert user's data */
2018-10-08 12:37:29 +02:00
Usr_CreateBirthdayStrDB (UsrDat,BirthdayStrDB); // It can include start and ending apostrophes
if (UsrDat->Comments)
CommentsLength = strlen (UsrDat->Comments);
else
CommentsLength = 0;
2018-11-03 01:45:36 +01:00
UsrDat->UsrCod =
DB_QueryINSERTandReturnCode ("can not create user",
"INSERT INTO usr_data"
" (EncryptedUsrCod,Password,"
"Surname1,Surname2,FirstName,Sex,"
"Theme,IconSet,Language,FirstDayOfWeek,DateFormat,"
2019-03-22 15:21:46 +01:00
"PhotoVisibility,BaPrfVisibility,ExPrfVisibility,"
2018-11-03 01:45:36 +01:00
"CtyCod,"
"LocalAddress,LocalPhone,"
"FamilyAddress,FamilyPhone,"
"OriginPlace,Birthday,Comments,"
"Menu,SideCols,NotifNtfEvents,EmailNtfEvents)"
" VALUES"
" ('%s','%s',"
"'%s','%s','%s','%s',"
"'%s','%s','%s',%u,%u,"
2019-03-22 15:21:46 +01:00
"'%s','%s','%s',"
2018-11-03 01:45:36 +01:00
"%ld,"
"'%s','%s',"
"'%s','%s','%s',"
"%s,'%s',"
"%u,%u,-1,0)",
UsrDat->EncryptedUsrCod,
UsrDat->Password,
UsrDat->Surname1,UsrDat->Surname2,UsrDat->FirstName,
Usr_StringsSexDB[UsrDat->Sex],
The_ThemeId[UsrDat->Prefs.Theme],
Ico_IconSetId[UsrDat->Prefs.IconSet],
2018-12-08 16:43:13 +01:00
Lan_STR_LANG_ID[UsrDat->Prefs.Language],
2018-11-03 01:45:36 +01:00
Cal_FIRST_DAY_OF_WEEK_DEFAULT,
(unsigned) Dat_FORMAT_DEFAULT,
Pri_VisibilityDB[UsrDat->PhotoVisibility],
2019-03-22 15:21:46 +01:00
Pri_VisibilityDB[UsrDat->BaPrfVisibility],
Pri_VisibilityDB[UsrDat->ExPrfVisibility],
2018-11-03 01:45:36 +01:00
UsrDat->CtyCod,
UsrDat->LocalAddress ,UsrDat->LocalPhone,
UsrDat->FamilyAddress,UsrDat->FamilyPhone,UsrDat->OriginPlace,
BirthdayStrDB,
CommentsLength ? UsrDat->Comments :
"",
(unsigned) Mnu_MENU_DEFAULT,
(unsigned) Cfg_DEFAULT_COLUMNS);
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);
2018-11-02 19:37:11 +01:00
DB_QueryINSERT ("can not store user's ID when creating user",
"INSERT INTO usr_IDs"
" (UsrCod,UsrID,CreatTime,Confirmed)"
" VALUES"
" (%ld,'%s',NOW(),'%c')",
UsrDat->UsrCod,
UsrDat->IDs.List[NumID].ID,
UsrDat->IDs.List[NumID].Confirmed ? 'Y' :
'N');
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 *****/
2016-11-08 00:58:32 +01:00
Prf_CreateNewUsrFigures (UsrDat->UsrCod,CreatingMyOwnAccount);
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 UsrData *UsrDat)
{
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->EncryptedUsrCod);
if (!Usr_ChkIfEncryptedUsrCodExists (UsrDat->EncryptedUsrCod))
break;
}
if (NumTry == MAX_TRY)
Lay_ShowErrorAndExit ("Can not create a new encrypted user's code.");
}
/*****************************************************************************/
/***************** 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_GetParamOtherUsrCodEncryptedAndGetUsrData ())
2016-12-18 19:06:48 +01:00
{
if (Acc_CheckIfICanEliminateAccount (Gbl.Usrs.Other.UsrDat.UsrCod))
Acc_ReqRemAccountOrRemAccount (Acc_REMOVE_USR);
else
Error = true;
}
2016-06-17 23:38:32 +02:00
else
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
{
2018-10-10 23:56:42 +02:00
bool ItsMe = 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
2018-10-09 22:15:12 +02:00
Acc_AskIfRemoveUsrAccount (ItsMe);
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_MoveUnusedMsgsContentToDeleted ();
}
2018-10-09 22:15:12 +02:00
else
Acc_AskIfRemoveUsrAccount (ItsMe);
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 *********/
/*****************************************************************************/
2016-06-17 23:38:32 +02:00
bool Acc_CheckIfICanEliminateAccount (long UsrCod)
2014-12-12 22:39:55 +01:00
{
2018-10-10 23:56:42 +02:00
bool ItsMe = 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
2016-06-17 23:38:32 +02:00
return (( ItsMe && // It's me
2017-06-04 18:18:54 +02:00
(Gbl.Usrs.Me.Role.Available & (1 << Rol_SYS_ADM)) == 0) // I can not be system admin
2014-12-12 22:39:55 +01:00
||
2016-06-17 23:38:32 +02:00
(!ItsMe && // It's not me
2018-10-10 23:56:42 +02:00
Gbl.Usrs.Me.Role.Logged == Rol_SYS_ADM)); // I am logged as system admin
2014-12-12 22:39:55 +01:00
}
/*****************************************************************************/
/*********** Ask if really wanted to eliminate completely a user *************/
/*****************************************************************************/
2015-09-16 00:15:20 +02:00
static void Acc_AskIfRemoveUsrAccount (bool ItsMe)
{
if (ItsMe)
Acc_AskIfRemoveMyAccount ();
else
Acc_AskIfRemoveOtherUsrAccount ();
}
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 *****/
/* Start alert */
2017-05-11 23:45:46 +02:00
Ale_ShowAlertAndButton1 (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 */
2018-11-09 20:47:39 +01:00
Frm_StartForm (ActRemMyAcc);
2015-09-16 00:15:20 +02:00
Pwd_AskForConfirmationOnDangerousAction ();
2017-06-11 19:02:40 +02:00
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 */
2017-06-11 19:02:40 +02:00
Ale_ShowAlertAndButton2 (ActUnk,NULL,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_ChkIfUsrCodExists (Gbl.Usrs.Other.UsrDat.UsrCod))
{
2017-04-28 00:13:28 +02:00
/***** Show question and button to remove user account *****/
2017-04-27 23:54:29 +02:00
/* Start alert */
2017-05-11 23:45:46 +02:00
Ale_ShowAlertAndButton1 (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 */
2018-11-09 20:47:39 +01:00
Frm_StartForm (ActRemUsrGbl);
2015-04-02 18:39:49 +02:00
Usr_PutParamOtherUsrCodEncrypted ();
2014-12-12 22:39:55 +01:00
Pwd_AskForConfirmationOnDangerousAction ();
2017-06-11 19:02:40 +02:00
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 */
2017-06-11 19:02:40 +02:00
Ale_ShowAlertAndButton2 (ActUnk,NULL,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_MoveUnusedMsgsContentToDeleted ();
}
2018-10-09 22:15:12 +02:00
else
Acc_AskIfRemoveUsrAccount (true);
2015-09-16 00:15:20 +02:00
}
2014-12-12 22:39:55 +01:00
void Acc_CompletelyEliminateAccount (struct UsrData *UsrDat,
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 *****/
2017-06-04 15:11:41 +02:00
Rec_RemoveFieldsCrsRecordAll (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);
2014-12-12 22:39:55 +01:00
/***** Remove user from all the attendance events *****/
Att_RemoveUsrFromAllAttEvents (UsrDat->UsrCod);
/***** Remove user from all the 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 inscription *****/
2018-11-02 22:00:31 +01:00
DB_QueryDELETE ("can not remove user's requests for inscription",
"DELETE FROM crs_usr_requests WHERE UsrCod=%ld",
UsrDat->UsrCod);
2014-12-12 22:39:55 +01:00
2016-06-15 14:52:43 +02:00
/***** Remove user from possible duplicate users *****/
2016-06-16 14:34:17 +02:00
Dup_RemoveUsrFromDuplicated (UsrDat->UsrCod);
2016-06-15 14:52:43 +02:00
2014-12-12 22:39:55 +01:00
/***** Remove user from the table of courses and users *****/
2018-11-02 22:00:31 +01:00
DB_QueryDELETE ("can not remove a user from all courses",
"DELETE FROM crs_usr WHERE UsrCod=%ld",
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 *****/
2018-11-02 22:00:31 +01:00
DB_QueryDELETE ("can not remove a user as administrator",
"DELETE FROM admin WHERE UsrCod=%ld",
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 *****/
2014-12-12 22:39:55 +01:00
For_RemoveUsrFromThrClipboard (UsrDat->UsrCod);
2015-01-25 18:50:43 +01:00
/***** Remove some files of the user's from database *****/
Brw_RemoveUsrFilesFromDB (UsrDat->UsrCod);
/***** 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
2016-11-21 13:15:08 +01:00
/***** Remove test results made by user in all courses *****/
Tst_RemoveTestResultsMadeByUsrInAllCrss (UsrDat->UsrCod);
2014-12-12 22:39:55 +01:00
/***** Remove user's notifications *****/
Ntf_RemoveUsrNtfs (UsrDat->UsrCod);
/***** Delete user's messages sent and received *****/
Gbl.Msg.FilterContent[0] = '\0';
Msg_DelAllRecAndSntMsgsUsr (UsrDat->UsrCod);
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 *****/
Usr_RemoveUsrFromUsrBanned (UsrDat->UsrCod);
2014-12-12 22:39:55 +01:00
Msg_RemoveUsrFromBanned (UsrDat->UsrCod);
/***** Delete thread read status for this user *****/
For_RemoveUsrFromReadThrs (UsrDat->UsrCod);
/***** Remove user from table of seen announcements *****/
Ann_RemoveUsrFromSeenAnnouncements (UsrDat->UsrCod);
/***** Remove user from table of connected users *****/
2018-11-02 22:00:31 +01:00
DB_QueryDELETE ("can not remove a user from table of connected users",
"DELETE FROM connected WHERE UsrCod=%ld",
UsrDat->UsrCod);
2014-12-12 22:39:55 +01:00
/***** Remove all sessions of this user *****/
2018-11-02 22:00:31 +01:00
DB_QueryDELETE ("can not remove sessions of a user",
"DELETE FROM sessions WHERE UsrCod=%ld",
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 *****/
2019-03-12 21:25:55 +01:00
TL_RemoveUsrContent (UsrDat->UsrCod);
2016-01-08 10:13:28 +01:00
2015-03-11 12:48:41 +01:00
/***** Remove user's figures *****/
2015-03-14 17:39:04 +01:00
Prf_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_RemoveUsrEvents (UsrDat->UsrCod);
2014-12-12 22:39:55 +01:00
/***** Remove the user from the list of users without photo *****/
Pho_RemoveUsrFromTableClicksWithoutPhoto (UsrDat->UsrCod);
/***** 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 *****/
Acc_RemoveUsr (UsrDat);
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 UsrData *UsrDat)
{
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
}
/*****************************************************************************/
/************************ Remove a user from database ************************/
/*****************************************************************************/
static void Acc_RemoveUsr (struct UsrData *UsrDat)
{
/***** Remove user's webs / social networks *****/
2018-11-02 22:00:31 +01:00
DB_QueryDELETE ("can not remove user's webs / social networks",
"DELETE FROM usr_webs WHERE UsrCod=%ld",
UsrDat->UsrCod);
2014-12-12 22:39:55 +01:00
/***** Remove user's nicknames *****/
2018-11-02 22:00:31 +01:00
DB_QueryDELETE ("can not remove user's nicknames",
"DELETE FROM usr_nicknames WHERE UsrCod=%ld",
UsrDat->UsrCod);
2014-12-12 22:39:55 +01:00
2016-11-16 23:19:52 +01:00
/***** Remove user's emails *****/
2018-11-02 22:00:31 +01:00
DB_QueryDELETE ("can not remove pending user's emails",
"DELETE FROM pending_emails WHERE UsrCod=%ld",
UsrDat->UsrCod);
2014-12-12 22:39:55 +01:00
2018-11-02 22:00:31 +01:00
DB_QueryDELETE ("can not remove user's emails",
"DELETE FROM usr_emails WHERE UsrCod=%ld",
UsrDat->UsrCod);
2014-12-12 22:39:55 +01:00
/***** Remove user's IDs *****/
2018-11-02 22:00:31 +01:00
DB_QueryDELETE ("can not remove user's IDs",
"DELETE FROM usr_IDs WHERE UsrCod=%ld",
UsrDat->UsrCod);
2014-12-12 22:39:55 +01:00
/***** Remove user's last data *****/
2018-11-02 22:00:31 +01:00
DB_QueryDELETE ("can not remove user's last data",
"DELETE FROM usr_last WHERE UsrCod=%ld",
UsrDat->UsrCod);
2014-12-12 22:39:55 +01:00
/***** Remove user's data *****/
2018-11-02 22:00:31 +01:00
DB_QueryDELETE ("can not remove user's data",
"DELETE FROM usr_data WHERE UsrCod=%ld",
UsrDat->UsrCod);
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 (void)
{
extern const char *Txt_Change_account;
Act_Action_t NextAction;
bool ItsMe = Usr_ItsMe (Gbl.Record.UsrDat->UsrCod);
/***** Link for changing the account *****/
if (ItsMe)
2019-01-12 03:00:59 +01:00
Lay_PutContextualLinkOnlyIcon (ActFrmMyAcc,NULL,NULL,
"at.svg",
Txt_Change_account);
2018-10-16 01:36:13 +02:00
else // Not me
if (Usr_ICanEditOtherUsr (Gbl.Record.UsrDat))
{
switch (Gbl.Record.UsrDat->Roles.InCurrentCrs.Role)
{
case Rol_STD:
NextAction = ActFrmAccStd;
break;
case Rol_NET:
case Rol_TCH:
NextAction = ActFrmAccTch;
break;
default: // Guest, user or admin
NextAction = ActFrmAccOth;
break;
}
2019-01-12 03:00:59 +01:00
Lay_PutContextualLinkOnlyIcon (NextAction,NULL,
Rec_PutParamUsrCodEncrypted,
"at.svg",
Txt_Change_account);
2018-10-16 01:36:13 +02:00
}
}