MDL-82379 core_user: Move email change token to user private access key

This commit is contained in:
Huong Nguyen 2024-12-05 10:26:00 +07:00 committed by Jun Pataleta
parent 488da643c6
commit bef45583cc
No known key found for this signature in database
GPG key ID: F83510526D99E2C7
4 changed files with 18 additions and 6 deletions

View file

@ -199,9 +199,11 @@ if ($userform->is_cancelled()) {
// Other users require a confirmation email.
if (isset($usernew->email) and $user->email != $usernew->email && !has_capability('moodle/user:update', $systemcontext)) {
$a = new stdClass();
$emailchangedkey = random_string(20);
// Set the key to expire in 10 minutes.
$validuntil = time() + 600;
$emailchangedkey = create_user_key('core_user/email_change', $user->id, null, null, $validuntil);
set_user_preference('newemail', $usernew->email, $user->id);
set_user_preference('newemailkey', $emailchangedkey, $user->id);
set_user_preference('newemailattemptsleft', 3, $user->id);
$a->newemail = $emailchanged = $usernew->email;