You are here

function username_enumeration_prevention_pass_submit in Username Enumeration Prevention 8

Same name and namespace in other branches
  1. 6 username_enumeration_prevention.module \username_enumeration_prevention_pass_submit()
  2. 7 username_enumeration_prevention.module \username_enumeration_prevention_pass_submit()

Overrides the user_pass_submit() found in user.pages.inc.

1 string reference to 'username_enumeration_prevention_pass_submit'
username_enumeration_prevention_form_user_pass_alter in ./username_enumeration_prevention.module
Implements hook_form_FORM_ID_alter().

File

./username_enumeration_prevention.module, line 71
Main file for the Username Enumeration Prevention module.

Code

function username_enumeration_prevention_pass_submit($form, FormStateInterface $form_state) {
  $account = $form_state
    ->getValue('account');
  if (isset($account) && !$form_state
    ->get('username_enumeration_prevention_blocked')) {
    $langcode = \Drupal::languageManager()
      ->getCurrentLanguage()
      ->getId();

    // Mail one time login URL and instructions using current language.
    $mail = _user_mail_notify('password_reset', $account, $langcode);
    if (!empty($mail)) {
      \Drupal::logger('username_enumeration_prevention')
        ->notice('Password reset instructions mailed to %name at %email.', [
        '%name' => $account
          ->getAccountName(),
        '%email' => $account
          ->getEmail(),
      ]);
    }
  }
  \Drupal::messenger()
    ->addMessage(t('If the username or email address exists and is active, further instructions have been sent to your email address.'));
  $form_state
    ->setRedirect('user.page');
}