diff --git a/swad_action.c b/swad_action.c index 54e3db4b..180ebeff 100644 --- a/swad_action.c +++ b/swad_action.c @@ -1575,6 +1575,8 @@ Profile: 1332. ActChgMyTT1stDay Change first day of week and show timetable of the course */ +#define Act_DEFAULT_ACTION_AFTER_LOGIN ActSeeSocTmlGbl + /* struct Act_Actions { @@ -5385,10 +5387,10 @@ void Act_AdjustCurrentAction (void) /***** Adjustment 10: -------------- - Just after login with all checks OK ==> go to timeline *****/ + Just after login with all checks OK ==> go to default action *****/ if (JustAfterLogin) { - Gbl.Action.Act = ActSeeSocTmlGbl; + Gbl.Action.Act = Act_DEFAULT_ACTION_AFTER_LOGIN; Tab_SetCurrentTab (); } } diff --git a/swad_changelog.h b/swad_changelog.h index 626aad2c..be435f87 100644 --- a/swad_changelog.h +++ b/swad_changelog.h @@ -464,10 +464,11 @@ En OpenSWAD: ps2pdf source.ps destination.pdf */ -#define Log_PLATFORM_VERSION "SWAD 18.94 (2019-04-03)" +#define Log_PLATFORM_VERSION "SWAD 18.94.1 (2019-04-03)" #define CSS_FILE "swad18.92.css" #define JS_FILE "swad18.92.js" /* + Version 18.94.1: Apr 03, 2019 Remember last action and role after login only if last access is recent. (241526 lines) Version 18.94: Apr 03, 2019 Code refactoring related to hierarchy. (241513 lines) Version 18.93: Apr 01, 2019 When a user logs in, hierarchy, action and role are got from database. (241533 lines) 5 changes necessary in database: diff --git a/swad_config.h b/swad_config.h index 44cbd113..3ec451f3 100644 --- a/swad_config.h +++ b/swad_config.h @@ -533,6 +533,8 @@ #define Cfg_MIN_TIME_TO_RECOMPUTE_AVG_PHOTO ((time_t)( 12UL * 60UL * 60UL)) // After these seconds, users can recompute the average photos of a degree +#define Cfg_MAX_TIME_TO_REMEMBER_LAST_ACTION_ON_LOGIN ((time_t)( 2UL * 60UL * 60UL)) // On login, if interval since last action is less than this time, remember last action and role + /*****************************************************************************/ /***************************** Public prototypes *****************************/ /*****************************************************************************/ diff --git a/swad_user.c b/swad_user.c index b4f97d2e..77fc69bc 100644 --- a/swad_user.c +++ b/swad_user.c @@ -369,6 +369,7 @@ void Usr_ResetMyLastData (void) Gbl.Usrs.Me.UsrLast.LastHie.Cod = -1L; Gbl.Usrs.Me.UsrLast.LastAct = ActUnk; Gbl.Usrs.Me.UsrLast.LastRole = Rol_UNK; + Gbl.Usrs.Me.UsrLast.LastTime = 0; Gbl.Usrs.Me.UsrLast.LastAccNotif = 0; } @@ -766,7 +767,8 @@ static void Usr_GetMyLastData (void) "LastCod," // row[2] "LastAct," // row[3] "LastRole," // row[4] - "UNIX_TIMESTAMP(LastAccNotif)" // row[5] + "UNIX_TIMESTAMP(LastTime)," // row[5] + "UNIX_TIMESTAMP(LastAccNotif)" // row[6] " FROM usr_last WHERE UsrCod=%ld", Gbl.Usrs.Me.UsrDat.UsrCod); if (NumRows == 0) @@ -822,10 +824,15 @@ static void Usr_GetMyLastData (void) /* Get last role (row[4]) */ Gbl.Usrs.Me.UsrLast.LastRole = Rol_ConvertUnsignedStrToRole (row[4]); - /* Get last access to notifications (row[5]) */ - Gbl.Usrs.Me.UsrLast.LastAccNotif = 0L; + /* Get last access to platform (row[5]) */ + Gbl.Usrs.Me.UsrLast.LastTime = 0L; if (row[5]) - sscanf (row[5],"%ld",&(Gbl.Usrs.Me.UsrLast.LastAccNotif)); + sscanf (row[5],"%ld",&(Gbl.Usrs.Me.UsrLast.LastTime)); + + /* Get last access to notifications (row[6]) */ + Gbl.Usrs.Me.UsrLast.LastAccNotif = 0L; + if (row[6]) + sscanf (row[6],"%ld",&(Gbl.Usrs.Me.UsrLast.LastAccNotif)); /***** Free structure that stores the query result *****/ DB_FreeMySQLResult (&mysql_res); @@ -3404,18 +3411,21 @@ static void Usr_SetMyPrefsAndRoles (void) /***** Get action and role from last data *****/ if (GetActionAndRoleFromLastData) - { - /* Get action from last data */ - LastSuperAction = Act_GetSuperAction (Gbl.Usrs.Me.UsrLast.LastAct); - if (LastSuperAction != ActUnk) + // Remember last action and role only if last access is recent + if (Gbl.Usrs.Me.UsrLast.LastTime >= Gbl.StartExecutionTimeUTC - + Cfg_MAX_TIME_TO_REMEMBER_LAST_ACTION_ON_LOGIN) { - Gbl.Action.Act = LastSuperAction; - Tab_SetCurrentTab (); - } + /* Get action from last data */ + LastSuperAction = Act_GetSuperAction (Gbl.Usrs.Me.UsrLast.LastAct); + if (LastSuperAction != ActUnk) + { + Gbl.Action.Act = LastSuperAction; + Tab_SetCurrentTab (); + } - /* Get role from last data */ - Gbl.Usrs.Me.Role.Logged = Gbl.Usrs.Me.UsrLast.LastRole; - } + /* Get role from last data */ + Gbl.Usrs.Me.Role.Logged = Gbl.Usrs.Me.UsrLast.LastRole; + } } /***** Set my roles *****/ diff --git a/swad_user.h b/swad_user.h index 015c7d50..454fb3c7 100644 --- a/swad_user.h +++ b/swad_user.h @@ -220,6 +220,7 @@ struct UsrLast } LastHie; Act_Action_t LastAct; Rol_Role_t LastRole; + long LastTime; long LastAccNotif; };