diff --git a/Makefile b/Makefile index fbdd6ad3c..224072510 100644 --- a/Makefile +++ b/Makefile @@ -26,7 +26,7 @@ # # ############################################################################### -OBJS = swad_action.o swad_announcement.o swad_assignment.o swad_attendance.o \ +OBJS = swad_account.o swad_action.o swad_announcement.o swad_assignment.o swad_attendance.o \ swad_banner.o \ swad_centre.o swad_chat.o swad_config.o swad_connected.o swad_country.o swad_course.o swad_cryptography.o \ swad_database.o swad_date.o swad_degree.o swad_department.o \ diff --git a/swad_ID.c b/swad_ID.c index 4454e7201..3b68eb061 100644 --- a/swad_ID.c +++ b/swad_ID.c @@ -29,9 +29,9 @@ #include // For exit, system, malloc, free, rand, etc. #include // For string functions +#include "swad_account.h" #include "swad_bool.h" #include "swad_database.h" -#include "swad_enrollment.h" #include "swad_global.h" #include "swad_ID.h" #include "swad_parameter.h" @@ -558,7 +558,7 @@ void ID_RemoveMyUsrID (void) ID_GetListIDsFromUsrCod (&Gbl.Usrs.Me.UsrDat); /***** Show my account again *****/ - Enr_ShowFormChangeMyAccount (); + Acc_ShowFormChangeMyAccount (); } /*****************************************************************************/ @@ -673,7 +673,7 @@ void ID_NewMyUsrID (void) ID_GetListIDsFromUsrCod (&Gbl.Usrs.Me.UsrDat); /***** Show my account again *****/ - Enr_ShowFormChangeMyAccount (); + Acc_ShowFormChangeMyAccount (); } /*****************************************************************************/ diff --git a/swad_account.c b/swad_account.c new file mode 100644 index 000000000..d69345876 --- /dev/null +++ b/swad_account.c @@ -0,0 +1,823 @@ +// 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-2014 Antonio Caņas Vargas + + 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 . +*/ +/*****************************************************************************/ +/*********************************** Headers *********************************/ +/*****************************************************************************/ + +#include // For string functions + +#include "swad_account.h" +#include "swad_announcement.h" +#include "swad_database.h" +#include "swad_enrollment.h" +#include "swad_global.h" +#include "swad_ID.h" +#include "swad_notification.h" +#include "swad_parameter.h" + +/*****************************************************************************/ +/****************************** Public constants *****************************/ +/*****************************************************************************/ + +/*****************************************************************************/ +/***************************** Private constants *****************************/ +/*****************************************************************************/ + +/*****************************************************************************/ +/****************************** Internal types *******************************/ +/*****************************************************************************/ + +typedef enum + { + Acc_REQUEST_REMOVE_USR, + Acc_REMOVE_USR, + } Acc_ReqDelOrDelUsr_t; + +/*****************************************************************************/ +/************** External global variables from others modules ****************/ +/*****************************************************************************/ + +extern struct Globals Gbl; + +/*****************************************************************************/ +/************************* Internal global variables *************************/ +/*****************************************************************************/ + +/*****************************************************************************/ +/***************************** Private prototypes ****************************/ +/*****************************************************************************/ + +static void Acc_ShowFormRequestNewAccountWithParams (const char *NewNicknameWithoutArroba, + const char *NewEmail); +static bool Acc_GetParamsNewAccount (char *NewNicknameWithoutArroba, + char *NewEmail, + char *NewEncryptedPassword); +static void Acc_CreateNewEncryptedUsrCod (struct UsrData *UsrDat); + +static void Acc_PutLinkToRemoveMyAccount (void); +static void Acc_PrintAccountSeparator (void); + +static void Acc_ReqDelOrDelUsrGbl (Acc_ReqDelOrDelUsr_t ReqDelOrDelUsr); + +static void Acc_RemoveUsrBriefcase (struct UsrData *UsrDat); +static void Acc_RemoveUsr (struct UsrData *UsrDat); + +/*****************************************************************************/ +/******** Show form to change my account or to create a new account **********/ +/*****************************************************************************/ + +void Acc_ShowFormAccount (void) + { + if (Gbl.Usrs.Me.Logged) + Acc_ShowFormChangeMyAccount (); + else + Acc_ShowFormRequestNewAccountWithParams ("",""); + } + +/*****************************************************************************/ +/********************* Show form to create a new account *********************/ +/*****************************************************************************/ + +static void Acc_ShowFormRequestNewAccountWithParams (const char *NewNicknameWithoutArroba, + const char *NewEmail) + { + extern const char *The_ClassFormul[The_NUM_THEMES]; + extern const char *Txt_Log_in; + extern const char *Txt_Nickname; + extern const char *Txt_Email; + extern const char *Txt_New_on_PLATFORM_Sign_up; + extern const char *Txt_Create_account; + + /***** Link to log in *****/ + fprintf (Gbl.F.Out,"
"); + Act_FormStart (ActFrmLogIn); + Act_LinkFormSubmit (Txt_Log_in,The_ClassFormul[Gbl.Prefs.Theme]); + Lay_PutSendIcon ("login",Txt_Log_in,Txt_Log_in); + fprintf (Gbl.F.Out,"" + "
"); + + /***** Form to enter the ID of the new user *****/ + fprintf (Gbl.F.Out,"
"); + Act_FormStart (ActCreUsrAcc); + sprintf (Gbl.Title,Txt_New_on_PLATFORM_Sign_up,Cfg_PLATFORM_SHORT_NAME); + Lay_StartRoundFrameTable10 (NULL,2,Gbl.Title); + + /***** Nickname *****/ + fprintf (Gbl.F.Out,"" + "" + "%s: " + "" + "" + "" + "" + "", + The_ClassFormul[Gbl.Prefs.Theme], + Txt_Nickname, + 1+Nck_MAX_LENGTH_NICKNAME_WITHOUT_ARROBA, + NewNicknameWithoutArroba); + + /***** E-mail *****/ + fprintf (Gbl.F.Out,"" + "" + "%s: " + "" + "" + "" + "" + "", + The_ClassFormul[Gbl.Prefs.Theme], + Txt_Email, + Cns_MAX_BYTES_STRING, + NewEmail); + + /***** Password *****/ + Pwd_PutFormToGetNewPasswordTwice (); + + /***** Send button and form end *****/ + fprintf (Gbl.F.Out,"" + "" + "" + "" + "", + Txt_Create_account); + Lay_EndRoundFrameTable10 (); + fprintf (Gbl.F.Out,"" + "
"); + } + +/*****************************************************************************/ +/*********************** Show form to change my account **********************/ +/*****************************************************************************/ + +void Acc_ShowFormChangeMyAccount (void) + { + extern const char *Txt_Before_going_to_any_other_option_you_must_fill_your_nickname; + extern const char *Txt_Before_going_to_any_other_option_you_must_fill_your_email_address; + extern const char *Txt_Before_going_to_any_other_option_you_must_fill_your_ID; + extern const char *Txt_User_account; + + /***** Get current user's nickname and e-mail address + It's necessary because current nickname or e-mail could be just updated *****/ + Nck_GetNicknameFromUsrCod (Gbl.Usrs.Me.UsrDat.UsrCod,Gbl.Usrs.Me.UsrDat.Nickname); + Mai_GetEmailFromUsrCod (Gbl.Usrs.Me.UsrDat.UsrCod,Gbl.Usrs.Me.UsrDat.Email,&(Gbl.Usrs.Me.UsrDat.EmailConfirmed)); + + /***** Check nickname and e-mail *****/ + if (!Gbl.Usrs.Me.UsrDat.Nickname[0]) + Lay_ShowAlert (Lay_WARNING,Txt_Before_going_to_any_other_option_you_must_fill_your_nickname); + else if (!Gbl.Usrs.Me.UsrDat.Email[0]) + Lay_ShowAlert (Lay_WARNING,Txt_Before_going_to_any_other_option_you_must_fill_your_email_address); + else if (!Gbl.Usrs.Me.UsrDat.IDs.Num) + Lay_ShowAlert (Lay_WARNING,Txt_Before_going_to_any_other_option_you_must_fill_your_ID); + + /***** Put links to change my password and to remove my account*****/ + fprintf (Gbl.F.Out,"
"); + Pwd_PutLinkToChangeUsrPassword (&Gbl.Usrs.Me.UsrDat); + if (Acc_CheckIfICanEliminateAccount (true)) // ItsMe = true + Acc_PutLinkToRemoveMyAccount (); + fprintf (Gbl.F.Out,"
"); + + /***** Start table *****/ + Lay_StartRoundFrameTable10 ("80%",2,Txt_User_account); + + /***** Nickname *****/ + Nck_ShowFormChangeUsrNickname (); + + /***** Separator *****/ + Acc_PrintAccountSeparator (); + + /***** E-mail *****/ + Mai_ShowFormChangeUsrEmail (); + + /***** Separator *****/ + Acc_PrintAccountSeparator (); + + /***** User's ID *****/ + ID_ShowFormChangeUsrID (&Gbl.Usrs.Me.UsrDat,true); + + /***** End of table *****/ + Lay_EndRoundFrameTable10 (); + } + + +/*****************************************************************************/ +/******** Put a link to the action used to request user's password ***********/ +/*****************************************************************************/ + +static void Acc_PutLinkToRemoveMyAccount (void) + { + extern const char *The_ClassFormul[The_NUM_THEMES]; + extern const char *Txt_Remove_account; + + Act_FormStart (ActUpdOthUsrDat); + Usr_PutParamOtherUsrCodEncrypted (Gbl.Usrs.Me.UsrDat.EncryptedUsrCod); + Par_PutHiddenParamUnsigned ("RegRemAction",(unsigned) Enr_ELIMINATE_ONE_USR_FROM_PLATFORM); + Act_LinkFormSubmit (Txt_Remove_account,The_ClassFormul[Gbl.Prefs.Theme]); + Lay_PutSendIcon ("delon",Txt_Remove_account,Txt_Remove_account); + fprintf (Gbl.F.Out,""); + } + +/*****************************************************************************/ +/******* Draw a separator between different parts of new account form ********/ +/*****************************************************************************/ + +static void Acc_PrintAccountSeparator (void) + { + extern const char *The_ClassSeparator[The_NUM_THEMES]; + + /***** Separator *****/ + fprintf (Gbl.F.Out,"" + "" + "
" + "" + "", + The_ClassSeparator[Gbl.Prefs.Theme]); + } + +/*****************************************************************************/ +/*************** Create new user account with an ID and login ****************/ +/*****************************************************************************/ +// Return true if no error and user can be logged in +// Return false on error + +bool Acc_CreateNewAccountAndLogIn (void) + { + char NewNicknameWithoutArroba[Nck_MAX_BYTES_NICKNAME_WITH_ARROBA+1]; + char NewEmail[Cns_MAX_BYTES_STRING+1]; + char NewEncryptedPassword[Cry_LENGTH_ENCRYPTED_STR_SHA512_BASE64+1]; + + 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 *****/ + strcpy (Gbl.Usrs.Me.UsrDat.Password,NewEncryptedPassword); + + /***** User does not exist in the platform, so create him/her! *****/ + Acc_CreateNewUsr (&Gbl.Usrs.Me.UsrDat); + + /***** Save nickname *****/ + Nck_UpdateMyNick (NewNicknameWithoutArroba); + strcpy (Gbl.Usrs.Me.UsrDat.Nickname,NewNicknameWithoutArroba); + + /***** Save e-mail *****/ + if (Mai_UpdateEmailInDB (&Gbl.Usrs.Me.UsrDat,NewEmail)) + { + /* E-mail updated sucessfully */ + strcpy (Gbl.Usrs.Me.UsrDat.Email,NewEmail); + 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 + +static bool Acc_GetParamsNewAccount (char *NewNicknameWithoutArroba, + 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; + extern const char *Txt_You_have_not_written_twice_the_same_new_password; + char Query[1024]; + char NewNicknameWithArroba[Nck_MAX_BYTES_NICKNAME_WITH_ARROBA+1]; + char NewPlainPassword[2][Pwd_MAX_LENGTH_PLAIN_PASSWORD+1]; + bool Error = false; + + /***** Step 1/3: Get new nickname from form *****/ + Par_GetParToText ("NewNick",NewNicknameWithArroba,Nck_MAX_BYTES_NICKNAME_WITH_ARROBA); + + if (Nck_CheckIfNickWithArrobaIsValid (NewNicknameWithArroba)) // If new nickname is valid + { + /***** Remove arrobas at the beginning *****/ + strncpy (NewNicknameWithoutArroba,NewNicknameWithArroba,Nck_MAX_BYTES_NICKNAME_WITH_ARROBA); + NewNicknameWithoutArroba[Nck_MAX_BYTES_NICKNAME_WITH_ARROBA] = '\0'; + Str_RemoveLeadingArrobas (NewNicknameWithoutArroba); + + /***** Check if the new nickname matches any of the nicknames of other users *****/ + sprintf (Query,"SELECT COUNT(*) FROM usr_nicknames" + " WHERE Nickname='%s' AND UsrCod<>'%ld'", + NewNicknameWithoutArroba,Gbl.Usrs.Me.UsrDat.UsrCod); + if (DB_QueryCOUNT (Query,"can not check if nickname already existed")) // A nickname of another user is the same that this nickname + { + Error = true; + sprintf (Gbl.Message,Txt_The_nickname_X_had_been_registered_by_another_user, + NewNicknameWithoutArroba); + Lay_ShowAlert (Lay_WARNING,Gbl.Message); + } + } + else // New nickname is not valid + { + Error = true; + sprintf (Gbl.Message,Txt_The_nickname_entered_X_is_not_valid_, + NewNicknameWithArroba, + Nck_MIN_LENGTH_NICKNAME_WITHOUT_ARROBA, + Nck_MAX_LENGTH_NICKNAME_WITHOUT_ARROBA); + Lay_ShowAlert (Lay_WARNING,Gbl.Message); + } + + /***** Step 2/3: Get new e-mail from form *****/ + Par_GetParToText ("NewEmail",NewEmail,Cns_MAX_BYTES_STRING); + + if (Mai_CheckIfEmailIsValid (NewEmail)) // New e-mail is valid + { + /***** Check if the new e-mail matches any of the confirmed e-mails of other users *****/ + sprintf (Query,"SELECT COUNT(*) FROM usr_emails" + " WHERE E_mail='%s' AND Confirmed='Y'", + NewEmail); + if (DB_QueryCOUNT (Query,"can not check if e-mail already existed")) // An e-mail of another user is the same that my e-mail + { + Error = true; + sprintf (Gbl.Message,Txt_The_email_address_X_had_been_registered_by_another_user, + NewEmail); + Lay_ShowAlert (Lay_WARNING,Gbl.Message); + } + } + else // New e-mail is not valid + { + Error = true; + sprintf (Gbl.Message,Txt_The_email_address_entered_X_is_not_valid, + NewEmail); + Lay_ShowAlert (Lay_WARNING,Gbl.Message); + } + + /***** Step 3/3: Get new user's ID from form *****/ + Par_GetParToText ("Paswd1",NewPlainPassword[0],Pwd_MAX_LENGTH_PLAIN_PASSWORD); + Par_GetParToText ("Paswd2",NewPlainPassword[1],Pwd_MAX_LENGTH_PLAIN_PASSWORD); + if (strcmp (NewPlainPassword[0],NewPlainPassword[1])) + { + // Passwords don't match + Error = true; + Lay_ShowAlert (Lay_WARNING,Txt_You_have_not_written_twice_the_same_new_password); + } + else + { + Str_ChangeFormat (Str_FROM_FORM,Str_TO_TEXT, + NewPlainPassword[0],Pwd_MAX_LENGTH_PLAIN_PASSWORD,true); + Cry_EncryptSHA512Base64 (NewPlainPassword[0],NewEncryptedPassword); + if (!Pwd_SlowCheckIfPasswordIsGood (NewPlainPassword[0],NewEncryptedPassword,-1L)) // New password is good? + { + Error = true; + Lay_ShowAlert (Lay_WARNING,Gbl.Message); // Error message is set in Usr_SlowCheckIfPasswordIsGood + } + } + + 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 UsrData *UsrDat) + { + extern const char *Ico_IconSetId[Ico_NUM_ICON_SETS]; + extern const char *The_ThemeId[The_NUM_THEMES]; + extern const char *Txt_STR_LANG_ID[Txt_NUM_LANGUAGES]; + extern const char *Usr_StringsSexDB[Usr_NUM_SEXS]; + char Query[2048]; + char PathRelUsr[PATH_MAX+1]; + 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 */ + sprintf (Query,"INSERT INTO usr_data (EncryptedUsrCod,Password,Surname1,Surname2,FirstName,Sex," + "Layout,Theme,IconSet,Language,PublicPhoto," + "CtyCod," + "LocalAddress,LocalPhone,FamilyAddress,FamilyPhone,OriginPlace,Birthday,Comments," + "SideCols,NotifNtfEvents,EmailNtfEvents)" + " VALUES ('%s','%s','%s','%s','%s','%s'," + "'%u','%s','%s','%s','%c'," + "'%ld'," + "'%s','%s','%s','%s','%s','%04u-%02u-%02u','%s'," + "'3','-1','0')", + UsrDat->EncryptedUsrCod, + UsrDat->Password, + UsrDat->Surname1,UsrDat->Surname2,UsrDat->FirstName, + Usr_StringsSexDB[UsrDat->Sex], + (unsigned) UsrDat->Prefs.Layout, + The_ThemeId[UsrDat->Prefs.Theme], + Ico_IconSetId[UsrDat->Prefs.IconSet], + Txt_STR_LANG_ID[UsrDat->Prefs.Language], + UsrDat->PublicPhoto ? 'Y' : + 'N', + UsrDat->CtyCod, + UsrDat->LocalAddress ,UsrDat->LocalPhone, + UsrDat->FamilyAddress,UsrDat->FamilyPhone, + UsrDat->OriginPlace, + UsrDat->Birthday.Year,UsrDat->Birthday.Month,UsrDat->Birthday.Day, + UsrDat->Comments ? UsrDat->Comments : + ""); + UsrDat->UsrCod = DB_QueryINSERTandReturnCode (Query,"can not create user"); + + /* Insert user's IDs as confirmed */ + for (NumID = 0; + NumID < UsrDat->IDs.Num; + NumID++) + { + Str_ConvertToUpperText (UsrDat->IDs.List[NumID].ID); + sprintf (Query,"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'); + DB_QueryINSERT (Query,"can not store user's ID when creating user"); + } + + /***** Create directory for the user, if not exists *****/ + Usr_ConstructPathUsr (UsrDat->UsrCod,PathRelUsr); + Fil_CreateDirIfNotExists (PathRelUsr); + } + +/*****************************************************************************/ +/******************** Create a new encrypted user's code *********************/ +/*****************************************************************************/ + +#define LENGTH_RANDOM_STR 32 +#define MAX_TRY 10 + +static void Acc_CreateNewEncryptedUsrCod (struct UsrData *UsrDat) + { + char RandomStr[LENGTH_RANDOM_STR+1]; + 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) + { + extern const char *Txt_New_account_created; + + if (Gbl.Usrs.Me.Logged) // If account has been created without problem, I am logged + { + /***** Show message of success *****/ + Lay_ShowAlert (Lay_SUCCESS,Txt_New_account_created); + + /***** Show form with account data *****/ + Acc_ShowFormChangeMyAccount (); + } + } + +/*****************************************************************************/ +/********* Request definite removing of a user from the platform *************/ +/*****************************************************************************/ + +void Acc_ReqRemUsrGbl (void) + { + Acc_ReqDelOrDelUsrGbl (Acc_REQUEST_REMOVE_USR); + } + +/*****************************************************************************/ +/************** Definite removing of a user from the platform ****************/ +/*****************************************************************************/ + +void Acc_RemUsrGbl (void) + { + Acc_ReqDelOrDelUsrGbl (Acc_REMOVE_USR); + } + +/*****************************************************************************/ +/**************************** Removing of a user *****************************/ +/*****************************************************************************/ + +static void Acc_ReqDelOrDelUsrGbl (Acc_ReqDelOrDelUsr_t ReqDelOrDelUsr) + { + extern const char *Txt_User_not_found_or_you_do_not_have_permission_; + bool ItsMe; + + /***** Get user to be removed *****/ + if (Usr_GetParamOtherUsrCodEncryptedAndGetUsrData ()) + { + ItsMe = (Gbl.Usrs.Me.UsrDat.UsrCod == Gbl.Usrs.Other.UsrDat.UsrCod); + if (Acc_CheckIfICanEliminateAccount (ItsMe)) + switch (ReqDelOrDelUsr) + { + case Acc_REQUEST_REMOVE_USR: // Ask if eliminate completely the user from the platform + Acc_AskIfCompletelyEliminateAccount (ItsMe); + break; + case Acc_REMOVE_USR: // Eliminate completely the user from the platform + if (Pwd_GetConfirmationOnDangerousAction ()) + { + Acc_CompletelyEliminateAccount (&Gbl.Usrs.Other.UsrDat,Cns_VERBOSE); + + /***** Move unused contents of messages to table of deleted contents of messages *****/ + Msg_MoveUnusedMsgsContentToDeleted (); + } + break; + } + else + Lay_ShowAlert (Lay_WARNING,Txt_User_not_found_or_you_do_not_have_permission_); + } + else + Lay_ShowAlert (Lay_WARNING,Txt_User_not_found_or_you_do_not_have_permission_); + } + +/*****************************************************************************/ +/******** Check if I can eliminate completely another user's account *********/ +/*****************************************************************************/ + +bool Acc_CheckIfICanEliminateAccount (bool ItsMe) + { + // A user logged as superuser can eliminate any user except her/him + // Other users only can eliminate themselves + return (( ItsMe && // It's me + (Gbl.Usrs.Me.AvailableRoles & (1 << Rol_ROLE_SUPERUSER)) == 0) // I can not be superuser + || + (!ItsMe && // It's not me + Gbl.Usrs.Me.LoggedRole == Rol_ROLE_SUPERUSER)); // I am logged as superuser + } + +/*****************************************************************************/ +/*********** Ask if really wanted to eliminate completely a user *************/ +/*****************************************************************************/ + +void Acc_AskIfCompletelyEliminateAccount (bool ItsMe) + { + extern const char *Txt_Do_you_really_want_to_completely_eliminate_your_user_account; + extern const char *Txt_Do_you_really_want_to_completely_eliminate_the_following_user; + extern const char *Txt_Completely_eliminate_me; + extern const char *Txt_Completely_eliminate_user; + extern const char *Txt_User_not_found_or_you_do_not_have_permission_; + + if (Usr_ChkIfUsrCodExists (Gbl.Usrs.Other.UsrDat.UsrCod)) + { + Lay_ShowAlert (Lay_WARNING,ItsMe ? Txt_Do_you_really_want_to_completely_eliminate_your_user_account : + Txt_Do_you_really_want_to_completely_eliminate_the_following_user); + + Rec_ShowCommonRecordUnmodifiable (&Gbl.Usrs.Other.UsrDat); + + Act_FormStart (ActRemUsrGbl); + Usr_PutParamOtherUsrCodEncrypted (Gbl.Usrs.Other.UsrDat.EncryptedUsrCod); + + /* Ask for consent on dangerous actions */ + Pwd_AskForConfirmationOnDangerousAction (); + + fprintf (Gbl.F.Out,"
" + "" + "
" + "", + ItsMe ? Txt_Completely_eliminate_me : + Txt_Completely_eliminate_user); + } + else + Lay_ShowAlert (Lay_WARNING,Txt_User_not_found_or_you_do_not_have_permission_); + } + +/*****************************************************************************/ +/************* Remove completely a user from the whole platform **************/ +/*****************************************************************************/ + +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; + extern const char *Txt_Virtual_pendrive_of_THE_USER_X_has_been_removed; + 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; + char Query[1024]; + bool PhotoRemoved = false; + + /***** Remove the works zones of the user in all courses *****/ + Brw_RemoveUsrWorksInAllCrss (UsrDat,QuietOrVerbose); // Make this before of removing the user from the courses + + /***** Remove the fields of course record in all courses *****/ + Rec_RemoveFieldsCrsRecordAll (UsrDat->UsrCod,QuietOrVerbose); + + /***** Remove user from all the attendance events *****/ + Att_RemoveUsrFromAllAttEvents (UsrDat->UsrCod); + + /***** Remove user from all the groups of all courses *****/ + Grp_RemUsrFromAllGrps (UsrDat,QuietOrVerbose); + + /***** Remove user's requests for inscription *****/ + sprintf (Query,"DELETE FROM crs_usr_requests" + " WHERE UsrCod='%ld'", + UsrDat->UsrCod); + DB_QueryDELETE (Query,"can not remove user's requests for inscription"); + + /***** Remove user from the table of courses and users *****/ + sprintf (Query,"DELETE FROM crs_usr" + " WHERE UsrCod='%ld'", + UsrDat->UsrCod); + DB_QueryDELETE (Query,"can not remove a user from all courses"); + + if (QuietOrVerbose == Cns_VERBOSE) + { + sprintf (Gbl.Message,Txt_THE_USER_X_has_been_removed_from_all_his_her_courses, + UsrDat->FullName); + Lay_ShowAlert (Lay_SUCCESS,Gbl.Message); + } + + /***** Remove user as administrator of any degree *****/ + sprintf (Query,"DELETE FROM deg_admin" + " WHERE UsrCod='%ld'", + UsrDat->UsrCod); + DB_QueryDELETE (Query,"can not remove a user as administrator"); + + if (QuietOrVerbose == Cns_VERBOSE) + { + sprintf (Gbl.Message,Txt_THE_USER_X_has_been_removed_as_administrator, + UsrDat->FullName); + Lay_ShowAlert (Lay_SUCCESS,Gbl.Message); + } + + /***** Remove user's clipboards *****/ + Brw_RemoveUsrClipboard (UsrDat->UsrCod); + For_RemoveUsrFromThrClipboard (UsrDat->UsrCod); + + /***** Remove user's expanded folders *****/ + Brw_RemoveUsrExpandedFolders (UsrDat->UsrCod); + + /***** Remove exams made by user in all courses *****/ + Tst_RemoveExamsMadeByUsrInAllCrss (UsrDat->UsrCod); + + /***** 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) + { + sprintf (Gbl.Message,Txt_Messages_of_THE_USER_X_have_been_deleted, + UsrDat->FullName); + Lay_ShowAlert (Lay_SUCCESS,Gbl.Message); + } + + /***** Remove user from table of banned users *****/ + 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 *****/ + sprintf (Query,"DELETE FROM connected WHERE UsrCod='%ld'", + UsrDat->UsrCod); + DB_QueryDELETE (Query,"can not remove a user from table of connected users"); + + /***** Remove all sessions of this user *****/ + sprintf (Query,"DELETE FROM sessions WHERE UsrCod='%ld'", + UsrDat->UsrCod); + DB_QueryDELETE (Query,"can not remove sessions of a user"); + + /***** Remove the user from the list of users without photo *****/ + Pho_RemoveUsrFromTableClicksWithoutPhoto (UsrDat->UsrCod); + + /***** Remove the file tree of a user *****/ + Acc_RemoveUsrBriefcase (UsrDat); + if (QuietOrVerbose == Cns_VERBOSE) + { + sprintf (Gbl.Message,Txt_Virtual_pendrive_of_THE_USER_X_has_been_removed, + UsrDat->FullName); + Lay_ShowAlert (Lay_SUCCESS,Gbl.Message); + } + + /***** Remove user's photo *****/ + PhotoRemoved = Pho_RemovePhoto (UsrDat); + if (PhotoRemoved && QuietOrVerbose == Cns_VERBOSE) + { + sprintf (Gbl.Message,Txt_Photo_of_THE_USER_X_has_been_removed, + UsrDat->FullName); + Lay_ShowAlert (Lay_SUCCESS,Gbl.Message); + } + + /***** Remove user *****/ + Acc_RemoveUsr (UsrDat); + if (QuietOrVerbose == Cns_VERBOSE) + { + sprintf (Gbl.Message,Txt_Record_card_of_THE_USER_X_has_been_removed, + UsrDat->FullName); + Lay_ShowAlert (Lay_SUCCESS,Gbl.Message); + } + } + +/*****************************************************************************/ +/********************** Remove the briefcase of a user ***********************/ +/*****************************************************************************/ + +static void Acc_RemoveUsrBriefcase (struct UsrData *UsrDat) + { + char PathRelUsr[PATH_MAX+1]; + + /***** Remove the briefcase of the user *****/ + Usr_ConstructPathUsr (UsrDat->UsrCod,PathRelUsr); + Brw_RemoveTree (PathRelUsr); + + /***** Remove files in the course from database *****/ + Brw_RemoveFilesFromDB (-1L,-1L,UsrDat->UsrCod); + + /***** Remove size of the briefcase of the user from database *****/ + Brw_RemoveSizeOfFileTreeFromDB (-1L,-1L,UsrDat->UsrCod); + } + +/*****************************************************************************/ +/************************ Remove a user from database ************************/ +/*****************************************************************************/ + +static void Acc_RemoveUsr (struct UsrData *UsrDat) + { + char Query[128]; + + /***** Remove user's webs / social networks *****/ + sprintf (Query,"DELETE FROM usr_webs WHERE UsrCod='%ld'", + UsrDat->UsrCod); + DB_QueryDELETE (Query,"can not remove user's webs / social networks"); + + /***** Remove user's nicknames *****/ + sprintf (Query,"DELETE FROM usr_nicknames WHERE UsrCod='%ld'", + UsrDat->UsrCod); + DB_QueryDELETE (Query,"can not remove user's nicknames"); + + /***** Remove user's e-mails *****/ + sprintf (Query,"DELETE FROM pending_emails WHERE UsrCod='%ld'", + UsrDat->UsrCod); + DB_QueryDELETE (Query,"can not remove pending user's e-mails"); + + sprintf (Query,"DELETE FROM usr_emails WHERE UsrCod='%ld'", + UsrDat->UsrCod); + DB_QueryDELETE (Query,"can not remove user's e-mails"); + + /***** Remove user's IDs *****/ + sprintf (Query,"DELETE FROM usr_IDs WHERE UsrCod='%ld'", + UsrDat->UsrCod); + DB_QueryDELETE (Query,"can not remove user's IDs"); + + /***** Remove user's last data *****/ + sprintf (Query,"DELETE FROM usr_last WHERE UsrCod='%ld'", + UsrDat->UsrCod); + DB_QueryDELETE (Query,"can not remove user's last data"); + + /***** Remove user's data *****/ + sprintf (Query,"DELETE FROM usr_data WHERE UsrCod='%ld'", + UsrDat->UsrCod); + DB_QueryDELETE (Query,"can not remove user's data"); + } diff --git a/swad_account.h b/swad_account.h new file mode 100644 index 000000000..ad4892dec --- /dev/null +++ b/swad_account.h @@ -0,0 +1,60 @@ +// swad_account.h: user's account + +#ifndef _SWAD_ACC +#define _SWAD_ACC +/* + SWAD (Shared Workspace At a Distance in Spanish), + 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-2014 Antonio Caņas Vargas + + This program is free software: you can redistribute it and/or modify + it under the terms of the GNU Affero General Public License as + published by the Free Software Foundation, either version 3 of the + License, or (at your option) any later version. + + This program is distributed in the hope that it will be useful, + but WITHOUT ANY WARRANTY; without even the implied warranty of + MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the + GNU Affero General Public License for more details. + + You should have received a copy of the GNU Affero General Public License + along with this program. If not, see . +*/ +/*****************************************************************************/ +/********************************** Headers **********************************/ +/*****************************************************************************/ + +#include "swad_bool.h" +#include "swad_constant.h" +#include "swad_user.h" + +/*****************************************************************************/ +/****************************** Public constants *****************************/ +/*****************************************************************************/ + +/*****************************************************************************/ +/******************************** Public types *******************************/ +/*****************************************************************************/ + +/*****************************************************************************/ +/****************************** Public prototypes ****************************/ +/*****************************************************************************/ + +void Acc_ShowFormAccount (void); +void Acc_ShowFormChangeMyAccount (void); +bool Acc_CreateNewAccountAndLogIn (void); +void Acc_CreateNewUsr (struct UsrData *UsrDat); +void Acc_AfterCreationNewAccount (void); + +void Acc_ReqRemUsrGbl (void); +void Acc_RemUsrGbl (void); + +bool Acc_CheckIfICanEliminateAccount (bool ItsMe); +void Acc_AskIfCompletelyEliminateAccount (bool ItsMe); +void Acc_CompletelyEliminateAccount (struct UsrData *UsrDat, + Cns_QuietOrVerbose_t QuietOrVerbose); + +#endif diff --git a/swad_action.c b/swad_action.c index aea21afdc..3d7972fb7 100644 --- a/swad_action.c +++ b/swad_action.c @@ -31,6 +31,7 @@ #include // For malloc and free #include // For string functions +#include "swad_account.h" #include "swad_action.h" #include "swad_announcement.h" #include "swad_banner.h" @@ -1951,7 +1952,7 @@ struct Act_Actions Act_Actions[Act_NUM_ACTIONS] = /* ActChgPwdOthUsr */{ 82,-1,TabUsr,ActReqMdfOneUsr ,0x1E0,0x1E0,0x1E0,Act_CONTENT_NORM,Act_MAIN_WINDOW,Pwd_UpdateOtherPwd1 ,Pwd_UpdateOtherPwd2 ,NULL}, /* ActRemUsrCrs */{ 58,-1,TabUsr,ActReqMdfOneUsr ,0x1F8,0x1E0,0x000,Act_CONTENT_NORM,Act_MAIN_WINDOW,NULL ,Enr_RemUsrFromCrs ,NULL}, - /* ActRemUsrGbl */{ 62,-1,TabUsr,ActReqMdfOneUsr ,0x1FE,0x1FE,0x1FE,Act_CONTENT_NORM,Act_MAIN_WINDOW,NULL ,Enr_RemUsrGbl ,NULL}, + /* ActRemUsrGbl */{ 62,-1,TabUsr,ActReqMdfOneUsr ,0x1FE,0x1FE,0x1FE,Act_CONTENT_NORM,Act_MAIN_WINDOW,NULL ,Acc_RemUsrGbl ,NULL}, /* ActReqRemAllStdCrs*/{ 88,-1,TabUsr,ActReqMdfSevUsr ,0x110,0x100,0x000,Act_CONTENT_NORM,Act_MAIN_WINDOW,NULL ,Enr_AskRemAllStdsThisCrs ,NULL}, /* ActRemAllStdCrs */{ 87,-1,TabUsr,ActReqMdfSevUsr ,0x110,0x100,0x000,Act_CONTENT_NORM,Act_MAIN_WINDOW,NULL ,Enr_RemAllStdsThisCrs ,NULL}, @@ -2186,7 +2187,7 @@ struct Act_Actions Act_Actions[Act_NUM_ACTIONS] = // TabPrf ****************************************************************** // Actions in menu: /* ActFrmLogIn */{ 843, 0,TabPrf,ActFrmLogIn ,0x1FF,0x1FF,0x1FF,Act_CONTENT_NORM,Act_MAIN_WINDOW,NULL ,Usr_WriteFormLoginLogout ,"keyuser" }, - /* ActFrmUsrAcc */{ 36, 1,TabPrf,ActFrmUsrAcc ,0x1FF,0x1FF,0x1FF,Act_CONTENT_NORM,Act_MAIN_WINDOW,NULL ,Enr_ShowFormAccount ,"arroba" }, + /* ActFrmUsrAcc */{ 36, 1,TabPrf,ActFrmUsrAcc ,0x1FF,0x1FF,0x1FF,Act_CONTENT_NORM,Act_MAIN_WINDOW,NULL ,Acc_ShowFormAccount ,"arroba" }, /* ActReqSndNewPwd */{ 665, 2,TabPrf,ActReqSndNewPwd ,0x000,0x001,0x001,Act_CONTENT_NORM,Act_MAIN_WINDOW,NULL ,Pwd_ShowFormSendNewPwd ,"key" }, /* ActFrmChgMyPwd */{ 34, 3,TabPrf,ActFrmChgMyPwd ,0x1FE,0x1FE,0x1FE,Act_CONTENT_NORM,Act_MAIN_WINDOW,NULL ,Pwd_ShowFormChgPwd ,"key" }, /* ActReqEdiRecCom */{ 285, 4,TabPrf,ActReqEdiRecCom ,0x1FE,0x1FE,0x1FE,Act_CONTENT_NORM,Act_MAIN_WINDOW,NULL ,Rec_ShowFormMyCommRecord ,"card" }, @@ -2208,7 +2209,7 @@ struct Act_Actions Act_Actions[Act_NUM_ACTIONS] = /* ActChgMyRol */{ 589,-1,TabPrf,ActFrmLogIn ,0x1FE,0x1FE,0x1FE,Act_CONTENT_NORM,Act_MAIN_WINDOW,Rol_ChangeMyRole ,Usr_ShowFormsRoleAndLogout ,NULL}, - /* ActCreUsrAcc */{1163,-1,TabPrf,ActFrmUsrAcc ,0x1FF,0x1FF,0x1FF,Act_CONTENT_NORM,Act_MAIN_WINDOW,NULL ,Enr_AfterCreationNewAccount ,NULL}, + /* ActCreUsrAcc */{1163,-1,TabPrf,ActFrmUsrAcc ,0x1FF,0x1FF,0x1FF,Act_CONTENT_NORM,Act_MAIN_WINDOW,NULL ,Acc_AfterCreationNewAccount ,NULL}, /* ActRemIDMe */{1147,-1,TabPrf,ActFrmUsrAcc ,0x1FE,0x1FE,0x1FE,Act_CONTENT_NORM,Act_MAIN_WINDOW,NULL ,ID_RemoveMyUsrID ,NULL}, /* ActNewIDMe */{1148,-1,TabPrf,ActFrmUsrAcc ,0x1FE,0x1FE,0x1FE,Act_CONTENT_NORM,Act_MAIN_WINDOW,NULL ,ID_NewMyUsrID ,NULL}, @@ -3889,7 +3890,7 @@ void Act_AdjustCurrentAction (void) if (!Gbl.Usrs.Me.MyPhotoExists) if (!(Act_Actions[Gbl.CurrentAct].PermisIfIBelongToCrs & (1 << Rol_ROLE_UNKNOWN)) && // If current action is not available for unknown users... Gbl.CurrentAct != ActReqMyPho) // ...and current action is not ActReqMyPho... - if ((Gbl.Usrs.Me.NumAccWithoutPhoto = Usr_UpdateMyClicksWithoutPhoto ()) > Usr_MAX_CLICKS_WITHOUT_PHOTO) + if ((Gbl.Usrs.Me.NumAccWithoutPhoto = Pho_UpdateMyClicksWithoutPhoto ()) > Pho_MAX_CLICKS_WITHOUT_PHOTO) { /* If limit of clicks has been reached, the only action possible is show a form to send my photo */ diff --git a/swad_changelog.h b/swad_changelog.h index de3809ce7..a71d29ca0 100644 --- a/swad_changelog.h +++ b/swad_changelog.h @@ -35,12 +35,16 @@ /****************************** Public constants *****************************/ /*****************************************************************************/ -#define Log_PLATFORM_VERSION "SWAD 14.36 (2014/12/12)" +#define Log_PLATFORM_VERSION "SWAD 14.37 (2014/12/12)" // Number of lines (includes comments but not blank lines) has been got with the following command: // nl swad*.c swad*.h css/swad*.css py/swad*.py js/swad*.js soap/swad*.h | tail -1 /* + Version 14.37 :Dic 12, 2014 New module swad_account for user's account. (170863 lines) + 1 change necessary in Makefile: +Add swad_account.o to list of object files + Version 14.36 :Dic 12, 2014 New module swad_role for user's roles. (170764 lines) 1 change necessary in Makefile: Add swad_role.o to list of object files diff --git a/swad_enrollment.c b/swad_enrollment.c index 65635745e..3eb083b70 100644 --- a/swad_enrollment.c +++ b/swad_enrollment.c @@ -28,6 +28,7 @@ #include // For exit, system, malloc, free, rand, etc. #include // For string functions +#include "swad_account.h" #include "swad_announcement.h" #include "swad_database.h" #include "swad_enrollment.h" @@ -49,16 +50,6 @@ /****************************** Internal types *******************************/ /*****************************************************************************/ -#define Enr_NUM_ACTIONS_REG_REM_ONE_USR 5 -typedef enum - { - Enr_REGISTER_MODIFY_ONE_USR_IN_CRS = 0, - Enr_REGISTER_ONE_DEGREE_ADMIN = 1, - Enr_REMOVE_ONE_USR_FROM_CRS = 2, - Enr_REMOVE_ONE_DEGREE_ADMIN = 3, - Enr_ELIMINATE_ONE_USR_FROM_PLATFORM = 4, - } Enr_RegRemOneUsrAction_t; - #define Enr_NUM_ACTIONS_REG_REM_USRS 5 typedef enum { @@ -69,6 +60,12 @@ typedef enum Enr_ELIMINATE_USRS_FROM_PLATFORM = 4, } Enr_RegRemUsrsAction_t; +typedef enum + { + Enr_REQUEST_REMOVE_USR, + Enr_REMOVE_USR, + } Enr_ReqDelOrDelUsr_t; + typedef enum { Enr_DO_NOT_REMOVE_WORKS, @@ -89,18 +86,9 @@ extern struct Globals Gbl; /***************************** Private prototypes ****************************/ /*****************************************************************************/ -static void Enr_ShowFormRequestNewAccountWithParams (const char *NewNicknameWithoutArroba, - const char *NewEmail); -static bool Enr_GetParamsNewAccount (char *NewNicknameWithoutArroba, - char *NewEmail, - char *NewEncryptedPassword); -static void Enr_PrintAccountSeparator (void); - static void Enr_PutFormToRemOldUsrs (void); static void Enr_PutAreaToEnterUsrsIDs (void); static bool Enr_PutActionsRegRemOneUsr (bool ItsMe); -static bool Enr_CheckIfICanEliminateAccount (bool ItsMe); -static void Enr_PutLinkToRemoveMyAccount (void); static void Enr_PutActionsRegRemSeveralUsrs (void); static void Enr_RegisterUsr (struct UsrData *UsrDat,Rol_Role_t RegRemRole, @@ -117,21 +105,18 @@ static void Enr_AskIfRegRemUsr (struct ListUsrCods *ListUsrCods); static void Enr_ShowFormToEditOtherUsr (void); static void Enr_RegisterAdminInCurrentDeg (struct UsrData *UsrDat); +static void Enr_ReqRemOrRemUsrFromCrs (Enr_ReqDelOrDelUsr_t ReqDelOrDelUsr); static void Enr_ReqRemAdmOfDeg (void); static void Enr_ReqRemOrRemAdm (Enr_ReqDelOrDelUsr_t ReqDelOrDelUsr); -static void Enr_AskIfRemoveUsrFromCrs (struct UsrData *UsrDat,bool ItsMe); -static void Enr_AskIfCompletelyEliminateUsrFromPlatform (bool ItsMe); static void Enr_ReqAddAdmOfDeg (void); -static void Enr_CreateNewEncryptedUsrCod (struct UsrData *UsrDat); -static void Enr_FilterUsrDat (struct UsrData *UsrDat); +static void Enr_AskIfRemoveUsrFromCrs (struct UsrData *UsrDat,bool ItsMe); static void Enr_EffectivelyRemUsrFromCrs (struct UsrData *UsrDat,struct Course *Crs, Enr_RemoveUsrWorks_t RemoveUsrWorks,Cns_QuietOrVerbose_t QuietOrVerbose); + +static void Enr_AskIfRemAdmFromDeg (bool ItsMe); static void Enr_EffectivelyRemAdmFromDeg (struct UsrData *UsrDat); -static void Enr_DeleteUsrFromPlatform (struct UsrData *UsrDat, - Cns_QuietOrVerbose_t QuietOrVerbose); -static void Enr_RemoveUsr (struct UsrData *UsrDat); /*****************************************************************************/ /***************** Modify the role of a user in a course *********************/ @@ -241,154 +226,6 @@ void Enr_RegisterUsrInCurrentCrs (struct UsrData *UsrDat,Rol_Role_t NewRole, } } -/*****************************************************************************/ -/************************ Remove a user from a course ************************/ -/*****************************************************************************/ - -static void Enr_EffectivelyRemUsrFromCrs (struct UsrData *UsrDat,struct Course *Crs, - Enr_RemoveUsrWorks_t RemoveUsrWorks,Cns_QuietOrVerbose_t QuietOrVerbose) - { - extern const char *Txt_THE_USER_X_has_been_removed_from_the_course_Y; - extern const char *Txt_User_not_found_or_you_do_not_have_permission_; - char Query[1024]; - - if (Usr_CheckIfUsrBelongsToCrs (UsrDat->UsrCod,Crs->CrsCod)) // User belongs to the course - { - /***** Remove user from all the attendance events in course *****/ - Att_RemoveUsrFromCrsAttEvents (UsrDat->UsrCod,Crs->CrsCod); - - /***** Remove user from all the groups in course *****/ - Grp_RemUsrFromAllGrpsInCrs (UsrDat,Crs,QuietOrVerbose); - - /***** Remove user's status about reading of course information *****/ - Inf_RemoveUsrFromCrsInfoRead (UsrDat->UsrCod,Crs->CrsCod); - - /***** Remove works zone of this user in course *****/ - if (RemoveUsrWorks == Enr_REMOVE_WORKS) - Brw_RemoveUsrWorksInCrs (UsrDat,Crs,QuietOrVerbose); - - /***** Remove fields of this user in its course record *****/ - Rec_RemoveFieldsCrsRecordInCrs (UsrDat->UsrCod,Crs,QuietOrVerbose); - - /***** Remove user's clipboard in course *****/ - Brw_RemoveUsrClipboardInCrs (UsrDat->UsrCod,Crs->CrsCod); - - /***** Remove user's expanded folders in course *****/ - Brw_RemoveUsrExpandedFoldersInCrs (UsrDat->UsrCod,Crs->CrsCod); - - /***** Remove exams made by user in course *****/ - Tst_RemoveExamsMadeByUsrInCrs (UsrDat->UsrCod,Crs->CrsCod); - - /***** Set all the notifications for this user in this course as removed, - except notifications about new messages *****/ - Ntf_SetNotifInCrsAsRemoved (Crs->CrsCod,UsrDat->UsrCod); - - /***** Remove user from the table of courses-users *****/ - sprintf (Query,"DELETE FROM crs_usr" - " WHERE CrsCod='%ld' AND UsrCod='%ld'", - Crs->CrsCod,UsrDat->UsrCod); - DB_QueryDELETE (Query,"can not remove a user from a course"); - - if (QuietOrVerbose == Cns_VERBOSE) - { - sprintf (Gbl.Message,Txt_THE_USER_X_has_been_removed_from_the_course_Y, - UsrDat->FullName,Crs->FullName); - Lay_ShowAlert (Lay_SUCCESS,Gbl.Message); - } - } - else // User does not belong to course - if (QuietOrVerbose == Cns_VERBOSE) - Lay_ShowAlert (Lay_WARNING,Txt_User_not_found_or_you_do_not_have_permission_); - } - -/*****************************************************************************/ -/************* Remove an administrator from current degree *******************/ -/*****************************************************************************/ - -static void Enr_EffectivelyRemAdmFromDeg (struct UsrData *UsrDat) - { - extern const char *Txt_THE_USER_X_has_been_removed_as_administrator_of_the_degree_Y; - extern const char *Txt_THE_USER_X_is_not_an_administrator_of_the_degree_Y; - char Query[1024]; - - if (Usr_CheckIfUsrIsAdmOfDeg (UsrDat->UsrCod,Gbl.CurrentDeg.Deg.DegCod)) // User is administrator of current degree - { - /***** Remove user from the table of courses-users *****/ - sprintf (Query,"DELETE FROM deg_admin" - " WHERE UsrCod='%ld' AND DegCod='%ld'", - UsrDat->UsrCod,Gbl.CurrentDeg.Deg.DegCod); - DB_QueryDELETE (Query,"can not remove an administrator from a degree"); - - sprintf (Gbl.Message,Txt_THE_USER_X_has_been_removed_as_administrator_of_the_degree_Y, - UsrDat->FullName,Gbl.CurrentDeg.Deg.FullName); - Lay_ShowAlert (Lay_SUCCESS,Gbl.Message); - } - else // User is not an administrator of the current degree - { - sprintf (Gbl.Message,Txt_THE_USER_X_is_not_an_administrator_of_the_degree_Y, - UsrDat->FullName,Gbl.CurrentDeg.Deg.FullName); - Lay_ShowAlert (Lay_ERROR,Gbl.Message); - } - } - -/*****************************************************************************/ -/*************** Create new user account with an ID and login ****************/ -/*****************************************************************************/ -// Return true if no error and user can be logged in -// Return false on error - -bool Enr_CreateNewAccountAndLogIn (void) - { - char NewNicknameWithoutArroba[Nck_MAX_BYTES_NICKNAME_WITH_ARROBA+1]; - char NewEmail[Cns_MAX_BYTES_STRING+1]; - char NewEncryptedPassword[Cry_LENGTH_ENCRYPTED_STR_SHA512_BASE64+1]; - - if (Enr_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 *****/ - strcpy (Gbl.Usrs.Me.UsrDat.Password,NewEncryptedPassword); - - /***** User does not exist in the platform, so create him/her! *****/ - Enr_CreateNewUsr (&Gbl.Usrs.Me.UsrDat); - - /***** Save nickname *****/ - Nck_UpdateMyNick (NewNicknameWithoutArroba); - strcpy (Gbl.Usrs.Me.UsrDat.Nickname,NewNicknameWithoutArroba); - - /***** Save e-mail *****/ - if (Mai_UpdateEmailInDB (&Gbl.Usrs.Me.UsrDat,NewEmail)) - { - /* E-mail updated sucessfully */ - strcpy (Gbl.Usrs.Me.UsrDat.Email,NewEmail); - Gbl.Usrs.Me.UsrDat.EmailConfirmed = false; - } - - return true; - } - else - { - /***** Show form again ******/ - Enr_ShowFormRequestNewAccountWithParams (NewNicknameWithoutArroba,NewEmail); - return false; - } - } - -/*****************************************************************************/ -/******** Remove user from table with number of clicks without photo *********/ -/*****************************************************************************/ - -void Enr_RemoveUsrFromTableClicksWithoutPhoto (long UsrCod) - { - char Query[512]; - - sprintf (Query,"DELETE FROM clicks_without_photo WHERE UsrCod='%ld'",UsrCod); - DB_QueryDELETE (Query,"can not remove a user from the list of users without photo"); - } - /*****************************************************************************/ /****** Write a form to request another user's ID, @nickname or e-mail *******/ /*****************************************************************************/ @@ -415,472 +252,6 @@ void Enr_WriteFormToReqAnotherUsrID (Act_Action_t NextAction) fprintf (Gbl.F.Out,""); } -/*****************************************************************************/ -/********************* Show form to create a new account *********************/ -/*****************************************************************************/ - -static void Enr_ShowFormRequestNewAccountWithParams (const char *NewNicknameWithoutArroba, - const char *NewEmail) - { - extern const char *The_ClassFormul[The_NUM_THEMES]; - extern const char *Txt_Log_in; - extern const char *Txt_Nickname; - extern const char *Txt_Email; - // extern const char *Txt_ID; - extern const char *Txt_New_on_PLATFORM_Sign_up; - extern const char *Txt_Create_account; - - /***** Link to log in *****/ - fprintf (Gbl.F.Out,"
"); - Act_FormStart (ActFrmLogIn); - Act_LinkFormSubmit (Txt_Log_in,The_ClassFormul[Gbl.Prefs.Theme]); - Lay_PutSendIcon ("login",Txt_Log_in,Txt_Log_in); - fprintf (Gbl.F.Out,"" - "
"); - - /***** Form to enter the ID of the new user *****/ - fprintf (Gbl.F.Out,"
"); - Act_FormStart (ActCreUsrAcc); - sprintf (Gbl.Title,Txt_New_on_PLATFORM_Sign_up,Cfg_PLATFORM_SHORT_NAME); - Lay_StartRoundFrameTable10 (NULL,2,Gbl.Title); - - /***** Nickname *****/ - fprintf (Gbl.F.Out,"" - "" - "%s: " - "" - "" - "" - "" - "", - The_ClassFormul[Gbl.Prefs.Theme], - Txt_Nickname, - 1+Nck_MAX_LENGTH_NICKNAME_WITHOUT_ARROBA, - NewNicknameWithoutArroba); - - /***** E-mail *****/ - fprintf (Gbl.F.Out,"" - "" - "%s: " - "" - "" - "" - "" - "", - The_ClassFormul[Gbl.Prefs.Theme], - Txt_Email, - Cns_MAX_BYTES_STRING, - NewEmail); - - /***** Password *****/ - Pwd_PutFormToGetNewPasswordTwice (); - - /***** Send button and form end *****/ - fprintf (Gbl.F.Out,"" - "" - "" - "" - "", - Txt_Create_account); - Lay_EndRoundFrameTable10 (); - fprintf (Gbl.F.Out,"" - "
"); - } - -/*****************************************************************************/ -/************* Get parameters for the creation of a new account **************/ -/*****************************************************************************/ -// Return false on error - -static bool Enr_GetParamsNewAccount (char *NewNicknameWithoutArroba, - 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; - extern const char *Txt_You_have_not_written_twice_the_same_new_password; - char Query[1024]; - char NewNicknameWithArroba[Nck_MAX_BYTES_NICKNAME_WITH_ARROBA+1]; - char NewPlainPassword[2][Pwd_MAX_LENGTH_PLAIN_PASSWORD+1]; - bool Error = false; - - /***** Step 1/3: Get new nickname from form *****/ - Par_GetParToText ("NewNick",NewNicknameWithArroba,Nck_MAX_BYTES_NICKNAME_WITH_ARROBA); - - if (Nck_CheckIfNickWithArrobaIsValid (NewNicknameWithArroba)) // If new nickname is valid - { - /***** Remove arrobas at the beginning *****/ - strncpy (NewNicknameWithoutArroba,NewNicknameWithArroba,Nck_MAX_BYTES_NICKNAME_WITH_ARROBA); - NewNicknameWithoutArroba[Nck_MAX_BYTES_NICKNAME_WITH_ARROBA] = '\0'; - Str_RemoveLeadingArrobas (NewNicknameWithoutArroba); - - /***** Check if the new nickname matches any of the nicknames of other users *****/ - sprintf (Query,"SELECT COUNT(*) FROM usr_nicknames" - " WHERE Nickname='%s' AND UsrCod<>'%ld'", - NewNicknameWithoutArroba,Gbl.Usrs.Me.UsrDat.UsrCod); - if (DB_QueryCOUNT (Query,"can not check if nickname already existed")) // A nickname of another user is the same that this nickname - { - Error = true; - sprintf (Gbl.Message,Txt_The_nickname_X_had_been_registered_by_another_user, - NewNicknameWithoutArroba); - Lay_ShowAlert (Lay_WARNING,Gbl.Message); - } - } - else // New nickname is not valid - { - Error = true; - sprintf (Gbl.Message,Txt_The_nickname_entered_X_is_not_valid_, - NewNicknameWithArroba, - Nck_MIN_LENGTH_NICKNAME_WITHOUT_ARROBA, - Nck_MAX_LENGTH_NICKNAME_WITHOUT_ARROBA); - Lay_ShowAlert (Lay_WARNING,Gbl.Message); - } - - /***** Step 2/3: Get new e-mail from form *****/ - Par_GetParToText ("NewEmail",NewEmail,Cns_MAX_BYTES_STRING); - - if (Mai_CheckIfEmailIsValid (NewEmail)) // New e-mail is valid - { - /***** Check if the new e-mail matches any of the confirmed e-mails of other users *****/ - sprintf (Query,"SELECT COUNT(*) FROM usr_emails" - " WHERE E_mail='%s' AND Confirmed='Y'", - NewEmail); - if (DB_QueryCOUNT (Query,"can not check if e-mail already existed")) // An e-mail of another user is the same that my e-mail - { - Error = true; - sprintf (Gbl.Message,Txt_The_email_address_X_had_been_registered_by_another_user, - NewEmail); - Lay_ShowAlert (Lay_WARNING,Gbl.Message); - } - } - else // New e-mail is not valid - { - Error = true; - sprintf (Gbl.Message,Txt_The_email_address_entered_X_is_not_valid, - NewEmail); - Lay_ShowAlert (Lay_WARNING,Gbl.Message); - } - - /***** Step 3/3: Get new user's ID from form *****/ - Par_GetParToText ("Paswd1",NewPlainPassword[0],Pwd_MAX_LENGTH_PLAIN_PASSWORD); - Par_GetParToText ("Paswd2",NewPlainPassword[1],Pwd_MAX_LENGTH_PLAIN_PASSWORD); - if (strcmp (NewPlainPassword[0],NewPlainPassword[1])) - { - // Passwords don't match - Error = true; - Lay_ShowAlert (Lay_WARNING,Txt_You_have_not_written_twice_the_same_new_password); - } - else - { - Str_ChangeFormat (Str_FROM_FORM,Str_TO_TEXT, - NewPlainPassword[0],Pwd_MAX_LENGTH_PLAIN_PASSWORD,true); - Cry_EncryptSHA512Base64 (NewPlainPassword[0],NewEncryptedPassword); - if (!Pwd_SlowCheckIfPasswordIsGood (NewPlainPassword[0],NewEncryptedPassword,-1L)) // New password is good? - { - Error = true; - Lay_ShowAlert (Lay_WARNING,Gbl.Message); // Error message is set in Usr_SlowCheckIfPasswordIsGood - } - } - - return !Error; - } - -/*****************************************************************************/ -/***************** Message after creation of a new account *******************/ -/*****************************************************************************/ - -void Enr_AfterCreationNewAccount (void) - { - extern const char *Txt_New_account_created; - - if (Gbl.Usrs.Me.Logged) // If account has been created without problem, I am logged - { - /***** Show message of success *****/ - Lay_ShowAlert (Lay_SUCCESS,Txt_New_account_created); - - /***** Show form with account data *****/ - Enr_ShowFormChangeMyAccount (); - } - } - -/*****************************************************************************/ -/******** Show form to change my account or to create a new account **********/ -/*****************************************************************************/ - -void Enr_ShowFormAccount (void) - { - if (Gbl.Usrs.Me.Logged) - Enr_ShowFormChangeMyAccount (); - else - Enr_ShowFormRequestNewAccountWithParams ("",""); - } - -/*****************************************************************************/ -/*********************** Show form to change my account **********************/ -/*****************************************************************************/ - -void Enr_ShowFormChangeMyAccount (void) - { - extern const char *Txt_Before_going_to_any_other_option_you_must_fill_your_nickname; - extern const char *Txt_Before_going_to_any_other_option_you_must_fill_your_email_address; - extern const char *Txt_Before_going_to_any_other_option_you_must_fill_your_ID; - extern const char *Txt_User_account; - - /***** Get current user's nickname and e-mail address - It's necessary because current nickname or e-mail could be just updated *****/ - Nck_GetNicknameFromUsrCod (Gbl.Usrs.Me.UsrDat.UsrCod,Gbl.Usrs.Me.UsrDat.Nickname); - Mai_GetEmailFromUsrCod (Gbl.Usrs.Me.UsrDat.UsrCod,Gbl.Usrs.Me.UsrDat.Email,&(Gbl.Usrs.Me.UsrDat.EmailConfirmed)); - - /***** Check nickname and e-mail *****/ - if (!Gbl.Usrs.Me.UsrDat.Nickname[0]) - Lay_ShowAlert (Lay_WARNING,Txt_Before_going_to_any_other_option_you_must_fill_your_nickname); - else if (!Gbl.Usrs.Me.UsrDat.Email[0]) - Lay_ShowAlert (Lay_WARNING,Txt_Before_going_to_any_other_option_you_must_fill_your_email_address); - else if (!Gbl.Usrs.Me.UsrDat.IDs.Num) - Lay_ShowAlert (Lay_WARNING,Txt_Before_going_to_any_other_option_you_must_fill_your_ID); - - /***** Put links to change my password and to remove my account*****/ - fprintf (Gbl.F.Out,"
"); - Pwd_PutLinkToChangeUsrPassword (&Gbl.Usrs.Me.UsrDat); - if (Enr_CheckIfICanEliminateAccount (true)) // ItsMe = true - Enr_PutLinkToRemoveMyAccount (); - fprintf (Gbl.F.Out,"
"); - - /***** Start table *****/ - Lay_StartRoundFrameTable10 ("80%",2,Txt_User_account); - - /***** Nickname *****/ - Nck_ShowFormChangeUsrNickname (); - - /***** Separator *****/ - Enr_PrintAccountSeparator (); - - /***** E-mail *****/ - Mai_ShowFormChangeUsrEmail (); - - /***** Separator *****/ - Enr_PrintAccountSeparator (); - - /***** User's ID *****/ - ID_ShowFormChangeUsrID (&Gbl.Usrs.Me.UsrDat,true); - - /***** End of table *****/ - Lay_EndRoundFrameTable10 (); - } - -static void Enr_PrintAccountSeparator (void) - { - extern const char *The_ClassSeparator[The_NUM_THEMES]; - - /***** Separator *****/ - fprintf (Gbl.F.Out,"" - "" - "
" - "" - "", - The_ClassSeparator[Gbl.Prefs.Theme]); - } - - -/*****************************************************************************/ -/************* Remove completely a user from the whole platform **************/ -/*****************************************************************************/ - -static void Enr_DeleteUsrFromPlatform (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; - extern const char *Txt_Virtual_pendrive_of_THE_USER_X_has_been_removed; - 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; - char Query[1024]; - bool PhotoRemoved = false; - - /***** Remove the works zones of the user in all courses *****/ - Brw_RemoveUsrWorksInAllCrss (UsrDat,QuietOrVerbose); // Make this before of removing the user from the courses - - /***** Remove the fields of course record in all courses *****/ - Rec_RemoveFieldsCrsRecordAll (UsrDat->UsrCod,QuietOrVerbose); - - /***** Remove user from all the attendance events *****/ - Att_RemoveUsrFromAllAttEvents (UsrDat->UsrCod); - - /***** Remove user from all the groups of all courses *****/ - Grp_RemUsrFromAllGrps (UsrDat,QuietOrVerbose); - - /***** Remove user's requests for inscription *****/ - sprintf (Query,"DELETE FROM crs_usr_requests" - " WHERE UsrCod='%ld'", - UsrDat->UsrCod); - DB_QueryDELETE (Query,"can not remove user's requests for inscription"); - - /***** Remove user from the table of courses and users *****/ - sprintf (Query,"DELETE FROM crs_usr" - " WHERE UsrCod='%ld'", - UsrDat->UsrCod); - DB_QueryDELETE (Query,"can not remove a user from all courses"); - - if (QuietOrVerbose == Cns_VERBOSE) - { - sprintf (Gbl.Message,Txt_THE_USER_X_has_been_removed_from_all_his_her_courses, - UsrDat->FullName); - Lay_ShowAlert (Lay_SUCCESS,Gbl.Message); - } - - /***** Remove user as administrator of any degree *****/ - sprintf (Query,"DELETE FROM deg_admin" - " WHERE UsrCod='%ld'", - UsrDat->UsrCod); - DB_QueryDELETE (Query,"can not remove a user as administrator"); - - if (QuietOrVerbose == Cns_VERBOSE) - { - sprintf (Gbl.Message,Txt_THE_USER_X_has_been_removed_as_administrator, - UsrDat->FullName); - Lay_ShowAlert (Lay_SUCCESS,Gbl.Message); - } - - /***** Remove user's clipboards *****/ - Brw_RemoveUsrClipboard (UsrDat->UsrCod); - For_RemoveUsrFromThrClipboard (UsrDat->UsrCod); - - /***** Remove user's expanded folders *****/ - Brw_RemoveUsrExpandedFolders (UsrDat->UsrCod); - - /***** Remove exams made by user in all courses *****/ - Tst_RemoveExamsMadeByUsrInAllCrss (UsrDat->UsrCod); - - /***** 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) - { - sprintf (Gbl.Message,Txt_Messages_of_THE_USER_X_have_been_deleted, - UsrDat->FullName); - Lay_ShowAlert (Lay_SUCCESS,Gbl.Message); - } - - /***** Remove user from table of banned users *****/ - 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 *****/ - sprintf (Query,"DELETE FROM connected WHERE UsrCod='%ld'", - UsrDat->UsrCod); - DB_QueryDELETE (Query,"can not remove a user from table of connected users"); - - /***** Remove all sessions of this user *****/ - sprintf (Query,"DELETE FROM sessions WHERE UsrCod='%ld'", - UsrDat->UsrCod); - DB_QueryDELETE (Query,"can not remove sessions of a user"); - - /***** Remove the user from the list of users without photo *****/ - Enr_RemoveUsrFromTableClicksWithoutPhoto (UsrDat->UsrCod); - - /***** Remove the file tree of a user *****/ - Enr_RemoveUsrBriefcase (UsrDat); - if (QuietOrVerbose == Cns_VERBOSE) - { - sprintf (Gbl.Message,Txt_Virtual_pendrive_of_THE_USER_X_has_been_removed, - UsrDat->FullName); - Lay_ShowAlert (Lay_SUCCESS,Gbl.Message); - } - - /***** Remove user's photo *****/ - PhotoRemoved = Pho_RemovePhoto (UsrDat); - if (PhotoRemoved && QuietOrVerbose == Cns_VERBOSE) - { - sprintf (Gbl.Message,Txt_Photo_of_THE_USER_X_has_been_removed, - UsrDat->FullName); - Lay_ShowAlert (Lay_SUCCESS,Gbl.Message); - } - - /***** Remove user *****/ - Enr_RemoveUsr (UsrDat); - if (QuietOrVerbose == Cns_VERBOSE) - { - sprintf (Gbl.Message,Txt_Record_card_of_THE_USER_X_has_been_removed, - UsrDat->FullName); - Lay_ShowAlert (Lay_SUCCESS,Gbl.Message); - } - } - -/*****************************************************************************/ -/********************** Remove the briefcase of a user ***********************/ -/*****************************************************************************/ - -void Enr_RemoveUsrBriefcase (struct UsrData *UsrDat) - { - char PathRelUsr[PATH_MAX+1]; - - /***** Remove the briefcase of the user *****/ - Usr_ConstructPathUsr (UsrDat->UsrCod,PathRelUsr); - Brw_RemoveTree (PathRelUsr); - - /***** Remove files in the course from database *****/ - Brw_RemoveFilesFromDB (-1L,-1L,UsrDat->UsrCod); - - /***** Remove size of the briefcase of the user from database *****/ - Brw_RemoveSizeOfFileTreeFromDB (-1L,-1L,UsrDat->UsrCod); - } - -/*****************************************************************************/ -/************************ Remove a user from database ************************/ -/*****************************************************************************/ - -static void Enr_RemoveUsr (struct UsrData *UsrDat) - { - char Query[128]; - - /***** Remove user's webs / social networks *****/ - sprintf (Query,"DELETE FROM usr_webs WHERE UsrCod='%ld'", - UsrDat->UsrCod); - DB_QueryDELETE (Query,"can not remove user's webs / social networks"); - - /***** Remove user's nicknames *****/ - sprintf (Query,"DELETE FROM usr_nicknames WHERE UsrCod='%ld'", - UsrDat->UsrCod); - DB_QueryDELETE (Query,"can not remove user's nicknames"); - - /***** Remove user's e-mails *****/ - sprintf (Query,"DELETE FROM pending_emails WHERE UsrCod='%ld'", - UsrDat->UsrCod); - DB_QueryDELETE (Query,"can not remove pending user's e-mails"); - - sprintf (Query,"DELETE FROM usr_emails WHERE UsrCod='%ld'", - UsrDat->UsrCod); - DB_QueryDELETE (Query,"can not remove user's e-mails"); - - /***** Remove user's IDs *****/ - sprintf (Query,"DELETE FROM usr_IDs WHERE UsrCod='%ld'", - UsrDat->UsrCod); - DB_QueryDELETE (Query,"can not remove user's IDs"); - - /***** Remove user's last data *****/ - sprintf (Query,"DELETE FROM usr_last WHERE UsrCod='%ld'", - UsrDat->UsrCod); - DB_QueryDELETE (Query,"can not remove user's last data"); - - /***** Remove user's data *****/ - sprintf (Query,"DELETE FROM usr_data WHERE UsrCod='%ld'", - UsrDat->UsrCod); - DB_QueryDELETE (Query,"can not remove user's data"); - } - /*****************************************************************************/ /****** Request acceptation / refusion of register in current course *********/ /*****************************************************************************/ @@ -971,108 +342,6 @@ void Enr_GetNotifEnrollment (char *SummaryStr, } } -/*****************************************************************************/ -/****************************** Create new user ******************************/ -/*****************************************************************************/ -// UsrDat->UsrCod must be <= 0 -// UsrDat->UsrDat.IDs must contain a list of IDs for the new user - -void Enr_CreateNewUsr (struct UsrData *UsrDat) - { - extern const char *Ico_IconSetId[Ico_NUM_ICON_SETS]; - extern const char *The_ThemeId[The_NUM_THEMES]; - extern const char *Txt_STR_LANG_ID[Txt_NUM_LANGUAGES]; - extern const char *Usr_StringsSexDB[Usr_NUM_SEXS]; - char Query[2048]; - char PathRelUsr[PATH_MAX+1]; - 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 *****/ - Enr_CreateNewEncryptedUsrCod (UsrDat); - - /***** Filter some user's data before inserting */ - Enr_FilterUsrDat (UsrDat); - - /***** Insert new user in database *****/ - /* Insert user's data */ - sprintf (Query,"INSERT INTO usr_data (EncryptedUsrCod,Password,Surname1,Surname2,FirstName,Sex," - "Layout,Theme,IconSet,Language,PublicPhoto," - "CtyCod," - "LocalAddress,LocalPhone,FamilyAddress,FamilyPhone,OriginPlace,Birthday,Comments," - "SideCols,NotifNtfEvents,EmailNtfEvents)" - " VALUES ('%s','%s','%s','%s','%s','%s'," - "'%u','%s','%s','%s','%c'," - "'%ld'," - "'%s','%s','%s','%s','%s','%04u-%02u-%02u','%s'," - "'3','-1','0')", - UsrDat->EncryptedUsrCod, - UsrDat->Password, - UsrDat->Surname1,UsrDat->Surname2,UsrDat->FirstName, - Usr_StringsSexDB[UsrDat->Sex], - (unsigned) UsrDat->Prefs.Layout, - The_ThemeId[UsrDat->Prefs.Theme], - Ico_IconSetId[UsrDat->Prefs.IconSet], - Txt_STR_LANG_ID[UsrDat->Prefs.Language], - UsrDat->PublicPhoto ? 'Y' : - 'N', - UsrDat->CtyCod, - UsrDat->LocalAddress ,UsrDat->LocalPhone, - UsrDat->FamilyAddress,UsrDat->FamilyPhone, - UsrDat->OriginPlace, - UsrDat->Birthday.Year,UsrDat->Birthday.Month,UsrDat->Birthday.Day, - UsrDat->Comments ? UsrDat->Comments : - ""); - UsrDat->UsrCod = DB_QueryINSERTandReturnCode (Query,"can not create user"); - - /* Insert user's IDs as confirmed */ - for (NumID = 0; - NumID < UsrDat->IDs.Num; - NumID++) - { - Str_ConvertToUpperText (UsrDat->IDs.List[NumID].ID); - sprintf (Query,"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'); - DB_QueryINSERT (Query,"can not store user's ID when creating user"); - } - - /***** Create directory for the user, if not exists *****/ - Usr_ConstructPathUsr (UsrDat->UsrCod,PathRelUsr); - Fil_CreateDirIfNotExists (PathRelUsr); - } - -/*****************************************************************************/ -/******************** Create a new encrypted user's code *********************/ -/*****************************************************************************/ - -#define LENGTH_RANDOM_STR 32 -#define MAX_TRY 10 - -static void Enr_CreateNewEncryptedUsrCod (struct UsrData *UsrDat) - { - char RandomStr[LENGTH_RANDOM_STR+1]; - 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."); - } - /*****************************************************************************/ /***************************** Update user's data ****************************/ /*****************************************************************************/ @@ -1124,7 +393,7 @@ void Enr_UpdateUsrData (struct UsrData *UsrDat) /************************* Filter some user's data ***************************/ /*****************************************************************************/ -static void Enr_FilterUsrDat (struct UsrData *UsrDat) +void Enr_FilterUsrDat (struct UsrData *UsrDat) { /***** Fix birthday *****/ if (UsrDat->Birthday.Year < Gbl.Now.Date.Year-99 || @@ -1290,7 +559,7 @@ void Enr_AskRemoveOldUsrs (void) extern const char *Txt_Eliminate_all_users_who_are_not_enrolled_on_any_courses_PART_2_OF_2; extern const char *Txt_Eliminate; unsigned MonthsWithoutAccess = Usr_DEF_MONTHS_WITHOUT_ACCESS_TO_REMOVE_OLD_USRS; - unsigned i; + unsigned Months; /***** Form to request number of months without clicks *****/ fprintf (Gbl.F.Out,"
"); @@ -1299,14 +568,14 @@ void Enr_AskRemoveOldUsrs (void) The_ClassFormul[Gbl.Prefs.Theme], Txt_Eliminate_all_users_who_are_not_enrolled_on_any_courses_PART_1_OF_2); fprintf (Gbl.F.Out,"" " ", @@ -1380,7 +649,7 @@ void Enr_RemoveOldUsrs (void) UsrDat.UsrCod = Str_ConvertStrCodToLongCod (row[0]); if (Usr_ChkUsrCodAndGetAllUsrDataFromUsrCod (&UsrDat)) // If user's data exist... { - Enr_DeleteUsrFromPlatform (&UsrDat,Cns_QUIET); + Acc_CompletelyEliminateAccount (&UsrDat,Cns_QUIET); NumUsrsEliminated++; } } @@ -1550,7 +819,7 @@ static bool Enr_PutActionsRegRemOneUsr (bool ItsMe) } /***** Eliminate user completely from platform *****/ - if (Enr_CheckIfICanEliminateAccount (ItsMe)) + if (Acc_CheckIfICanEliminateAccount (ItsMe)) { fprintf (Gbl.F.Out,"
  • " ""); - } - /*****************************************************************************/ /*** Put different actions to register/remove users to/from current course ***/ /*****************************************************************************/ @@ -1963,7 +1200,7 @@ void Enr_ReceiveFormUsrsCrs (void) { if (WhatToDo.EliminateUsrs) // Eliminate user completely from the platform { - Enr_DeleteUsrFromPlatform (&UsrDat,Cns_QUIET); // Remove definitely the user from the platform + Acc_CompletelyEliminateAccount (&UsrDat,Cns_QUIET); // Remove definitely the user from the platform NumUsrsEliminated++; } else @@ -2179,7 +1416,7 @@ static void Enr_RegisterUsr (struct UsrData *UsrDat,Rol_Role_t RegRemRole, // User does not exist in database;list of IDs is initialized UsrDat->IDs.List[0].Confirmed = true; // If he/she is a new user ==> his/her ID will be stored as confirmed in database - Enr_CreateNewUsr (UsrDat); + Acc_CreateNewUsr (UsrDat); } /***** Register user in current course in database *****/ @@ -2574,7 +1811,7 @@ void Enr_AskIfRejectSignUp (void) } else // User does not belong to this course { - Role = Enr_GetRequestedRole (Gbl.Usrs.Other.UsrDat.UsrCod); + Role = Rol_GetRequestedRole (Gbl.Usrs.Other.UsrDat.UsrCod); if (Role == Rol_ROLE_STUDENT || Role == Rol_ROLE_TEACHER) { @@ -3088,34 +2325,6 @@ static void Enr_RemoveEnrollmentRequest (long CrsCod,long UsrCod) DB_QueryDELETE (Query,"can not remove a request for enrollment"); } -/*****************************************************************************/ -/************ Get requested role of a user in current course *****************/ -/*****************************************************************************/ - -Rol_Role_t Enr_GetRequestedRole (long UsrCod) - { - char Query[256]; - MYSQL_RES *mysql_res; - MYSQL_ROW row; - Rol_Role_t Role = Rol_ROLE_UNKNOWN; - - /***** Get requested role from database *****/ - sprintf (Query,"SELECT Role FROM crs_usr_requests" - " WHERE CrsCod='%ld' AND UsrCod='%ld'", - Gbl.CurrentCrs.Crs.CrsCod,UsrCod); - if (DB_QuerySELECT (Query,&mysql_res,"can not get requested role")) - { - /***** Get role *****/ - row = mysql_fetch_row (mysql_res); - Role = Rol_ConvertUnsignedStrToRole (row[0]); - } - - /***** Free structure that stores the query result *****/ - DB_FreeMySQLResult (&mysql_res); - - return Role; - } - /*****************************************************************************/ /************** Form to request the user's ID of another user ****************/ /*****************************************************************************/ @@ -3455,7 +2664,7 @@ void Enr_RemUsrFromCrs (void) /******************** Remove of a user from current course *******************/ /*****************************************************************************/ -void Enr_ReqRemOrRemUsrFromCrs (Enr_ReqDelOrDelUsr_t ReqDelOrDelUsr) +static void Enr_ReqRemOrRemUsrFromCrs (Enr_ReqDelOrDelUsr_t ReqDelOrDelUsr) { extern const char *Txt_User_not_found_or_you_do_not_have_permission_; bool ItsMe; @@ -3557,132 +2766,6 @@ static void Enr_ReqRemOrRemAdm (Enr_ReqDelOrDelUsr_t ReqDelOrDelUsr) } } -/*****************************************************************************/ -/********* Request definite removing of a user from the platform *************/ -/*****************************************************************************/ - -void Enr_ReqRemUsrGbl (void) - { - Enr_ReqDelOrDelUsrGbl (Enr_REQUEST_REMOVE_USR); - } - -/*****************************************************************************/ -/************** Definite removing of a user from the platform ****************/ -/*****************************************************************************/ - -void Enr_RemUsrGbl (void) - { - Enr_ReqDelOrDelUsrGbl (Enr_REMOVE_USR); - } - -/*****************************************************************************/ -/**************************** Removing of a user *****************************/ -/*****************************************************************************/ - -void Enr_ReqDelOrDelUsrGbl (Enr_ReqDelOrDelUsr_t ReqDelOrDelUsr) - { - extern const char *Txt_User_not_found_or_you_do_not_have_permission_; - bool ItsMe; - - /***** Get user to be removed *****/ - if (Usr_GetParamOtherUsrCodEncryptedAndGetUsrData ()) - { - ItsMe = (Gbl.Usrs.Me.UsrDat.UsrCod == Gbl.Usrs.Other.UsrDat.UsrCod); - if (Enr_CheckIfICanEliminateAccount (ItsMe)) - switch (ReqDelOrDelUsr) - { - case Enr_REQUEST_REMOVE_USR: // Ask if eliminate completely the user from the platform - Enr_AskIfCompletelyEliminateUsrFromPlatform (ItsMe); - break; - case Enr_REMOVE_USR: // Eliminate completely the user from the platform - if (Pwd_GetConfirmationOnDangerousAction ()) - { - Enr_DeleteUsrFromPlatform (&Gbl.Usrs.Other.UsrDat,Cns_VERBOSE); - - /***** Move unused contents of messages to table of deleted contents of messages *****/ - Msg_MoveUnusedMsgsContentToDeleted (); - } - break; - } - else - Lay_ShowAlert (Lay_WARNING,Txt_User_not_found_or_you_do_not_have_permission_); - } - else - Lay_ShowAlert (Lay_WARNING,Txt_User_not_found_or_you_do_not_have_permission_); - } - -/*****************************************************************************/ -/******************* Ask if really wanted to remove a user *******************/ -/*****************************************************************************/ - -static void Enr_AskIfRemoveUsrFromCrs (struct UsrData *UsrDat,bool ItsMe) - { - extern const char *Txt_Do_you_really_want_to_be_removed_from_the_course_X; - extern const char *Txt_Do_you_really_want_to_remove_the_following_user_from_the_course_X; - extern const char *Txt_Remove_me_from_this_course; - extern const char *Txt_Remove_user_from_this_course; - extern const char *Txt_User_not_found_or_you_do_not_have_permission_; - - if (Usr_CheckIfUsrBelongsToCrs (UsrDat->UsrCod,Gbl.CurrentCrs.Crs.CrsCod)) - { - sprintf (Gbl.Message, - ItsMe ? Txt_Do_you_really_want_to_be_removed_from_the_course_X : - Txt_Do_you_really_want_to_remove_the_following_user_from_the_course_X, - Gbl.CurrentCrs.Crs.FullName); - Lay_ShowAlert (Lay_WARNING,Gbl.Message); - - Rec_ShowCommonRecordUnmodifiable (UsrDat); - - fprintf (Gbl.F.Out,"
    "); - Act_FormStart (ActRemUsrCrs); - Usr_PutParamOtherUsrCodEncrypted (UsrDat->EncryptedUsrCod); - Pwd_AskForConfirmationOnDangerousAction (); - fprintf (Gbl.F.Out,"", - ItsMe ? Txt_Remove_me_from_this_course : - Txt_Remove_user_from_this_course); - fprintf (Gbl.F.Out,"" - "
    "); - } - else - Lay_ShowAlert (Lay_WARNING,Txt_User_not_found_or_you_do_not_have_permission_); - } - -/*****************************************************************************/ -/*********** Ask if really wanted to eliminate completely a user *************/ -/*****************************************************************************/ - -static void Enr_AskIfCompletelyEliminateUsrFromPlatform (bool ItsMe) - { - extern const char *Txt_Do_you_really_want_to_completely_eliminate_your_user_account; - extern const char *Txt_Do_you_really_want_to_completely_eliminate_the_following_user; - extern const char *Txt_Completely_eliminate_me; - extern const char *Txt_Completely_eliminate_user; - extern const char *Txt_User_not_found_or_you_do_not_have_permission_; - - if (Usr_ChkIfUsrCodExists (Gbl.Usrs.Other.UsrDat.UsrCod)) - { - Lay_ShowAlert (Lay_WARNING,ItsMe ? Txt_Do_you_really_want_to_completely_eliminate_your_user_account : - Txt_Do_you_really_want_to_completely_eliminate_the_following_user); - - Rec_ShowCommonRecordUnmodifiable (&Gbl.Usrs.Other.UsrDat); - - Act_FormStart (ActRemUsrGbl); - Usr_PutParamOtherUsrCodEncrypted (Gbl.Usrs.Other.UsrDat.EncryptedUsrCod); - - /* Ask for consent on dangerous actions */ - Pwd_AskForConfirmationOnDangerousAction (); - - fprintf (Gbl.F.Out,"
    " - "" - "
    " - "", - ItsMe ? Txt_Completely_eliminate_me : - Txt_Completely_eliminate_user); - } - else - Lay_ShowAlert (Lay_WARNING,Txt_User_not_found_or_you_do_not_have_permission_); - } - /*****************************************************************************/ /****** Ask if really wanted to add an administrator to current degree *******/ /*****************************************************************************/ @@ -3733,40 +2816,6 @@ static void Enr_ReqAddAdmOfDeg (void) } } -/*****************************************************************************/ -/**** Ask if really wanted to remove an administrator from current degree ****/ -/*****************************************************************************/ - -void Enr_AskIfRemAdmFromDeg (bool ItsMe) - { - extern const char *Txt_Do_you_really_want_to_be_removed_as_an_administrator_of_the_degree_X; - extern const char *Txt_Do_you_really_want_to_remove_the_following_user_as_an_administrator_of_the_degree_X; - extern const char *Txt_Remove_me_as_an_administrator; - extern const char *Txt_Remove_user_as_an_administrator; - - if (Usr_ChkIfUsrCodExists (Gbl.Usrs.Other.UsrDat.UsrCod)) - { - sprintf (Gbl.Message, - ItsMe ? Txt_Do_you_really_want_to_be_removed_as_an_administrator_of_the_degree_X : - Txt_Do_you_really_want_to_remove_the_following_user_as_an_administrator_of_the_degree_X, - Gbl.CurrentDeg.Deg.FullName); - Lay_ShowAlert (Lay_INFO,Gbl.Message); - - Rec_ShowCommonRecordUnmodifiable (&Gbl.Usrs.Other.UsrDat); - - Act_FormStart (ActRemAdm); - Usr_PutParamOtherUsrCodEncrypted (Gbl.Usrs.Other.UsrDat.EncryptedUsrCod); - fprintf (Gbl.F.Out,"
    " - "" - "
    " - "", - ItsMe ? Txt_Remove_me_as_an_administrator : - Txt_Remove_user_as_an_administrator); - } - else - Lay_ShowErrorAndExit ("User doen't exist."); - } - /*****************************************************************************/ /*************** Accept my enrollment in the current course ******************/ /*****************************************************************************/ @@ -3811,7 +2860,7 @@ void Enr_CreatAndShowNewUsrRecordAndRegInCrs (void) /***** Create user *****/ Gbl.Usrs.Other.UsrDat.IDs.List[0].Confirmed = true; // User's ID will be stored as confirmed - Enr_CreateNewUsr (&Gbl.Usrs.Other.UsrDat); + Acc_CreateNewUsr (&Gbl.Usrs.Other.UsrDat); /***** Register user in current course in database *****/ if (Gbl.CurrentCrs.Crs.CrsCod > 0) // Course selected @@ -3930,8 +2979,8 @@ void Enr_ModifAndShowUsrCardAndRegInCrsAndGrps (void) Error = true; break; case Enr_ELIMINATE_ONE_USR_FROM_PLATFORM: - if (Enr_CheckIfICanEliminateAccount (ItsMe)) - Enr_ReqRemUsrGbl (); + if (Acc_CheckIfICanEliminateAccount (ItsMe)) + Acc_ReqRemUsrGbl (); else Error = true; break; @@ -3965,3 +3014,163 @@ void Enr_AcceptUsrInCrs (long UsrCod) Gbl.CurrentCrs.Crs.CrsCod,UsrCod); DB_QueryUPDATE (Query,"can not confirm user's enrollment"); } + +/*****************************************************************************/ +/******************* Ask if really wanted to remove a user *******************/ +/*****************************************************************************/ + +static void Enr_AskIfRemoveUsrFromCrs (struct UsrData *UsrDat,bool ItsMe) + { + extern const char *Txt_Do_you_really_want_to_be_removed_from_the_course_X; + extern const char *Txt_Do_you_really_want_to_remove_the_following_user_from_the_course_X; + extern const char *Txt_Remove_me_from_this_course; + extern const char *Txt_Remove_user_from_this_course; + extern const char *Txt_User_not_found_or_you_do_not_have_permission_; + + if (Usr_CheckIfUsrBelongsToCrs (UsrDat->UsrCod,Gbl.CurrentCrs.Crs.CrsCod)) + { + sprintf (Gbl.Message, + ItsMe ? Txt_Do_you_really_want_to_be_removed_from_the_course_X : + Txt_Do_you_really_want_to_remove_the_following_user_from_the_course_X, + Gbl.CurrentCrs.Crs.FullName); + Lay_ShowAlert (Lay_WARNING,Gbl.Message); + + Rec_ShowCommonRecordUnmodifiable (UsrDat); + + fprintf (Gbl.F.Out,"
    "); + Act_FormStart (ActRemUsrCrs); + Usr_PutParamOtherUsrCodEncrypted (UsrDat->EncryptedUsrCod); + Pwd_AskForConfirmationOnDangerousAction (); + fprintf (Gbl.F.Out,"", + ItsMe ? Txt_Remove_me_from_this_course : + Txt_Remove_user_from_this_course); + fprintf (Gbl.F.Out,"" + "
    "); + } + else + Lay_ShowAlert (Lay_WARNING,Txt_User_not_found_or_you_do_not_have_permission_); + } + +/*****************************************************************************/ +/************************ Remove a user from a course ************************/ +/*****************************************************************************/ + +static void Enr_EffectivelyRemUsrFromCrs (struct UsrData *UsrDat,struct Course *Crs, + Enr_RemoveUsrWorks_t RemoveUsrWorks,Cns_QuietOrVerbose_t QuietOrVerbose) + { + extern const char *Txt_THE_USER_X_has_been_removed_from_the_course_Y; + extern const char *Txt_User_not_found_or_you_do_not_have_permission_; + char Query[1024]; + + if (Usr_CheckIfUsrBelongsToCrs (UsrDat->UsrCod,Crs->CrsCod)) // User belongs to the course + { + /***** Remove user from all the attendance events in course *****/ + Att_RemoveUsrFromCrsAttEvents (UsrDat->UsrCod,Crs->CrsCod); + + /***** Remove user from all the groups in course *****/ + Grp_RemUsrFromAllGrpsInCrs (UsrDat,Crs,QuietOrVerbose); + + /***** Remove user's status about reading of course information *****/ + Inf_RemoveUsrFromCrsInfoRead (UsrDat->UsrCod,Crs->CrsCod); + + /***** Remove works zone of this user in course *****/ + if (RemoveUsrWorks == Enr_REMOVE_WORKS) + Brw_RemoveUsrWorksInCrs (UsrDat,Crs,QuietOrVerbose); + + /***** Remove fields of this user in its course record *****/ + Rec_RemoveFieldsCrsRecordInCrs (UsrDat->UsrCod,Crs,QuietOrVerbose); + + /***** Remove user's clipboard in course *****/ + Brw_RemoveUsrClipboardInCrs (UsrDat->UsrCod,Crs->CrsCod); + + /***** Remove user's expanded folders in course *****/ + Brw_RemoveUsrExpandedFoldersInCrs (UsrDat->UsrCod,Crs->CrsCod); + + /***** Remove exams made by user in course *****/ + Tst_RemoveExamsMadeByUsrInCrs (UsrDat->UsrCod,Crs->CrsCod); + + /***** Set all the notifications for this user in this course as removed, + except notifications about new messages *****/ + Ntf_SetNotifInCrsAsRemoved (Crs->CrsCod,UsrDat->UsrCod); + + /***** Remove user from the table of courses-users *****/ + sprintf (Query,"DELETE FROM crs_usr" + " WHERE CrsCod='%ld' AND UsrCod='%ld'", + Crs->CrsCod,UsrDat->UsrCod); + DB_QueryDELETE (Query,"can not remove a user from a course"); + + if (QuietOrVerbose == Cns_VERBOSE) + { + sprintf (Gbl.Message,Txt_THE_USER_X_has_been_removed_from_the_course_Y, + UsrDat->FullName,Crs->FullName); + Lay_ShowAlert (Lay_SUCCESS,Gbl.Message); + } + } + else // User does not belong to course + if (QuietOrVerbose == Cns_VERBOSE) + Lay_ShowAlert (Lay_WARNING,Txt_User_not_found_or_you_do_not_have_permission_); + } + +/*****************************************************************************/ +/**** Ask if really wanted to remove an administrator from current degree ****/ +/*****************************************************************************/ + +static void Enr_AskIfRemAdmFromDeg (bool ItsMe) + { + extern const char *Txt_Do_you_really_want_to_be_removed_as_an_administrator_of_the_degree_X; + extern const char *Txt_Do_you_really_want_to_remove_the_following_user_as_an_administrator_of_the_degree_X; + extern const char *Txt_Remove_me_as_an_administrator; + extern const char *Txt_Remove_user_as_an_administrator; + + if (Usr_ChkIfUsrCodExists (Gbl.Usrs.Other.UsrDat.UsrCod)) + { + sprintf (Gbl.Message, + ItsMe ? Txt_Do_you_really_want_to_be_removed_as_an_administrator_of_the_degree_X : + Txt_Do_you_really_want_to_remove_the_following_user_as_an_administrator_of_the_degree_X, + Gbl.CurrentDeg.Deg.FullName); + Lay_ShowAlert (Lay_INFO,Gbl.Message); + + Rec_ShowCommonRecordUnmodifiable (&Gbl.Usrs.Other.UsrDat); + + Act_FormStart (ActRemAdm); + Usr_PutParamOtherUsrCodEncrypted (Gbl.Usrs.Other.UsrDat.EncryptedUsrCod); + fprintf (Gbl.F.Out,"
    " + "" + "
    " + "", + ItsMe ? Txt_Remove_me_as_an_administrator : + Txt_Remove_user_as_an_administrator); + } + else + Lay_ShowErrorAndExit ("User doen't exist."); + } + +/*****************************************************************************/ +/************* Remove an administrator from current degree *******************/ +/*****************************************************************************/ + +static void Enr_EffectivelyRemAdmFromDeg (struct UsrData *UsrDat) + { + extern const char *Txt_THE_USER_X_has_been_removed_as_administrator_of_the_degree_Y; + extern const char *Txt_THE_USER_X_is_not_an_administrator_of_the_degree_Y; + char Query[1024]; + + if (Usr_CheckIfUsrIsAdmOfDeg (UsrDat->UsrCod,Gbl.CurrentDeg.Deg.DegCod)) // User is administrator of current degree + { + /***** Remove user from the table of courses-users *****/ + sprintf (Query,"DELETE FROM deg_admin" + " WHERE UsrCod='%ld' AND DegCod='%ld'", + UsrDat->UsrCod,Gbl.CurrentDeg.Deg.DegCod); + DB_QueryDELETE (Query,"can not remove an administrator from a degree"); + + sprintf (Gbl.Message,Txt_THE_USER_X_has_been_removed_as_administrator_of_the_degree_Y, + UsrDat->FullName,Gbl.CurrentDeg.Deg.FullName); + Lay_ShowAlert (Lay_SUCCESS,Gbl.Message); + } + else // User is not an administrator of the current degree + { + sprintf (Gbl.Message,Txt_THE_USER_X_is_not_an_administrator_of_the_degree_Y, + UsrDat->FullName,Gbl.CurrentDeg.Deg.FullName); + Lay_ShowAlert (Lay_ERROR,Gbl.Message); + } + } diff --git a/swad_enrollment.h b/swad_enrollment.h index 73cb5010c..655e6b8a4 100644 --- a/swad_enrollment.h +++ b/swad_enrollment.h @@ -43,18 +43,22 @@ typedef enum Enr_INSERT_NEW_DATA, } Enr_ReplaceInsert_t; -typedef enum - { - Enr_REQUEST_REMOVE_USR, - Enr_REMOVE_USR, - } Enr_ReqDelOrDelUsr_t; - typedef enum { Enr_SET_ACCEPTED_TO_FALSE, Enr_SET_ACCEPTED_TO_TRUE, } Enr_KeepOrSetAccepted_t; +#define Enr_NUM_ACTIONS_REG_REM_ONE_USR 5 +typedef enum + { + Enr_REGISTER_MODIFY_ONE_USR_IN_CRS = 0, + Enr_REGISTER_ONE_DEGREE_ADMIN = 1, + Enr_REMOVE_ONE_USR_FROM_CRS = 2, + Enr_REMOVE_ONE_DEGREE_ADMIN = 3, + Enr_ELIMINATE_ONE_USR_FROM_PLATFORM = 4, + } Enr_RegRemOneUsrAction_t; + /*****************************************************************************/ /****************************** Public prototypes ****************************/ /*****************************************************************************/ @@ -66,30 +70,20 @@ void Enr_RegisterUsrInCurrentCrs (struct UsrData *UsrDat,Rol_Role_t NewRole, Cns_QuietOrVerbose_t QuietOrVerbose, Enr_KeepOrSetAccepted_t KeepOrSetAccepted); -void Enr_RemoveUsrFromTableClicksWithoutPhoto (long UsrCod); - void Enr_WriteFormToReqAnotherUsrID (Act_Action_t NextAction); -void Enr_AfterCreationNewAccount (void); -void Enr_ShowFormAccount (void); -void Enr_ShowFormChangeMyAccount (void); +void Enr_ReqAcceptRegisterInCrs (void); +void Enr_GetNotifEnrollment (char *SummaryStr, + long CrsCod,long UsrCod, + unsigned MaxChars); +void Enr_UpdateUsrData (struct UsrData *UsrDat); +void Enr_FilterUsrDat (struct UsrData *UsrDat); +void Enr_UpdateInstitutionCentreDepartment (void); +void Enr_ShowFormRegRemSeveralUsrs (void); void Enr_AskRemoveOldUsrs (void); void Enr_RemoveOldUsrs (void); -void Enr_ReqAcceptRegisterInCrs (void); - -void Enr_GetNotifEnrollment (char *SummaryStr, - long CrsCod,long UsrCod, - unsigned MaxChars); -void Enr_CreateNewUsr (struct UsrData *UsrDat); -void Enr_UpdateUsrData (struct UsrData *UsrDat); -void Enr_UpdateInstitutionCentreDepartment (void); - -bool Enr_CreateNewAccountAndLogIn (void); - -void Enr_RemoveUsrBriefcase (struct UsrData *UsrDat); -void Enr_ShowFormRegRemSeveralUsrs (void); void Enr_ReceiveFormUsrsCrs (void); void Enr_AskRemAllStdsThisCrs (void); void Enr_RemAllStdsThisCrs (void); @@ -101,7 +95,7 @@ void Enr_GetNotifEnrollmentRequest (char *SummaryStr,char **ContentStr, void Enr_AskIfRejectSignUp (void); void Enr_RejectSignUp (void); void Enr_ShowEnrollmentRequests (void); -Rol_Role_t Enr_GetRequestedRole (long UsrCod); + void Enr_ReqRegRemUsr (void); void Enr_AskIfRegRemAnotherUsr (void); void Enr_AddAdmToDeg (void); @@ -109,12 +103,7 @@ void Enr_AddAdmToDeg (void); void Enr_ReqRemMeFromCrs (void); void Enr_ReqRemUsrFromCrs (void); void Enr_RemUsrFromCrs (void); -void Enr_ReqRemOrRemUsrFromCrs (Enr_ReqDelOrDelUsr_t ReqDelOrDelUsr); -void Enr_ReqRemUsrGbl (void); void Enr_RemAdm (void); -void Enr_RemUsrGbl (void); -void Enr_ReqDelOrDelUsrGbl (Enr_ReqDelOrDelUsr_t ReqDelOrDelUsr); -void Enr_AskIfRemAdmFromDeg (bool ItsMe); void Enr_AcceptRegisterMeInCrs (void); void Enr_CreatAndShowNewUsrRecordAndRegInCrs (void); diff --git a/swad_import.c b/swad_import.c index 2c0f04c37..e17d11966 100644 --- a/swad_import.c +++ b/swad_import.c @@ -32,6 +32,7 @@ #include // For the macro WEXITSTATUS #include // For unlink +#include "swad_account.h" #include "swad_config.h" #include "swad_database.h" #include "swad_enrollment.h" @@ -246,7 +247,7 @@ void Imp_ImportStdsFromAnImpGrp (long ImpGrpCod,struct ListCodGrps *LstGrps,unsi /* Create user */ UsrDat.IDs.List[0].Confirmed = true; // If he/she is a new user ==> his/her ID will be stored as confirmed in database - Enr_CreateNewUsr (&UsrDat); + Acc_CreateNewUsr (&UsrDat); /* Update e-mail */ if (!Mai_UpdateEmailInDB (&UsrDat,UsrDat.Email)) // Email was already registered and confirmed by another user diff --git a/swad_mail.c b/swad_mail.c index 3efb4b86b..d2d685e74 100644 --- a/swad_mail.c +++ b/swad_mail.c @@ -31,8 +31,8 @@ #include // For the macro WEXITSTATUS #include // For access, lstat, getpid, chdir, symlink, unlink +#include "swad_account.h" #include "swad_database.h" -#include "swad_enrollment.h" #include "swad_global.h" #include "swad_mail.h" #include "swad_parameter.h" @@ -1109,7 +1109,7 @@ void Mai_RemoveEmail (void) Lay_ShowAlert (Lay_WARNING,Txt_You_can_not_delete_your_current_email); /***** Show my account again *****/ - Enr_ShowFormChangeMyAccount (); + Acc_ShowFormChangeMyAccount (); } /*****************************************************************************/ @@ -1189,7 +1189,7 @@ void Mai_UpdateEmail (void) } /***** Show my account again *****/ - Enr_ShowFormChangeMyAccount (); + Acc_ShowFormChangeMyAccount (); } /*****************************************************************************/ diff --git a/swad_nickname.c b/swad_nickname.c index 3e604611c..cd15805c0 100644 --- a/swad_nickname.c +++ b/swad_nickname.c @@ -27,8 +27,8 @@ #include // For string functions +#include "swad_account.h" #include "swad_database.h" -#include "swad_enrollment.h" #include "swad_global.h" #include "swad_parameter.h" #include "swad_QR.h" @@ -311,7 +311,7 @@ void Nck_RemoveNick (void) Lay_ShowAlert (Lay_WARNING,Txt_You_can_not_delete_your_current_nickname); /***** Show my account again *****/ - Enr_ShowFormChangeMyAccount (); + Acc_ShowFormChangeMyAccount (); } /*****************************************************************************/ @@ -406,7 +406,7 @@ void Nck_UpdateNick (void) Gbl.Message); /***** Show my account again *****/ - Enr_ShowFormChangeMyAccount (); + Acc_ShowFormChangeMyAccount (); } /*****************************************************************************/ diff --git a/swad_photo.c b/swad_photo.c index 635cac04a..cbeab321a 100644 --- a/swad_photo.c +++ b/swad_photo.c @@ -661,7 +661,7 @@ static void Pho_UpdatePhoto1 (struct UsrData *UsrDat) Pho_UpdatePhotoName (UsrDat); /* Remove the user from the list of users without photo */ - Enr_RemoveUsrFromTableClicksWithoutPhoto (UsrDat->UsrCod); + Pho_RemoveUsrFromTableClicksWithoutPhoto (UsrDat->UsrCod); Gbl.Error = false; } @@ -697,6 +697,67 @@ static void Pho_UpdatePhoto2 (void) Lay_ShowAlert (Lay_SUCCESS,Txt_Photo_has_been_updated); } +/*****************************************************************************/ +/******************* Update number of clicks without photo *******************/ +/*****************************************************************************/ + +unsigned Pho_UpdateMyClicksWithoutPhoto (void) + { + char Query[512]; + MYSQL_RES *mysql_res; + MYSQL_ROW row; + unsigned long NumRows; + unsigned NumClicks; + + /***** Get number of clicks without photo from database *****/ + sprintf (Query,"SELECT NumClicks FROM clicks_without_photo" + " WHERE UsrCod='%ld'", + Gbl.Usrs.Me.UsrDat.UsrCod); + NumRows = DB_QuerySELECT (Query,&mysql_res,"can not get number of clicks without photo"); + + /***** Update the list of clicks without photo *****/ + if (NumRows) // The user exists ==> update number of clicks without photo + { + /* Get current number of clicks */ + row = mysql_fetch_row (mysql_res); + sscanf (row[0],"%u",&NumClicks); + + /* Update number of clicks */ + if (NumClicks <= Pho_MAX_CLICKS_WITHOUT_PHOTO) + { + sprintf (Query,"UPDATE clicks_without_photo SET NumClicks=NumClicks+1 WHERE UsrCod='%ld'", + Gbl.Usrs.Me.UsrDat.UsrCod); + DB_QueryUPDATE (Query,"can not update number of clicks without photo"); + NumClicks++; + } + } + else // The user does not exist ==> add him/her + { + /* Add the user, with one access */ + sprintf (Query,"INSERT INTO clicks_without_photo (UsrCod,NumClicks) VALUES ('%ld',1)", + Gbl.Usrs.Me.UsrDat.UsrCod); + DB_QueryINSERT (Query,"can not create number of clicks without photo"); + NumClicks = 1; + } + + /***** Free structure that stores the query result *****/ + DB_FreeMySQLResult (&mysql_res); + + /***** Return the number of rows of the result *****/ + return NumClicks; + } + +/*****************************************************************************/ +/******** Remove user from table with number of clicks without photo *********/ +/*****************************************************************************/ + +void Pho_RemoveUsrFromTableClicksWithoutPhoto (long UsrCod) + { + char Query[512]; + + sprintf (Query,"DELETE FROM clicks_without_photo WHERE UsrCod='%ld'",UsrCod); + DB_QueryDELETE (Query,"can not remove a user from the list of users without photo"); + } /*****************************************************************************/ /********************* Check if user's photo can be shown ********************/ diff --git a/swad_photo.h b/swad_photo.h index 29c18f177..cc1399e90 100644 --- a/swad_photo.h +++ b/swad_photo.h @@ -27,7 +27,6 @@ /********************************* Headers ***********************************/ /*****************************************************************************/ - /*****************************************************************************/ /************************* Public types and constants ************************/ /*****************************************************************************/ @@ -68,6 +67,8 @@ typedef enum Pho_DEGREE_NAME = 3, } Pho_HowOrderDegrees_t; +#define Pho_MAX_CLICKS_WITHOUT_PHOTO 50 + /*****************************************************************************/ /***************************** Public prototypes *****************************/ /*****************************************************************************/ @@ -89,6 +90,9 @@ void Pho_UpdateMyPhoto2 (void); void Pho_UpdateUsrPhoto1 (void); void Pho_UpdateUsrPhoto2 (void); +unsigned Pho_UpdateMyClicksWithoutPhoto (void); +void Pho_RemoveUsrFromTableClicksWithoutPhoto (long UsrCod); + bool Pho_ShowUsrPhotoIsAllowed (struct UsrData *UsrDat,char *PhotoURL); bool Pho_BuildLinkToPhoto (const struct UsrData *UsrDat,char *PhotoURL,bool HTTPS); bool Pho_CheckIfPrivPhotoExists (long UsrCod,char *PathPrivRelPhoto); diff --git a/swad_record.c b/swad_record.c index 4a49cc5d9..01de160c1 100644 --- a/swad_record.c +++ b/swad_record.c @@ -2339,7 +2339,7 @@ void Rec_ShowCommonRecord (Rec_RecordViewType_t TypeOfView, if (UsrDat->RoleInCurrentCrsDB < Rol_ROLE_STUDENT) // The other user does not belong to current course { /* If there is a request of this user, default role is the requested role */ - if ((DefaultRoleInCurrentCrs = Enr_GetRequestedRole (UsrDat->UsrCod)) == Rol_ROLE_UNKNOWN) + if ((DefaultRoleInCurrentCrs = Rol_GetRequestedRole (UsrDat->UsrCod)) == Rol_ROLE_UNKNOWN) DefaultRoleInCurrentCrs = (UsrDat->Roles & (1 << Rol_ROLE_TEACHER)) ? Rol_ROLE_TEACHER : Rol_ROLE_STUDENT; } diff --git a/swad_role.c b/swad_role.c index c3f894d49..e63d9cbfa 100644 --- a/swad_role.c +++ b/swad_role.c @@ -433,3 +433,31 @@ static void Rol_PutOneRoleRegRemUsrsCrs (Rol_Role_t Role,bool Checked) fprintf (Gbl.F.Out," />%s
  • ", Txt_ROLES_SINGULAR_Abc[Role][Usr_SEX_UNKNOWN]); } + +/*****************************************************************************/ +/************ Get requested role of a user in current course *****************/ +/*****************************************************************************/ + +Rol_Role_t Rol_GetRequestedRole (long UsrCod) + { + char Query[256]; + MYSQL_RES *mysql_res; + MYSQL_ROW row; + Rol_Role_t Role = Rol_ROLE_UNKNOWN; + + /***** Get requested role from database *****/ + sprintf (Query,"SELECT Role FROM crs_usr_requests" + " WHERE CrsCod='%ld' AND UsrCod='%ld'", + Gbl.CurrentCrs.Crs.CrsCod,UsrCod); + if (DB_QuerySELECT (Query,&mysql_res,"can not get requested role")) + { + /***** Get role *****/ + row = mysql_fetch_row (mysql_res); + Role = Rol_ConvertUnsignedStrToRole (row[0]); + } + + /***** Free structure that stores the query result *****/ + DB_FreeMySQLResult (&mysql_res); + + return Role; + } diff --git a/swad_role.h b/swad_role.h index 4a00113e1..5db49e422 100644 --- a/swad_role.h +++ b/swad_role.h @@ -83,4 +83,6 @@ void Rol_GetSelectedRoles (unsigned *Roles); void Rol_PutAllRolesRegRemUsrsCrs (void); +Rol_Role_t Rol_GetRequestedRole (long UsrCod); + #endif diff --git a/swad_user.c b/swad_user.c index 4faa7a441..4ab0b6fd9 100644 --- a/swad_user.c +++ b/swad_user.c @@ -34,6 +34,7 @@ #include // For the macro WEXITSTATUS #include // For access, lstat, getpid, chdir, symlink, unlink +#include "swad_account.h" #include "swad_announcement.h" #include "swad_config.h" #include "swad_connected.h" @@ -185,12 +186,12 @@ void Usr_InformAboutNumClicksBeforePhoto (void) if (Gbl.Usrs.Me.NumAccWithoutPhoto) { - if (Gbl.Usrs.Me.NumAccWithoutPhoto >= Usr_MAX_CLICKS_WITHOUT_PHOTO) + if (Gbl.Usrs.Me.NumAccWithoutPhoto >= Pho_MAX_CLICKS_WITHOUT_PHOTO) Lay_ShowAlert (Lay_WARNING,Txt_You_must_send_your_photo_because_); else if (Act_Actions[Gbl.CurrentAct].BrowserWindow == Act_MAIN_WINDOW) { sprintf (Message,Txt_You_can_only_perform_X_further_actions_, - Usr_MAX_CLICKS_WITHOUT_PHOTO-Gbl.Usrs.Me.NumAccWithoutPhoto); + Pho_MAX_CLICKS_WITHOUT_PHOTO-Gbl.Usrs.Me.NumAccWithoutPhoto); Lay_ShowAlert (Lay_WARNING,Message); fprintf (Gbl.F.Out,"
    "); @@ -1666,7 +1667,7 @@ void Usr_ChkUsrAndGetUsrData (void) if (Gbl.CurrentAct == ActCreUsrAcc) { /***** Create new account and login *****/ - if (Enr_CreateNewAccountAndLogIn ()) // User logged in + if (Acc_CreateNewAccountAndLogIn ()) // User logged in { Gbl.Usrs.Me.Logged = true; Usr_SetUsrRoleAndPrefs (); @@ -2319,56 +2320,6 @@ void Usr_ShowFormsRoleAndLogout (void) } } -/*****************************************************************************/ -/******************* Update number of clicks without photo *******************/ -/*****************************************************************************/ - -unsigned Usr_UpdateMyClicksWithoutPhoto (void) - { - char Query[512]; - MYSQL_RES *mysql_res; - MYSQL_ROW row; - unsigned long NumRows; - unsigned NumClicks; - - /***** Get number of clicks without photo from database *****/ - sprintf (Query,"SELECT NumClicks FROM clicks_without_photo" - " WHERE UsrCod='%ld'", - Gbl.Usrs.Me.UsrDat.UsrCod); - NumRows = DB_QuerySELECT (Query,&mysql_res,"can not get number of clicks without photo"); - - /***** Update the list of clicks without photo *****/ - if (NumRows) // The user exists ==> update number of clicks without photo - { - /* Get current number of clicks */ - row = mysql_fetch_row (mysql_res); - sscanf (row[0],"%u",&NumClicks); - - /* Update number of clicks */ - if (NumClicks <= Usr_MAX_CLICKS_WITHOUT_PHOTO) - { - sprintf (Query,"UPDATE clicks_without_photo SET NumClicks=NumClicks+1 WHERE UsrCod='%ld'", - Gbl.Usrs.Me.UsrDat.UsrCod); - DB_QueryUPDATE (Query,"can not update number of clicks without photo"); - NumClicks++; - } - } - else // The user does not exist ==> add him/her - { - /* Add the user, with one access */ - sprintf (Query,"INSERT INTO clicks_without_photo (UsrCod,NumClicks) VALUES ('%ld',1)", - Gbl.Usrs.Me.UsrDat.UsrCod); - DB_QueryINSERT (Query,"can not create number of clicks without photo"); - NumClicks = 1; - } - - /***** Free structure that stores the query result *****/ - DB_FreeMySQLResult (&mysql_res); - - /***** Return the number of rows of the result *****/ - return NumClicks; - } - /*****************************************************************************/ /******* Check a user's code and get all user's data from user's code ********/ /*****************************************************************************/ diff --git a/swad_user.h b/swad_user.h index 4b0ee0e88..37af4fd16 100644 --- a/swad_user.h +++ b/swad_user.h @@ -47,8 +47,6 @@ /****************************** Public constants *****************************/ /*****************************************************************************/ -#define Usr_MAX_CLICKS_WITHOUT_PHOTO 50 - #define Usr_MIN_MONTHS_WITHOUT_ACCESS_TO_REMOVE_OLD_USRS 6 #define Usr_DEF_MONTHS_WITHOUT_ACCESS_TO_REMOVE_OLD_USRS 12 #define Usr_MAX_MONTHS_WITHOUT_ACCESS_TO_REMOVE_OLD_USRS 60 @@ -245,8 +243,6 @@ void Usr_ChkUsrAndGetUsrData (void); void Usr_WarningWhenDegreeTypeDoesntAllowDirectLogin (void); void Usr_ShowFormsRoleAndLogout (void); -unsigned Usr_UpdateMyClicksWithoutPhoto (void); - bool Usr_ChkUsrCodAndGetAllUsrDataFromUsrCod (struct UsrData *UsrDat); bool Usr_GetIfUserHasAcceptedEnrollmentInCurrentCrs (long UsrCod); void Usr_UpdateMyLastData (void);