mirror of
https://github.com/acanas/swad-core.git
synced 2024-06-16 13:44:06 +02:00
Version 15.10.2
This commit is contained in:
parent
d7602b1ce2
commit
e903454169
|
@ -10779,3 +10779,5 @@ INSERT INTO actions (ActCod,Language,Obsolete,Txt) VALUES ('1468','es','N','Camb
|
|||
INSERT INTO actions (ActCod,Language,Obsolete,Txt) VALUES ('1469','es','N','Cambiar contraseña profesor');
|
||||
|
||||
|
||||
|
||||
SELECT usr_nicknames.UsrCod FROM usr_nicknames,usr_data WHERE usr_nicknames.Nickname='JFERNAND' AND usr_nicknames.UsrCod=usr_data.UsrCod;
|
||||
|
|
19
swad_ID.c
19
swad_ID.c
|
@ -295,22 +295,35 @@ void ID_GetParamOtherUsrIDPlain (void)
|
|||
// Wrapper function to avoid passing extra parameters
|
||||
bool ID_CheckIfUsrIDIsValid (const char *UsrID)
|
||||
{
|
||||
return ID_CheckIfUsrIDIsValidUsingMinDigits (UsrID,ID_MIN_DIGITS_USR_ID);
|
||||
if (UsrID)
|
||||
if (UsrID[0])
|
||||
return ID_CheckIfUsrIDIsValidUsingMinDigits (UsrID,ID_MIN_DIGITS_USR_ID);
|
||||
|
||||
return false;
|
||||
}
|
||||
|
||||
// Wrapper function to avoid passing extra parameters
|
||||
bool ID_CheckIfUsrIDSeemsAValidID (const char *UsrID)
|
||||
{
|
||||
return ID_CheckIfUsrIDIsValidUsingMinDigits (UsrID,ID_MIN_DIGITS_AUTOMATIC_DETECT_USR_ID);
|
||||
if (UsrID)
|
||||
if (UsrID[0])
|
||||
return ID_CheckIfUsrIDIsValidUsingMinDigits (UsrID,ID_MIN_DIGITS_AUTOMATIC_DETECT_USR_ID);
|
||||
|
||||
return false;
|
||||
}
|
||||
|
||||
static bool ID_CheckIfUsrIDIsValidUsingMinDigits (const char *UsrID,unsigned MinDigits)
|
||||
{
|
||||
const char *Ptr;
|
||||
unsigned NumDigits = 0;
|
||||
unsigned Length = strlen (UsrID);
|
||||
unsigned Length;
|
||||
|
||||
/***** Check length *****/
|
||||
if (!UsrID)
|
||||
return false;
|
||||
if (!UsrID[0])
|
||||
return false;
|
||||
Length = strlen (UsrID);
|
||||
if (Length < ID_MIN_LENGTH_USR_ID ||
|
||||
Length > ID_MAX_LENGTH_USR_ID)
|
||||
return false; // 1. Must be ID_MIN_LENGTH_USR_ID <= characters <= ID_MAX_LENGTH_USR_ID
|
||||
|
|
|
@ -98,13 +98,16 @@
|
|||
/****************************** Public constants *****************************/
|
||||
/*****************************************************************************/
|
||||
|
||||
#define Log_PLATFORM_VERSION "SWAD 15.10.1 (2015/10/06)"
|
||||
#define Log_PLATFORM_VERSION "SWAD 15.10.2 (2015/10/06)"
|
||||
|
||||
// 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 sql/swad*.sql | tail -1
|
||||
/*
|
||||
TODO: If photo zoom is out of the screen at left, put on right
|
||||
|
||||
Version 15.10.2: Oct 07, 2015 Fixed bug in nicknames, reported by Javier Fdez. Baldomero.
|
||||
New MIME type, suggested by Javier Fdez. Baldomero.
|
||||
Some code refactoring related to nicknames. (185639 lines)
|
||||
Version 15.10.1: Oct 06, 2015 New row in contextual help to upload photo. (185581 lines)
|
||||
Version 15.10: Oct 06, 2015 New module swad_help for contextual help to enhance usability. (185561 lines)
|
||||
1 change necessary in Makefile:
|
||||
|
|
|
@ -1281,6 +1281,7 @@ const char *Brw_MIMETypesAllowed[] =
|
|||
"text/plain", // plain text C, cc, h, txt. BAS
|
||||
"text/richtext", // RTF
|
||||
"text/xml", //
|
||||
"text/x-c", // Source code in C
|
||||
"text/x-chdr", // Source code in C
|
||||
"text/x-csrc", // Source code in C
|
||||
"text/x-c++src", // Source code in C++
|
||||
|
|
46
swad_mail.c
46
swad_mail.c
|
@ -872,29 +872,33 @@ long Mai_GetUsrCodFromEmail (const char *Email)
|
|||
unsigned NumUsrs;
|
||||
long UsrCod = -1L;
|
||||
|
||||
/***** Get user's code from database *****/
|
||||
/* Check if user code from table usr_emails is also in table usr_data */
|
||||
sprintf (Query,"SELECT usr_emails.UsrCod FROM usr_emails,usr_data"
|
||||
" WHERE usr_emails.E_mail='%s'"
|
||||
" AND usr_emails.UsrCod=usr_data.UsrCod",
|
||||
Email);
|
||||
NumUsrs = (unsigned) DB_QuerySELECT (Query,&mysql_res,"can not get user's code");
|
||||
if (NumUsrs == 0)
|
||||
/* User not found for this e-mail ==> set user's code to void */
|
||||
UsrCod = -1L;
|
||||
else if (NumUsrs == 1) // One user found
|
||||
{
|
||||
/* Get row */
|
||||
row = mysql_fetch_row (mysql_res);
|
||||
if (Email)
|
||||
if (Email[0])
|
||||
{
|
||||
/***** Get user's code from database *****/
|
||||
/* Check if user code from table usr_emails is also in table usr_data */
|
||||
sprintf (Query,"SELECT usr_emails.UsrCod FROM usr_emails,usr_data"
|
||||
" WHERE usr_emails.E_mail='%s'"
|
||||
" AND usr_emails.UsrCod=usr_data.UsrCod",
|
||||
Email);
|
||||
NumUsrs = (unsigned) DB_QuerySELECT (Query,&mysql_res,"can not get user's code");
|
||||
if (NumUsrs == 0)
|
||||
/* User not found for this e-mail ==> set user's code to void */
|
||||
UsrCod = -1L;
|
||||
else if (NumUsrs == 1) // One user found
|
||||
{
|
||||
/* Get row */
|
||||
row = mysql_fetch_row (mysql_res);
|
||||
|
||||
/* Get user's code */
|
||||
UsrCod = Str_ConvertStrCodToLongCod (row[0]);
|
||||
}
|
||||
else // NumRows > 1 ==> impossible, an e-mail can not be reapeated
|
||||
Lay_ShowErrorAndExit ("Internal error: e-mail is repeated in database.");
|
||||
/* Get user's code */
|
||||
UsrCod = Str_ConvertStrCodToLongCod (row[0]);
|
||||
}
|
||||
else // NumRows > 1 ==> impossible, an e-mail can not be reapeated
|
||||
Lay_ShowErrorAndExit ("Internal error: e-mail is repeated in database.");
|
||||
|
||||
/***** Free structure that stores the query result *****/
|
||||
DB_FreeMySQLResult (&mysql_res);
|
||||
/***** Free structure that stores the query result *****/
|
||||
DB_FreeMySQLResult (&mysql_res);
|
||||
}
|
||||
|
||||
return UsrCod;
|
||||
}
|
||||
|
|
|
@ -146,28 +146,32 @@ long Nck_GetUsrCodFromNickname (const char *Nickname)
|
|||
MYSQL_ROW row;
|
||||
long UsrCod = -1L;
|
||||
|
||||
/***** Make a copy without possible starting arrobas *****/
|
||||
strncpy (NicknameWithoutArroba,Nickname,Nck_MAX_BYTES_NICKNAME_WITH_ARROBA);
|
||||
NicknameWithoutArroba[Nck_MAX_BYTES_NICKNAME_WITH_ARROBA] = '\0';
|
||||
Str_RemoveLeadingArrobas (NicknameWithoutArroba);
|
||||
if (Nickname)
|
||||
if (Nickname[0])
|
||||
{
|
||||
/***** Make a copy without possible starting arrobas *****/
|
||||
strncpy (NicknameWithoutArroba,Nickname,Nck_MAX_BYTES_NICKNAME_WITH_ARROBA);
|
||||
NicknameWithoutArroba[Nck_MAX_BYTES_NICKNAME_WITH_ARROBA] = '\0';
|
||||
Str_RemoveLeadingArrobas (NicknameWithoutArroba);
|
||||
|
||||
/***** Get user's code from database *****/
|
||||
/* Check if user code from table usr_nicknames is also in table usr_data */
|
||||
sprintf (Query,"SELECT usr_nicknames.UsrCod FROM usr_nicknames,usr_data"
|
||||
" WHERE usr_nicknames.Nickname='%s'"
|
||||
" AND usr_nicknames.UsrCod=usr_data.UsrCod",
|
||||
NicknameWithoutArroba);
|
||||
if (DB_QuerySELECT (Query,&mysql_res,"can not get user's code"))
|
||||
{
|
||||
/* Get row */
|
||||
row = mysql_fetch_row (mysql_res);
|
||||
/***** Get user's code from database *****/
|
||||
/* Check if user code from table usr_nicknames is also in table usr_data */
|
||||
sprintf (Query,"SELECT usr_nicknames.UsrCod FROM usr_nicknames,usr_data"
|
||||
" WHERE usr_nicknames.Nickname='%s'"
|
||||
" AND usr_nicknames.UsrCod=usr_data.UsrCod",
|
||||
NicknameWithoutArroba);
|
||||
if (DB_QuerySELECT (Query,&mysql_res,"can not get user's code"))
|
||||
{
|
||||
/* Get row */
|
||||
row = mysql_fetch_row (mysql_res);
|
||||
|
||||
/* Get user's code */
|
||||
UsrCod = Str_ConvertStrCodToLongCod (row[0]);
|
||||
}
|
||||
/* Get user's code */
|
||||
UsrCod = Str_ConvertStrCodToLongCod (row[0]);
|
||||
}
|
||||
|
||||
/***** Free structure that stores the query result *****/
|
||||
DB_FreeMySQLResult (&mysql_res);
|
||||
/***** Free structure that stores the query result *****/
|
||||
DB_FreeMySQLResult (&mysql_res);
|
||||
}
|
||||
|
||||
return UsrCod;
|
||||
}
|
||||
|
@ -347,7 +351,6 @@ void Nck_UpdateNick (void)
|
|||
|
||||
/***** 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 *****/
|
||||
|
|
|
@ -327,12 +327,13 @@ void Par_GetMainParameters (void)
|
|||
|
||||
/***** Get user's nickname, if exists
|
||||
(this nickname is used to go to a user's profile, not to get the logged user) *****/
|
||||
Par_GetParToText ("usr",Nickname,Nck_MAX_BYTES_NICKNAME_WITH_ARROBA);
|
||||
if ((OtherUsrCod = Nck_GetUsrCodFromNickname (Nickname)) > 0)
|
||||
{
|
||||
Gbl.Usrs.Other.UsrDat.UsrCod = OtherUsrCod;
|
||||
Gbl.CurrentAct = ActSeePubPrf;
|
||||
}
|
||||
if (Par_GetParToText ("usr",Nickname,Nck_MAX_BYTES_NICKNAME_WITH_ARROBA))
|
||||
if (Nickname[0])
|
||||
if ((OtherUsrCod = Nck_GetUsrCodFromNickname (Nickname)) > 0)
|
||||
{
|
||||
Gbl.Usrs.Other.UsrDat.UsrCod = OtherUsrCod;
|
||||
Gbl.CurrentAct = ActSeePubPrf;
|
||||
}
|
||||
|
||||
/***** Get tab to activate *****/
|
||||
Gbl.CurrentTab = TabUnk;
|
||||
|
|
|
@ -1352,27 +1352,43 @@ void Str_RemoveTrailingSpacesHTML (char *Str)
|
|||
}
|
||||
|
||||
/*****************************************************************************/
|
||||
/********** Remove the leading zeros ('0', not '\0') of a string *************/
|
||||
/********* Remove the leading zeros ('0', not '\0') from a string ************/
|
||||
/*****************************************************************************/
|
||||
|
||||
void Str_RemoveLeadingZeros (char *Str)
|
||||
{
|
||||
size_t NumLeadingZeros = strspn (Str,"0");
|
||||
size_t NumLeadingZeros;
|
||||
|
||||
if (NumLeadingZeros)
|
||||
strcpy (Str,&Str[NumLeadingZeros]);
|
||||
if (Str)
|
||||
if (Str[0])
|
||||
{
|
||||
NumLeadingZeros = strspn (Str,"0");
|
||||
if (NumLeadingZeros)
|
||||
// Do not use strcpy / memcpy because the strings overlap
|
||||
memmove (Str,&Str[NumLeadingZeros],
|
||||
strlen (Str) - NumLeadingZeros + 1);
|
||||
}
|
||||
}
|
||||
|
||||
/*****************************************************************************/
|
||||
/***************** Delete @'s at the start of a string ***********************/
|
||||
/*****************************************************************************/
|
||||
|
||||
#include "swad_database.h"
|
||||
|
||||
void Str_RemoveLeadingArrobas (char *Str)
|
||||
{
|
||||
size_t NumLeadingZeros = strspn (Str,"@");
|
||||
size_t NumLeadingArrobas;
|
||||
|
||||
if (NumLeadingZeros)
|
||||
strcpy (Str,&Str[NumLeadingZeros]);
|
||||
if (Str)
|
||||
if (Str[0])
|
||||
{
|
||||
NumLeadingArrobas = strspn (Str,"@");
|
||||
if (NumLeadingArrobas)
|
||||
// Do not use strcpy / memcpy because the strings overlap
|
||||
memmove (Str,&Str[NumLeadingArrobas],
|
||||
strlen (Str) - NumLeadingArrobas + 1);
|
||||
}
|
||||
}
|
||||
|
||||
/*****************************************************************************/
|
||||
|
|
97
swad_user.c
97
swad_user.c
|
@ -1711,7 +1711,7 @@ static void Usr_GetParamOtherUsrIDNickOrEMail (void)
|
|||
Par_GetParToText ("OtherUsrIDNickOrEMail",Gbl.Usrs.Other.UsrDat.UsrIDNickOrEmail,Usr_MAX_BYTES_USR_LOGIN);
|
||||
|
||||
// If it's a user's ID (if does not contain '@')
|
||||
if (strchr (Gbl.Usrs.Other.UsrDat.UsrIDNickOrEmail,(int) '@') != NULL) // '@' found
|
||||
if (strchr (Gbl.Usrs.Other.UsrDat.UsrIDNickOrEmail,(int) '@') != NULL) // '@' not found
|
||||
{
|
||||
// Users' IDs are always stored internally in capitals and without leading zeros
|
||||
Str_RemoveLeadingZeros (Gbl.Usrs.Other.UsrDat.UsrIDNickOrEmail);
|
||||
|
@ -1728,6 +1728,7 @@ static void Usr_GetParamOtherUsrIDNickOrEMail (void)
|
|||
unsigned Usr_GetParamOtherUsrIDNickOrEMailAndGetUsrCods (struct ListUsrCods *ListUsrCods)
|
||||
{
|
||||
extern const char *Txt_The_ID_nickname_or_email_X_is_not_valid;
|
||||
bool Wrong = false;
|
||||
|
||||
/***** Reset default list of users' codes *****/
|
||||
ListUsrCods->NumUsrs = 0;
|
||||
|
@ -1737,50 +1738,58 @@ unsigned Usr_GetParamOtherUsrIDNickOrEMailAndGetUsrCods (struct ListUsrCods *Lis
|
|||
Usr_GetParamOtherUsrIDNickOrEMail ();
|
||||
|
||||
/***** Check if it's an ID, a nickname or an e-mail address *****/
|
||||
if (Nck_CheckIfNickWithArrobaIsValid (Gbl.Usrs.Other.UsrDat.UsrIDNickOrEmail)) // 1: It's a nickname
|
||||
if (Gbl.Usrs.Other.UsrDat.UsrIDNickOrEmail[0])
|
||||
{
|
||||
if ((Gbl.Usrs.Other.UsrDat.UsrCod = Nck_GetUsrCodFromNickname (Gbl.Usrs.Other.UsrDat.UsrIDNickOrEmail)) > 0)
|
||||
if (Nck_CheckIfNickWithArrobaIsValid (Gbl.Usrs.Other.UsrDat.UsrIDNickOrEmail)) // 1: It's a nickname
|
||||
{
|
||||
ListUsrCods->NumUsrs = 1; // One user found
|
||||
Usr_AllocateListUsrCods (ListUsrCods);
|
||||
ListUsrCods->Lst[0] = Gbl.Usrs.Other.UsrDat.UsrCod;
|
||||
}
|
||||
}
|
||||
else if (Mai_CheckIfEmailIsValid (Gbl.Usrs.Other.UsrDat.UsrIDNickOrEmail)) // 2: It's an e-mail
|
||||
{
|
||||
if ((Gbl.Usrs.Other.UsrDat.UsrCod = Mai_GetUsrCodFromEmail (Gbl.Usrs.Other.UsrDat.UsrIDNickOrEmail)) > 0)
|
||||
{
|
||||
ListUsrCods->NumUsrs = 1; // One user found
|
||||
Usr_AllocateListUsrCods (ListUsrCods);
|
||||
ListUsrCods->Lst[0] = Gbl.Usrs.Other.UsrDat.UsrCod;
|
||||
}
|
||||
}
|
||||
else // 3: It's not a nickname nor e-mail
|
||||
{
|
||||
// Users' IDs are always stored internally in capitals and without leading zeros
|
||||
Str_RemoveLeadingZeros (Gbl.Usrs.Other.UsrDat.UsrIDNickOrEmail);
|
||||
Str_ConvertToUpperText (Gbl.Usrs.Other.UsrDat.UsrIDNickOrEmail);
|
||||
if (ID_CheckIfUsrIDIsValid (Gbl.Usrs.Other.UsrDat.UsrIDNickOrEmail))
|
||||
{
|
||||
if (strlen (Gbl.Usrs.Other.UsrDat.UsrIDNickOrEmail) <= ID_MAX_LENGTH_USR_ID)
|
||||
if ((Gbl.Usrs.Other.UsrDat.UsrCod = Nck_GetUsrCodFromNickname (Gbl.Usrs.Other.UsrDat.UsrIDNickOrEmail)) > 0)
|
||||
{
|
||||
/* Allocate space for the list */
|
||||
ID_ReallocateListIDs (&Gbl.Usrs.Other.UsrDat,1);
|
||||
|
||||
strncpy (Gbl.Usrs.Other.UsrDat.IDs.List[0].ID,Gbl.Usrs.Other.UsrDat.UsrIDNickOrEmail,ID_MAX_LENGTH_USR_ID);
|
||||
Gbl.Usrs.Other.UsrDat.IDs.List[0].ID[ID_MAX_LENGTH_USR_ID] = '\0';
|
||||
|
||||
/* Check if user's ID exists in database */
|
||||
ID_GetListUsrCodsFromUsrID (&Gbl.Usrs.Other.UsrDat,NULL,ListUsrCods,false);
|
||||
ListUsrCods->NumUsrs = 1; // One user found
|
||||
Usr_AllocateListUsrCods (ListUsrCods);
|
||||
ListUsrCods->Lst[0] = Gbl.Usrs.Other.UsrDat.UsrCod;
|
||||
}
|
||||
}
|
||||
else
|
||||
else if (Mai_CheckIfEmailIsValid (Gbl.Usrs.Other.UsrDat.UsrIDNickOrEmail)) // 2: It's an e-mail
|
||||
{
|
||||
/***** String is not a valid user's nickname, e-mail or ID *****/
|
||||
sprintf (Gbl.Message,Txt_The_ID_nickname_or_email_X_is_not_valid,
|
||||
Gbl.Usrs.Other.UsrDat.UsrIDNickOrEmail);
|
||||
Lay_ShowAlert (Lay_WARNING,Gbl.Message);
|
||||
if ((Gbl.Usrs.Other.UsrDat.UsrCod = Mai_GetUsrCodFromEmail (Gbl.Usrs.Other.UsrDat.UsrIDNickOrEmail)) > 0)
|
||||
{
|
||||
ListUsrCods->NumUsrs = 1; // One user found
|
||||
Usr_AllocateListUsrCods (ListUsrCods);
|
||||
ListUsrCods->Lst[0] = Gbl.Usrs.Other.UsrDat.UsrCod;
|
||||
}
|
||||
}
|
||||
else // 3: It's not a nickname nor e-mail
|
||||
{
|
||||
// Users' IDs are always stored internally in capitals and without leading zeros
|
||||
Str_RemoveLeadingZeros (Gbl.Usrs.Other.UsrDat.UsrIDNickOrEmail);
|
||||
Str_ConvertToUpperText (Gbl.Usrs.Other.UsrDat.UsrIDNickOrEmail);
|
||||
if (ID_CheckIfUsrIDIsValid (Gbl.Usrs.Other.UsrDat.UsrIDNickOrEmail))
|
||||
{
|
||||
if (strlen (Gbl.Usrs.Other.UsrDat.UsrIDNickOrEmail) <= ID_MAX_LENGTH_USR_ID)
|
||||
{
|
||||
/* Allocate space for the list */
|
||||
ID_ReallocateListIDs (&Gbl.Usrs.Other.UsrDat,1);
|
||||
|
||||
strncpy (Gbl.Usrs.Other.UsrDat.IDs.List[0].ID,Gbl.Usrs.Other.UsrDat.UsrIDNickOrEmail,ID_MAX_LENGTH_USR_ID);
|
||||
Gbl.Usrs.Other.UsrDat.IDs.List[0].ID[ID_MAX_LENGTH_USR_ID] = '\0';
|
||||
|
||||
/* Check if user's ID exists in database */
|
||||
ID_GetListUsrCodsFromUsrID (&Gbl.Usrs.Other.UsrDat,NULL,ListUsrCods,false);
|
||||
}
|
||||
}
|
||||
else // Not a valid user's nickname, e-mail or ID
|
||||
Wrong = true;
|
||||
}
|
||||
}
|
||||
else // Empty string
|
||||
Wrong = true;
|
||||
|
||||
if (Wrong)
|
||||
{
|
||||
/***** String is not a valid user's nickname, e-mail or ID *****/
|
||||
sprintf (Gbl.Message,Txt_The_ID_nickname_or_email_X_is_not_valid,
|
||||
Gbl.Usrs.Other.UsrDat.UsrIDNickOrEmail);
|
||||
Lay_ShowAlert (Lay_WARNING,Gbl.Message);
|
||||
}
|
||||
|
||||
return ListUsrCods->NumUsrs;
|
||||
|
@ -1996,6 +2005,18 @@ static bool Usr_ChkUsrAndGetUsrDataFromDirectLogin (void)
|
|||
struct ListUsrCods ListUsrCods;
|
||||
bool PasswordCorrect = false;
|
||||
|
||||
/***** Check if user typed anything *****/
|
||||
if (!Gbl.Usrs.Me.UsrIdLogin)
|
||||
{
|
||||
Lay_ShowAlert (Lay_WARNING,Txt_The_user_does_not_exist_or_password_is_incorrect);
|
||||
return false;
|
||||
}
|
||||
if (!Gbl.Usrs.Me.UsrIdLogin[0])
|
||||
{
|
||||
Lay_ShowAlert (Lay_WARNING,Txt_The_user_does_not_exist_or_password_is_incorrect);
|
||||
return false;
|
||||
}
|
||||
|
||||
/***** Check if user has typed his user's ID, his nickname or his e-mail address *****/
|
||||
if (Nck_CheckIfNickWithArrobaIsValid (Gbl.Usrs.Me.UsrIdLogin)) // 1: It's a nickname
|
||||
{
|
||||
|
|
Loading…
Reference in New Issue
Block a user