You are here

function mail_login_extra_validate in Mail Login 8

Custom validate function to enable email address login.

1 string reference to 'mail_login_extra_validate'
mail_login_form_alter in ./mail_login.module
Implements hook_form_alter().

File

./mail_login.module, line 37
Mail Login: This module enables users to login by email address.

Code

function mail_login_extra_validate($form, FormStateInterface &$form_state) {
  $login_input = $form_state
    ->getValue('name');
  if (filter_var($login_input, FILTER_VALIDATE_EMAIL)) {
    $user = user_load_by_mail($login_input);
    if ($user) {
      $form_state
        ->setValue('name', $user
        ->getAccountName());
    }
  }
}