6

I need to force users to register with just their email. I cannot use the Email Registration module, which still sets the username basing on the user name part of the email; in case of conflicts with existing usernames, a number is added.

I have a number of subdomains where I am using the Bakery module; I need to be sure there isn't any conflicting account. The Email registration module will just create a tokenized username with appended unique IDs, creating conflicting accounts.

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

2
  • 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, 2012 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, 2012 at 21:46

4 Answers 4

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 and acknowledge that you have read and understand our privacy policy and code of conduct.