diff --git a/core/modules/user/config/install/user.mail.yml b/core/modules/user/config/install/user.mail.yml index 436ff53..1f1eaaf 100644 --- a/core/modules/user/config/install/user.mail.yml +++ b/core/modules/user/config/install/user.mail.yml @@ -4,6 +4,12 @@ cancel_confirm: password_reset: body: "[user:name],\n\nA request to reset the password for your account has been made at [site:name].\n\nYou 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. It expires after one day and nothing will happen if it's not used.\n\n-- [site:name] team" subject: 'Replacement login information for [user:name] at [site:name]' +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." + 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" subject: 'An administrator created an account for you at [site:name]' diff --git a/core/modules/user/src/AccountForm.php b/core/modules/user/src/AccountForm.php index 16ab69f..977885a 100644 --- a/core/modules/user/src/AccountForm.php +++ b/core/modules/user/src/AccountForm.php @@ -388,6 +388,25 @@ public function validate(array $form, FormStateInterface $form_state) { * {@inheritdoc} */ public function submitForm(array &$form, FormStateInterface $form_state) { + + $user = $this->getEntity($form_state); + $new_email = $form_state->getValue('mail'); + + if($user->getEmail() !== $new_email && !$user->access('administer users')) { + $old_email = $user->getEmail(); + + // Send a verification to the new email address. + $user->setEmail($new_email); + if(_user_mail_notify('mail_change_verification', $user, NULL)) { + // Send notification email to the old email address. + $user->setEmail($old_email); + _user_mail_notify('mail_change_notification', $user); + } + + // The user's email address will be updated after verification. + $user->setEmail($old_email); + } + parent::submitForm($form, $form_state); $user = $this->getEntity($form_state); diff --git a/core/modules/user/src/AccountSettingsForm.php b/core/modules/user/src/AccountSettingsForm.php index df65cb8..cf11268 100644 --- a/core/modules/user/src/AccountSettingsForm.php +++ b/core/modules/user/src/AccountSettingsForm.php @@ -312,6 +312,50 @@ public function buildForm(array $form, FormStateInterface $form_state) { '#rows' => 12, ); + $form['email_mail_change_notification'] = array( + '#type' => 'details', + '#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, + '#group' => 'email', + '#weight' => 11, + ); + $form['email_mail_change_notification']['user_mail_mail_change_notification_subject'] = array( + '#type' => 'textfield', + '#title' => t('Subject'), + '#default_value' => $mail_config->get('mail_change_notification.subject'), + '#maxlength' => 180, + ); + $form['email_mail_change_notification']['user_mail_mail_change_notification_body'] = array( + '#type' => 'textarea', + '#title' => t('Body'), + '#default_value' => $mail_config->get('mail_change_notification.body'), + '#rows' => 12, + ); + + $form['email_mail_change_verification'] = array( + '#type' => 'details', + '#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, + '#group' => 'email', + '#weight' => 13, + ); + $form['email_mail_change_verification']['user_mail_mail_change_verification_subject'] = array( + '#type' => 'textfield', + '#title' => t('Subject'), + '#default_value' => $mail_config->get('mail_change_verification.subject'), + '#maxlength' => 180, + ); + $form['email_mail_change_verification']['user_mail_mail_change_verification_body'] = array( + '#type' => 'textarea', + '#title' => t('Body'), + '#default_value' => $mail_config->get('mail_change_verification.body'), + '#rows' => 12, + ); + $form['email_activated'] = array( '#type' => 'details', '#title' => $this->t('Account activation'), diff --git a/core/modules/user/user.module b/core/modules/user/user.module index 33ed45f..9a6e1c4 100644 --- a/core/modules/user/user.module +++ b/core/modules/user/user.module @@ -1179,6 +1179,8 @@ function user_role_revoke_permissions($rid, array $permissions = array()) { * - 'register_pending_approval': Welcome message, user pending admin * approval. * - 'password_reset': Password recovery request. + * - 'mail_change_notification': Email change notification. + * - 'mail_change_verification': Email change verification. * - 'status_activated': Account activated. * - 'status_blocked': Account blocked. * - 'cancel_confirm': Account cancellation request.