You are here

function email_registration_user_login_validate in Email Registration 8

Same name and namespace in other branches
  1. 5 email_registration.module \email_registration_user_login_validate()
  2. 6 email_registration.module \email_registration_user_login_validate()
  3. 7 email_registration.module \email_registration_user_login_validate()

Form element validation handler for the user login form.

Allows users to authenticate by email, which is our preferred method.

2 string references to 'email_registration_user_login_validate'
EmailRegistrationLogin::buildPaneForm in src/Plugin/Commerce/CheckoutPane/EmailRegistrationLogin.php
Builds the pane form.
email_registration_form_user_login_form_alter in ./email_registration.module
Implements hook_form_FORM_ID_alter().

File

./email_registration.module, line 178
Allows users to register with an email address as their username.

Code

function email_registration_user_login_validate($form, FormStateInterface $form_state) {
  $mail = $form_state
    ->getValue('name');
  if (!empty($mail)) {
    $config = \Drupal::config('email_registration.settings');
    if ($user = user_load_by_mail($mail)) {
      $form_state
        ->setValue('name', $user
        ->getAccountName());
    }
    elseif (!$config
      ->get('login_with_username')) {
      $user_input = $form_state
        ->getUserInput();
      $query = isset($user_input['name']) ? [
        'name' => $user_input['name'],
      ] : [];
      $form_state
        ->setErrorByName('name', t('Unrecognized email address or password. <a href=":password">Forgot your password?</a>', [
        ':password' => Url::fromRoute('user.pass', [], [
          'query' => $query,
        ])
          ->toString(),
      ]));
    }
  }
}