Skip to content

Instantly share code, notes, and snippets.

@henryhu712
Last active April 12, 2016 03:03
Show Gist options
  • Star 0 You must be signed in to star a gist
  • Fork 0 You must be signed in to fork a gist
  • Save henryhu712/7fbe3c3684ae8712d855eb141f2af643 to your computer and use it in GitHub Desktop.
Save henryhu712/7fbe3c3684ae8712d855eb141f2af643 to your computer and use it in GitHub Desktop.
Email login only, not email registration

The solution is from the issue:

logintoboggan module allows to register & login with email. user_registrationpassword module allows to set password and emai validation both configuration. But it does NOT work for both modules together.

Solution:

  • Enabled user_registrationpassword;

  • Abandon logintoboggan, instead, implement email login with the following:

    function bmisc_form_alter(&$form, &$form_state, $form_id) { if ($form_id == 'user_login') { array_unshift($form['#validate'], 'bmisc_email_login_user_login_validate'); } } /**

    • Capture the username entered, if there is an @ symbol, it will check it against email addresses instead of the username
    • if multiple_email is installed, check against that table instead
    • @param array $form The current form (I guess...)
    • @param array $form_state The state of the form (I guess...) */ function bmisc_email_login_user_login_validate($form, &$form_state) { if (isset($form_state['values']['name']) && strpos($form_state['values']['name'], '@') !== false) { $name = db_query("SELECT name FROM {users} WHERE LCASE(mail) = LCASE(:email)", array(":email" => $form_state['values']['name']))->fetchField(); if ($name) { form_set_value($form['name'], $name, $form_state); } } }

Reference: http://blog.seanja.com/2011/08/module-login-with-email-or-username-drupal/

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment