diff --git a/core/modules/user/config/install/user.settings.yml b/core/modules/user/config/install/user.settings.yml index 8372ccd..44e0ccf 100644 --- a/core/modules/user/config/install/user.settings.yml +++ b/core/modules/user/config/install/user.settings.yml @@ -3,6 +3,8 @@ verify_mail: true notify: cancel_confirm: true password_reset: true + mail_change_notification: true + mail_change_verification: true status_activated: true status_blocked: false status_canceled: false diff --git a/core/modules/user/config/schema/user.schema.yml b/core/modules/user/config/schema/user.schema.yml index 17d043f..3f264c2 100644 --- a/core/modules/user/config/schema/user.schema.yml +++ b/core/modules/user/config/schema/user.schema.yml @@ -20,6 +20,12 @@ user.settings: password_reset: type: boolean label: 'Notify user when password reset' + mail_change_notification: + type: boolean + label: 'Notify user when email changes' + mail_change_verification: + type: boolean + label: 'Verify user of an email address change' 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 977885a..ef9ee08 100644 --- a/core/modules/user/src/AccountForm.php +++ b/core/modules/user/src/AccountForm.php @@ -388,32 +388,31 @@ public function validate(array $form, FormStateInterface $form_state) { * {@inheritdoc} */ public function submitForm(array &$form, FormStateInterface $form_state) { - - $user = $this->getEntity($form_state); + $user = \Drupal::currentUser(); + $account = $this->getEntity($form_state); $new_email = $form_state->getValue('mail'); - if($user->getEmail() !== $new_email && !$user->access('administer users')) { - $old_email = $user->getEmail(); + if(!$account->isNew() && $account->getEmail() !== $new_email && !$user->hasPermission('administer users')) { + $old_email = $account->getEmail(); // Send a verification to the new email address. - $user->setEmail($new_email); - if(_user_mail_notify('mail_change_verification', $user, NULL)) { + $account->setEmail($new_email); + if(_user_mail_notify('mail_change_verification', $account, NULL)) { // Send notification email to the old email address. - $user->setEmail($old_email); - _user_mail_notify('mail_change_notification', $user); + $account->setEmail($old_email); + _user_mail_notify('mail_change_notification', $account); } // The user's email address will be updated after verification. - $user->setEmail($old_email); + $account->setEmail($old_email); } parent::submitForm($form, $form_state); - $user = $this->getEntity($form_state); // If there's a session set to the users id, remove the password reset tag // since a new password was saved. - if (isset($_SESSION['pass_reset_'. $user->id()])) { - unset($_SESSION['pass_reset_'. $user->id()]); + if (isset($_SESSION['pass_reset_'. $account->id()])) { + unset($_SESSION['pass_reset_'. $account->id()]); } } }