I know there are a million duplicates of this request, but please hear me out:

In the past, the maintainer of this module said he saw no need for this. However, we actually have a very specific need for this feature:

We need our users to login to the site using only their email address. Our Drupal site connects to several customer relations management services (including Automatr, by Volacci, which is actively courting Drupal sites, so we are likely to not be the only site with this problem). These services are able to pull the data from any Drupal form submitted, including the login form. If on the login form they can be required to use their email address, we have the required key Automatr and *everything else* uses to detect which real person they are.

If we can use email, everything in our entire system works, and basically allows us to run our whole business, provide services, market, make money, satisfy customers, etc. etc. If we can't take in the email address, nothing works.

It's an exponential difference -- between having a site or having a whole operational ecosystem.

If we simply change the theming so that it says "Login using your email address only. Not your user name. Never use your user name. Ever." This will not stop anyone from being able to successfully submit the form using the username, which will be the worst case scenario for this ecosystem -- it will write over the email address in our other platforms' records, propagating not only bad data throughout and losing one of the most valuable pieces of data anyone can have for a person, but also probably breaking the one key that syncs a user across all systems.

We need to know and require that the data a person logs in with is their email address.

Using a module (like Email Registration) that disables or auto creates the user name is not an option: User names are used elsewhere so users have a self-chosen identity in forums, etc. Plus, we use RealName in areas to display a real name for people such as site authors and staff.

Honestly, this seems like the sort of thing Drupal core should already provide as an option. Given it doesn't, I can't think of where else this gets accomplished except in LoginToboggan (especially since we and so many others already rely on it for other functionality -- and it's likely there could be bad conflicts if another module is required).

Is there any chance this very non-trivial function could be implemented somehow (without paying the $70,000 one poster suggested in another forum post about this topic)?

Comments

berenddeboer’s picture

To be honest, this is a really trivial request, and someone with a little bit of knowledge can easily implement a custom validation hook to the user registration form to do this.

If this belongs in logintoboggan or not is a different issue.

somatics’s picture

I appreciate the quick reply. Unfortunately, it's not trivial to us, and it's knowledge we lack:

While we have a long background in Drupal, we don't have experience with this aspect of it. We wouldn't know how to begin to write this, or what existing file to patch or new file to create or where to place it.

Do you have any suggestions about how to proceed to make this happen?

stevecowie’s picture

The solution suggested at #1 would work fine. You just need a custom validation function that checks that the data being submitted is a valid email. Here's a link to an explanation of how to do form validation: http://stackoverflow.com/questions/5299582/how-to-do-form-validation-in-...
You might want to combine the server side validation with something like this for client-side validation to get better ux: http://drupal.org/project/clientside_validation

somatics’s picture

Thank you for your suggestion. We'd be really content with going this route -- in fact, we'd be happy to even just do it with client side validation. We don't like to hack core or contributed modules, which is what it sounds like we'd need to do for a custom validation function.

However it would be done, it's outside of our scope of expertise on Drupal -- we have a lot of experience in building Drupal sites, but not in PHP coding. it involves modifying something so critical and global as logging in users, which makes me even more concerned about us messing with it.

So, an officially and competently developed module seems like a better idea. Unfortunately, the client-side validation module only does validation on custom forms and custom fields, not on the built-in login form.

We spent many hours on this and are at a dead-end. Is there any chance you have anything additional to offer as to how to make the client side or server side validation happen "for dummies" like us?

stevecowie’s picture

To implement the suggestion at #1 you would write a custom module with a form_alter hook that added an extra validation function to the existing array of validation functions. The hook is documented here: http://api.drupal.org/api/drupal/modules%21system%21system.api.php/funct...

Once you've added your custom function to the form_alter hook, it would be quite straightforward to write a function that checks the data from the name field to ensure that what's been submitted is an email.

This approach, incidentally, is definitely not a hack of anything but a standard implementation of Drupal's forms API using the hook system to interact with the core rather than hack it.

I'm not intending to add this to logintoboggan for now, but if you're really struggling I can write something for you that shows how it's done.

queenvictoria’s picture

Here are the beginnings of the solution. Simply hide the username field and copy the email field into the username. Note: I found that by setting our validation routine to the start I could rely on other modules (system, logintoboggan) to provide the validation of the email address. Its not perfect (if you supply an already used email address you get two warnings: one for user, one for mail). And some characters that are permitted in email addresses are illegal in usernames. But its a start.

<?php
/*
 * Implements hook_form_alter
 */
function MYTHEME_form_alter(&$form, &$form_state, $form_id) {
  if ( $form_id == 'user_register_form' ) {
    // hide the username field
    $form['account']['name']['#required'] = false;
    $form['account']['name']['#type'] = 'hidden';
    // add our validation callback first
    array_unshift($form['#validate'], '_MYTHEME_user_register_validation');
  }
}

/*
 * Copy the email address into the username form.
 */
function _MYTHEME_user_register_validation($form, &$form_state) {
  $email = $form_state['values']['mail'];
  $form_state['values']['name'] = $email;
  return TRUE;
}
queenvictoria’s picture

Component: Code » Documentation
Category: feature » support
Priority: Major » Normal

Changing category and component to represent that this issue forms documentation for the module rather than a proposed feature.

E Johnson’s picture

Hi queenvictoria,

Kind of an old thread.

The code you provided works like a charm. My only dilemma is that the name field in the core Users table is only 60 characters in length, where as, the mail field is 254. So I see this as a potential problem.

Have you implemented this on a live site with lots of users and seen any adverse side-effects? Is there any problems with changing the length of the core name field from 60 to 254? Will there be issues when I try to upgrade my Drupal 7.x.xx version to the newest 7.x.xx version?

The Email Registration module is another solution but my OCD hates seeing random numbers thrown into usernames created based off of the email addresses entered. I'd also have to go search and replace a lot of tokens (email templates, themes, etc.) going this route to eliminate the username from showing.

It seems strange that Drupal is still using Usernames where as every other App, Social Media platform, E-commerce site, etc. are strictly using e-mails as the norm since their unique to an individual.

Any advice on issues with modifying a core Drupal table would be appreciated. Thanks.

Joran Lafleuriel’s picture

#6 worked for me...

thanks queenvictoria !