diff --git a/core/modules/user/config/install/user.mail.yml b/core/modules/user/config/install/user.mail.yml index 1f1eaaf..843398f 100644 --- a/core/modules/user/config/install/user.mail.yml +++ b/core/modules/user/config/install/user.mail.yml @@ -8,7 +8,7 @@ mail_change_notification: body: "[user:name],\n\nA request to change your e-mail address has been made at [site:name]. In order to complete the change you will need to follow the instructions sent to your new e-mail address within one day." subject: 'E-mail change information for [user:name] at [site:name]' mail_change_verification: - body: "[user:name],\n\nA request to change your e-mail address has been made at [site:name]. You need to verif the change by clicking on the link below or copying and pasting it in your browser:\n\n[user:mail-change-login-url]\n\nThis is a one-time URL, so it can be used only once. It expires after one day. If not used, your e-mail address at [site:name] will not change." + body: "[user:name],\n\nA request to change your e-mail address has been made at [site:name]. You need to verify the change by clicking on the link below or copying and pasting it in your browser:\n\n[user:mail-change-login-url]\n\nThis is a one-time URL, so it can be used only once. It expires after one day. If not used, your e-mail address at [site:name] will not change." subject: 'E-mail change information for [user:name] at [site:name]' register_admin_created: body: "[user:name],\n\nA site administrator at [site:name] has created an account for you. You may now log in by clicking this link or copying and pasting it to your browser:\n\n[user:one-time-login-url]\n\nThis link can only be used once to log in and will lead you to a page where you can set your password.\n\nAfter setting your password, you will be able to log in at [site:login-url] in the future using:\n\nusername: [user:name]\npassword: Your password\n\n-- [site:name] team" diff --git a/core/modules/user/config/schema/user.schema.yml b/core/modules/user/config/schema/user.schema.yml index 3f264c2..d027c7b 100644 --- a/core/modules/user/config/schema/user.schema.yml +++ b/core/modules/user/config/schema/user.schema.yml @@ -25,7 +25,7 @@ user.settings: label: 'Notify user when email changes' mail_change_verification: type: boolean - label: 'Verify user of an email address change' + label: 'Require email verification when a user changes their email address' status_activated: type: boolean label: 'Notify user when account is activated' diff --git a/core/modules/user/src/AccountForm.php b/core/modules/user/src/AccountForm.php index 82c5619..8b6deea 100644 --- a/core/modules/user/src/AccountForm.php +++ b/core/modules/user/src/AccountForm.php @@ -398,11 +398,10 @@ protected function flagViolations(EntityConstraintViolationListInterface $violat * {@inheritdoc} */ public function submitForm(array &$form, FormStateInterface $form_state) { - $user = \Drupal::currentUser(); $account = $this->getEntity($form_state); $new_email = $form_state->getValue('mail'); - if(!$account->isNew() && $account->getEmail() !== $new_email && !$user->hasPermission('administer users')) { + if(!$account->isNew() && $account->getEmail() !== $new_email && !\Drupal::currentUser()->hasPermission('administer users')) { $old_email = $account->getEmail(); // Send a verification to the new email address. @@ -414,7 +413,9 @@ public function submitForm(array &$form, FormStateInterface $form_state) { } // The user's email address will be updated after verification. - $account->setEmail($old_email); + $form_state->setValue('mail', $old_email); + + drupal_set_message($this->t('Your email address needs to be validated. Further instructions have been sent to your new email address.'), 'warning'); } parent::submitForm($form, $form_state); diff --git a/core/modules/user/src/AccountSettingsForm.php b/core/modules/user/src/AccountSettingsForm.php index 24e4ef6..4153820 100644 --- a/core/modules/user/src/AccountSettingsForm.php +++ b/core/modules/user/src/AccountSettingsForm.php @@ -308,7 +308,7 @@ public function buildForm(array $form, FormStateInterface $form_state) { '#title' => t('Email change notification'), '#collapsible' => TRUE, '#collapsed' => TRUE, - '#description' => t('Edit the e-mail messages sent to users old mail address who change mail address.') . ' ' . $email_token_help, + '#description' => t("Edit the email messages sent to users' old email address when the email address is changed.") . ' ' . $email_token_help, '#group' => 'email', '#weight' => 11, ); @@ -330,7 +330,7 @@ public function buildForm(array $form, FormStateInterface $form_state) { '#title' => t('Email change verification'), '#collapsible' => TRUE, '#collapsed' => TRUE, - '#description' => t('Edit the e-mail messages sent to users new mail address who change mail address.') . ' ' . $email_token_help, + '#description' => t("Edit the email messages sent to users' new email address when the email address is changed.") . ' ' . $email_token_help, '#group' => 'email', '#weight' => 13, ); @@ -340,7 +340,7 @@ public function buildForm(array $form, FormStateInterface $form_state) { '#default_value' => $mail_config->get('mail_change_verification.subject'), '#maxlength' => 180, ); - $form['email_email_mail_change_verification']['user_email_change_verification_body'] = array( + $form['email_email_change_verification']['user_email_change_verification_body'] = array( '#type' => 'textarea', '#title' => t('Body'), '#default_value' => $mail_config->get('mail_change_verification.body'), diff --git a/core/modules/user/src/Controller/UserController.php b/core/modules/user/src/Controller/UserController.php index eb12780..6760cf4 100644 --- a/core/modules/user/src/Controller/UserController.php +++ b/core/modules/user/src/Controller/UserController.php @@ -138,7 +138,7 @@ public function resetPass($uid, $timestamp, $hash) { } /** - * Returens the user change email page. + * Returns the user change email page. * * @param int $uid * UID of user requesting reset. @@ -164,18 +164,18 @@ public function changeEmail($uid, $timestamp, $new_email, $hash) { if ($timestamp < $current) { if($current - $timestamp > $timeout) { - drupal_set_message(t('You have tried to use a one-time e-mail change link for %account that has expired--your change of e-mail request was not completed. Please visit your account edit page if you wish to attempt the change again.', array('%account' => $account->name)), 'error'); + drupal_set_message(t('You have tried to use a one-time email address change link for %account that has expired -- your change of email address was not completed. Please visit your account edit page if you wish to attempt the change again.', array('%account' => $account->name)), 'error'); } else if ($user->id() && $user->id() != $account->id()) { - drupal_set_message(t('You are currently logged in as %user, and are attempting to confirm an e-mail change for %account, which is not allowed. Please log in as %account and initiate a new change of e-mail request.', array('%user' => $user->name, '%account' => $account->name)), 'error'); + drupal_set_message(t('You are currently logged in as %user, and are attempting to confirm an email address change for %account, which is not allowed. Please log in as %account and initiate a new change of email request.', array('%user' => $user->name, '%account' => $account->name)), 'error'); } else if ($hash != user_pass_rehash($account->getPassword(), $timestamp, $new_email, $account->id())) { - drupal_set_message(t('There was a problem verifying your change of e-mail request. Please visit your account edit page and attempt the change again'), 'error'); + drupal_set_message(t('There was a problem validating the used link. Please visit your account edit page and retry changing your email address.'), 'error'); } else if ($timestamp > $account->login && $timestamp < $current) { $account->setEmail($new_email); $account->save(); - drupal_set_message(t('Your e-mail address is now %mail.', array('%mail' => $new_email))); + drupal_set_message(t('Your email address has been changed to %mail.', array('%mail' => $new_email))); } } else { diff --git a/core/modules/user/user.module b/core/modules/user/user.module index 65b2a8a..6328a0a 100644 --- a/core/modules/user/user.module +++ b/core/modules/user/user.module @@ -598,7 +598,7 @@ function user_change_mail_url($account, $options = array()) { 'uid' => $account->id(), 'timestamp' => $timestamp, 'new_email' => $account->getEmail(), - 'hash' => user_pass_rehash($account->getPassword(), $timestamp, $account->getLastLoginTime(), $account->id()), + 'hash' => user_pass_rehash($account, $timestamp), ], $url_options); } @@ -952,7 +952,7 @@ function user_mail($key, &$message, $params) { * properties: * - login: The UNIX timestamp of the user's last login. * - pass: The hashed account login password. - * - email: The email address of the user. + * - email: The user's email address. * @param array $options * A keyed array of settings and flags to control the token replacement * process. See \Drupal\Core\Utility\Token::replace().