From 7d7943b3eda3ee5221ba06d4f9610636b72204f3 Mon Sep 17 00:00:00 2001 From: plegall Date: Tue, 22 Dec 2020 15:04:30 +0100 Subject: [PATCH] fixes #1275 delete password reset key when email address is changed --- include/functions_user.inc.php | 19 +++++++++++++++++++ include/ws_functions/pwg.users.php | 5 +++++ password.php | 10 +--------- profile.php | 5 +++++ 4 files changed, 30 insertions(+), 9 deletions(-) diff --git a/include/functions_user.inc.php b/include/functions_user.inc.php index 5503a9dba..a7b4ac910 100644 --- a/include/functions_user.inc.php +++ b/include/functions_user.inc.php @@ -1629,6 +1629,25 @@ UPDATE '.USER_AUTH_KEYS_TABLE.' pwg_query($query); } +/** + * Deactivates password reset key + * + * @since 11 + * @param int $user_id + * @return null + */ +function deactivate_password_reset_key($user_id) +{ + single_update( + USER_INFOS_TABLE, + array( + 'activation_key' => null, + 'activation_key_expire' => null, + ), + array('user_id' => $user_id) + ); +} + /** * Gets the last visit (datetime) of a user, based on history table * diff --git a/include/ws_functions/pwg.users.php b/include/ws_functions/pwg.users.php index 1f240e32f..f9f607017 100644 --- a/include/ws_functions/pwg.users.php +++ b/include/ws_functions/pwg.users.php @@ -555,6 +555,11 @@ SELECT deactivate_user_auth_keys($params['user_id'][0]); } + if (isset($updates[ $conf['user_fields']['email'] ])) + { + deactivate_password_reset_key($params['user_id'][0]); + } + if (isset($update_status) and count($params['user_id_for_status']) > 0) { $query = ' diff --git a/password.php b/password.php index b19bfabad..286f0a8d7 100644 --- a/password.php +++ b/password.php @@ -238,15 +238,7 @@ function reset_password() array($conf['user_fields']['id'] => $user_id) ); - single_update( - USER_INFOS_TABLE, - array( - 'activation_key' => null, - 'activation_key_expire' => null, - ), - array('user_id' => $user_id) - ); - + deactivate_password_reset_key($user_id); deactivate_user_auth_keys($user_id); $page['infos'][] = l10n('Your password has been reset'); diff --git a/profile.php b/profile.php index cb7873cd1..f2b9a2ccd 100644 --- a/profile.php +++ b/profile.php @@ -243,6 +243,11 @@ function save_profile_from_post($userdata, &$errors) ), array($data)); + if ($_POST['mail_address'] != $userdata['email']) + { + deactivate_password_reset_key($userdata['id']); + } + $activity_details_tables[] = 'users'; }