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 1
1
<?php
2
+
2
3
/* For license terms, see /license.txt */
3
4
4
5
require_once __DIR__ .'/../inc/global.inc.php ' ;
5
6
6
- $ token = isset ( $ _GET ['token ' ]) ? $ _GET [ ' token ' ] : '' ;
7
+ $ token = $ _GET ['token ' ] ?? '' ;
7
8
8
9
if (!ctype_alnum ($ token )) {
9
10
$ token = '' ;
37
38
38
39
/** @var \Chamilo\UserBundle\Entity\User $user */
39
40
$ user = UserManager::getManager ()->findUserByConfirmationToken ($ token );
41
+
40
42
if ($ user ) {
41
43
if (!$ user ->isPasswordRequestNonExpired ($ ttl )) {
42
44
Display::addFlash (Display::return_message (get_lang ('LinkExpired ' )), 'warning ' );
54
56
Database::getManager ()->persist ($ user );
55
57
Database::getManager ()->flush ();
56
58
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
+
57
67
Display::addFlash (Display::return_message (get_lang ('Updated ' )));
58
68
header ('Location: ' .api_get_path (WEB_PATH ));
59
69
exit ;
Original file line number Diff line number Diff line change @@ -7319,4 +7319,32 @@ private static function getGravatar(
7319
7319
7320
7320
return $ url ;
7321
7321
}
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
+ }
7322
7350
}
Original file line number Diff line number Diff line change 516
516
if (is_array ($ my_url_list ) &&
517
517
in_array ($ current_access_url_id , $ my_url_list )
518
518
) {
519
+ UserManager::redirectToResetPassword ($ uData ['user_id ' ]);
519
520
ConditionalLogin::check_conditions ($ uData );
520
521
521
522
$ _user ['user_id ' ] = $ uData ['user_id ' ];
536
537
exit ;
537
538
}
538
539
} 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
540
541
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
542
543
ConditionalLogin::check_conditions ($ uData );
543
544
$ _user ['user_id ' ] = $ uData ['user_id ' ];
544
545
$ _user ['status ' ] = $ uData ['status ' ];
548
549
} else {
549
550
//This means a secondary admin wants to login so we check as he's a normal user
550
551
if (in_array ($ current_access_url_id , $ my_url_list )) {
552
+ UserManager::redirectToResetPassword ($ uData ['user_id ' ]);
551
553
$ _user ['user_id ' ] = $ uData ['user_id ' ];
552
554
$ _user ['status ' ] = $ uData ['status ' ];
553
555
Session::write ('_user ' , $ _user );
566
568
}
567
569
}
568
570
} else {
571
+ UserManager::redirectToResetPassword ($ uData ['user_id ' ]);
569
572
ConditionalLogin::check_conditions ($ uData );
570
573
$ _user ['user_id ' ] = $ uData ['user_id ' ];
571
574
$ _user ['status ' ] = $ uData ['status ' ];
Original file line number Diff line number Diff line change 1945
1945
// Disable webservices.
1946
1946
//$_configuration['disable_webservices'] = true;
1947
1947
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
+
1948
1952
// KEEP THIS AT THE END
1949
1953
// -------- Custom DB changes
1950
1954
// Add user activation by confirmation email
You can’t perform that action at this time.
0 commit comments