File tree Expand file tree Collapse file tree 4 files changed +48
-3
lines changed Expand file tree Collapse file tree 4 files changed +48
-3
lines changed Original file line number Diff line number Diff line change 11<?php
2+
23/* For license terms, see /license.txt */
34
45require_once __DIR__ .'/../inc/global.inc.php ' ;
56
6- $ token = isset ( $ _GET ['token ' ]) ? $ _GET [ ' token ' ] : '' ;
7+ $ token = $ _GET ['token ' ] ?? '' ;
78
89if (!ctype_alnum ($ token )) {
910 $ token = '' ;
3738
3839 /** @var \Chamilo\UserBundle\Entity\User $user */
3940 $ user = UserManager::getManager ()->findUserByConfirmationToken ($ token );
41+
4042 if ($ user ) {
4143 if (!$ user ->isPasswordRequestNonExpired ($ ttl )) {
4244 Display::addFlash (Display::return_message (get_lang ('LinkExpired ' )), 'warning ' );
5456 Database::getManager ()->persist ($ user );
5557 Database::getManager ()->flush ();
5658
59+ if (api_get_configuration_value ('force_renew_password_at_first_login ' )) {
60+ $ extraFieldValue = new ExtraFieldValue ('user ' );
61+ $ value = $ extraFieldValue ->get_values_by_handler_and_field_variable ($ user ->getId (), 'ask_new_password ' );
62+ if (!empty ($ value ) && isset ($ value ['value ' ]) && 1 === (int ) $ value ['value ' ]) {
63+ $ extraFieldValue ->delete ($ value ['id ' ]);
64+ }
65+ }
66+
5767 Display::addFlash (Display::return_message (get_lang ('Updated ' )));
5868 header ('Location: ' .api_get_path (WEB_PATH ));
5969 exit ;
Original file line number Diff line number Diff line change @@ -7319,4 +7319,32 @@ private static function getGravatar(
73197319
73207320 return $ url ;
73217321 }
7322+
7323+ public static function redirectToResetPassword ($ userId )
7324+ {
7325+ if (!api_get_configuration_value ('force_renew_password_at_first_login ' )) {
7326+ return ;
7327+ }
7328+
7329+ $ askPassword = self ::get_extra_user_data_by_field (
7330+ $ userId ,
7331+ 'ask_new_password '
7332+ );
7333+
7334+ if (!empty ($ askPassword ) && isset ($ askPassword ['ask_new_password ' ]) &&
7335+ 1 === (int ) $ askPassword ['ask_new_password ' ]
7336+ ) {
7337+ $ uniqueId = api_get_unique_id ();
7338+ $ userObj = api_get_user_entity ($ userId );
7339+
7340+ $ userObj ->setConfirmationToken ($ uniqueId );
7341+ $ userObj ->setPasswordRequestedAt (new \DateTime ());
7342+
7343+ Database::getManager ()->persist ($ userObj );
7344+ Database::getManager ()->flush ();
7345+
7346+ $ url = api_get_path (WEB_CODE_PATH ).'auth/reset.php?token= ' .$ uniqueId ;
7347+ api_location ($ url );
7348+ }
7349+ }
73227350}
Original file line number Diff line number Diff line change 516516 if (is_array ($ my_url_list ) &&
517517 in_array ($ current_access_url_id , $ my_url_list )
518518 ) {
519+ UserManager::redirectToResetPassword ($ uData ['user_id ' ]);
519520 ConditionalLogin::check_conditions ($ uData );
520521
521522 $ _user ['user_id ' ] = $ uData ['user_id ' ];
536537 exit ;
537538 }
538539 } else {
539- //Only admins of the "main" (first) Chamilo portal can login wherever they want
540+ // Only admins of the "main" (first) Chamilo portal can login wherever they want
540541 if (in_array (1 , $ my_url_list )) {
541- //Check if this admin have the access_url_id = 1 which means the principal
542+ // Check if this admin have the access_url_id = 1 which means the principal
542543 ConditionalLogin::check_conditions ($ uData );
543544 $ _user ['user_id ' ] = $ uData ['user_id ' ];
544545 $ _user ['status ' ] = $ uData ['status ' ];
548549 } else {
549550 //This means a secondary admin wants to login so we check as he's a normal user
550551 if (in_array ($ current_access_url_id , $ my_url_list )) {
552+ UserManager::redirectToResetPassword ($ uData ['user_id ' ]);
551553 $ _user ['user_id ' ] = $ uData ['user_id ' ];
552554 $ _user ['status ' ] = $ uData ['status ' ];
553555 Session::write ('_user ' , $ _user );
566568 }
567569 }
568570 } else {
571+ UserManager::redirectToResetPassword ($ uData ['user_id ' ]);
569572 ConditionalLogin::check_conditions ($ uData );
570573 $ _user ['user_id ' ] = $ uData ['user_id ' ];
571574 $ _user ['status ' ] = $ uData ['status ' ];
Original file line number Diff line number Diff line change 19451945// Disable webservices.
19461946//$_configuration['disable_webservices'] = true;
19471947
1948+ // Ask user to renew password at first login.
1949+ // Requires a user checkbox extra field called "ask_new_password".
1950+ //$_configuration['force_renew_password_at_first_login'] = true;
1951+
19481952// KEEP THIS AT THE END
19491953// -------- Custom DB changes
19501954// Add user activation by confirmation email
You can’t perform that action at this time.
0 commit comments