6

I need force users to register on my site with just email only. I cannot use the Email Registration module. With this module, a username is generated and assigned based on the user name part of the email address. Subsequent users who have the same name (email prefix) are numbered sequentially. For example, "johndoe@exampleA.com" would be assigned username "johndoe", "johndoe@exampleB.com" would be assigned "johndoe001" and so forth..

The use case is that I have a number of subdomains that I am using Bakery on and need to ensure that there aren't any conflicting slave site accounts. The Email registration module will just create a tokenized username with appended unique IDs, creating conflicting accounts.

I figure by forcing email addresses, I can bypass most of this as an issue. How can I completely eliminate the username field and just use email field?

  • If your concern with email registration is the username which is generated then you can override and give your own custom format to generate the username using the hook available function hook_email_registration_name($edit, $account) { return 'u' . $account->uid; } – junedkazi Nov 6 '12 at 21:45
  • Or in your case you could just return $account->mail so your username and email address will be the same. – junedkazi Nov 6 '12 at 21:46
4

Use hook_form_alter to hide the username field

/**
 * Implementation of hook_form_alter.
 */
function mymodule_form_alter(&$form, &$form_state, $form_id){
  if($form['#form_id'] === 'user_register_form'){
    unset($form['account']['name']);
  }
}

Then you can use hook_user_presave to set the username using the convention you want (the md5 hash of the email is a good candidate):

/**
 * Implementation of hook_user_presave.
 */
function mymodule_user_presave(&$edit, $account, $category){
  $edit['name'] = md5($edit['mail']);
}
1

You could still use Email Registration and just implement a custom hook

function modulename_email_registration_name($edit, $account) { 
 return $edit['mail']; 
}
1

A simpler way is to create a new Rule in "Configuration site". You can set an event after creating a new user and then set an action as: user name set to value user email.

0

There is not usual way to force Drupal to only use email and not consider username field, there are some Way to achieve this job with hacking core of Drupal But Strongly NOT Recommended, So the ways remain is filling username field ( as other guys answered) with somethings, there are several ways to fill user name field,

Using Email_registration module with custom hook

function modulename_email_registration_name($edit, $account) { 
 return $edit['mail'];
  // OR 
  // return "YOUR_DESIRE_STRING-".$edit['uid']; 
}

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service, privacy policy and cookie policy