diff --git a/core/modules/user/src/AccountForm.php b/core/modules/user/src/AccountForm.php index bf05df4..b99a0b1 100644 --- a/core/modules/user/src/AccountForm.php +++ b/core/modules/user/src/AccountForm.php @@ -387,21 +387,21 @@ protected function flagViolations(EntityConstraintViolationListInterface $violat */ public function submitForm(array &$form, FormStateInterface $form_state) { $account = $this->getEntity($form_state); - $new_email = $form_state->getValue('mail'); + $new_mail = $form_state->getValue('mail'); + $old_mail = $account->getEmail(); - if(!$account->isNew() && $account->getEmail() !== $new_email && !\Drupal::currentUser()->hasPermission('administer users')) { - $old_email = $account->getEmail(); + if (!$account->isNew() && $old_mail !== $new_mail && !$this->currentUser()->hasPermission('administer users')) { // Send a verification to the new email address. - $account->setEmail($new_email); - if(_user_mail_notify('mail_change_verification', $account, NULL)) { + $account->setEmail($new_mail); + if (_user_mail_notify('mail_change_verification', $account, NULL)) { // Send notification email to the old email address. - $account->setEmail($old_email); + $account->setEmail($old_mail); _user_mail_notify('mail_change_notification', $account); } // The user's email address will be updated after verification. - $form_state->setValue('mail', $old_email); + $form_state->setValue('mail', $old_mail); drupal_set_message($this->t('Your email address needs to be validated. Further instructions have been sent to your new email address.'), 'warning'); } diff --git a/core/modules/user/src/AccountSettingsForm.php b/core/modules/user/src/AccountSettingsForm.php index c20a020..fb8fac2 100644 --- a/core/modules/user/src/AccountSettingsForm.php +++ b/core/modules/user/src/AccountSettingsForm.php @@ -305,44 +305,44 @@ public function buildForm(array $form, FormStateInterface $form_state) { $form['email_email_change_notification'] = array( '#type' => 'details', - '#title' => t('Email change notification'), + '#title' => $this->t('Email change notification'), '#collapsible' => TRUE, '#collapsed' => TRUE, - '#description' => t("Edit the email messages sent to users' old email address when the email address is changed.") . ' ' . $email_token_help, + '#description' => $this->t("Edit the email messages sent to users' old email address when the email address is changed.") . ' ' . $email_token_help, '#group' => 'email', '#weight' => 11, ); $form['email_email_change_notification']['user_email_change_notification_subject'] = array( '#type' => 'textfield', - '#title' => t('Subject'), + '#title' => $this->t('Subject'), '#default_value' => $mail_config->get('mail_change_notification.subject'), '#maxlength' => 180, ); $form['email_email_change_notification']['user_email_change_notification_body'] = array( '#type' => 'textarea', - '#title' => t('Body'), + '#title' => $this->t('Body'), '#default_value' => $mail_config->get('mail_change_notification.body'), '#rows' => 12, ); $form['email_email_change_verification'] = array( '#type' => 'details', - '#title' => t('Email change verification'), + '#title' => $this->t('Email change verification'), '#collapsible' => TRUE, '#collapsed' => TRUE, - '#description' => t("Edit the email messages sent to users' new email address when the email address is changed.") . ' ' . $email_token_help, + '#description' => $this->t("Edit the email messages sent to users' new email address when the email address is changed.") . ' ' . $email_token_help, '#group' => 'email', '#weight' => 13, ); $form['email_email_change_verification']['user_email_change_verification_subject'] = array( '#type' => 'textfield', - '#title' => t('Subject'), + '#title' => $this->t('Subject'), '#default_value' => $mail_config->get('mail_change_verification.subject'), '#maxlength' => 180, ); $form['email_email_change_verification']['user_email_change_verification_body'] = array( '#type' => 'textarea', - '#title' => t('Body'), + '#title' => $this->t('Body'), '#default_value' => $mail_config->get('mail_change_verification.body'), '#rows' => 12, ); diff --git a/core/modules/user/src/Controller/UserController.php b/core/modules/user/src/Controller/UserController.php index 018cfb5..9c4a667 100644 --- a/core/modules/user/src/Controller/UserController.php +++ b/core/modules/user/src/Controller/UserController.php @@ -71,7 +71,7 @@ public static function create(ContainerInterface $container) { } /** - * Returns the user password reset page. + * Provides a callback for user E-mail change page. * * @param int $uid * UID of user requesting reset. @@ -145,7 +145,7 @@ public function resetPass($uid, $timestamp, $hash) { * UID of user requesting reset. * @param int $timestamp * The current timestamp. - * @param string new_email + * @param string $new_mail * The user's new email address. * @param string $hash * Login link hash. @@ -156,30 +156,29 @@ public function resetPass($uid, $timestamp, $hash) { * @throws \Symfony\Component\HttpKernel\Exception\AccessDeniedHttpException * If the timestamp passed is in the future. */ - public function changeEmail($uid, $timestamp, $new_email, $hash) { - $user = \Drupal::currentUser(); + public function changeEmail($uid, $timestamp, $new_mail, $hash) { $account = $this->userStorage->load($uid); - // We need to set the new email here to validate the hash correctly, which is - // created using the new mail adress. We only save the account if the hash matches. - $account->setEmail($new_email); - + // We need to set the new email here to validate the hash correctly, + // which is created using the new mail adress. We only save the account + // if the hash matches. + $account->setEmail($new_mail); $timeout = 24 * 60 * 60; - $current = $_SERVER['REQUEST_TIME']; + $current = REQUEST_TIME; if ($timestamp < $current) { - if($current - $timestamp > $timeout) { + if ($current - $timestamp > $timeout) { 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()) { + elseif ($this->currentUser()->id() && $this->currentUser()->id() != $account->id()) { 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, $timestamp)) { + elseif ($hash != user_pass_rehash($account, $timestamp)) { 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->getLastLoginTime() && $timestamp < $current) { + elseif ($timestamp > $account->getLastLoginTime() && $timestamp < $current) { $account->save(); - drupal_set_message(t('Your email address has been changed to %mail.', array('%mail' => $new_email))); + drupal_set_message(t('Your email address has been changed to %mail.', array('%mail' => $new_mail))); } } else { diff --git a/core/modules/user/user.install b/core/modules/user/user.install index 0c59cb7..ad523f8 100644 --- a/core/modules/user/user.install +++ b/core/modules/user/user.install @@ -1,5 +1,7 @@ getEditable('user.mail'); - $mail_config->set('mail_change_notification.body',"[user:display-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."); - $mail_config->set('mail_change_notification.subject','E-mail change information for [user:display-name] at [site:name]'); - $mail_config->set('mail_change_verification.body',"[user:display-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."); - $mail_config->set('mail_change_verification.subject','E-mail change information for [user:display-name] at [site:name]'); + $mail_config->set('mail_change_notification.body', $mail_settings['mail_change_notification']['body']); + $mail_config->set('mail_change_notification.subject', $mail_settings['mail_change_notification']['subject']); + $mail_config->set('mail_change_verification.body', $mail_settings['mail_change_verification']['body']); + $mail_config->set('mail_change_verification.subject', $mail_settings['mail_change_verification']['body']); $mail_config->save(); } diff --git a/core/modules/user/user.module b/core/modules/user/user.module index 0246d24..cf58e5b 100644 --- a/core/modules/user/user.module +++ b/core/modules/user/user.module @@ -606,7 +606,7 @@ function user_pass_reset_url($account, $options = array()) { * A unique URL that provides a one-time email change confirmation for the * user. */ -function user_change_mail_url($account, $options = array()) { +function user_change_mail_url($account, $options = []) { $timestamp = $_SERVER['REQUEST_TIME']; $langcode = isset($options['langcode']) ? $options['langcode'] : $account->getPreferredLangcode(); $url_options = array('absolute' => TRUE, 'language' => \Drupal::languageManager()->getLanguage($langcode));