The project page mentions the automatic account name creation by taking the first part of the email address.
This does not occur however, the account name created is a random set of characters, i.e. onvUp7moby
This random account name appears everywhere in the site, and is very user unfriendly.
I need the account to show the (first part of the0 email address as username.

Support from Acquia helps fund testing for Drupal Acquia logo

Comments

Spleshka’s picture

I've got the same issue.

hook_user_insert() works not properly in your case. It's better to change user name on submit callback. That works for me. Patch attached.

Spleshka’s picture

Status: Active » Needs review
FileSize
2.37 KB

If you wanna to save hook_email_registration_name() you should use this patch.

andypost’s picture

Status: Needs review » Needs work

This way is wrong, deprecating hook_user_insert() will kill ability to generate names by fedds and programmatic way

suppose you should dig deeper and find a real cause of the error

Spleshka’s picture

But why can't I use my method? Is it wrong?

andypost’s picture

Status: Needs work » Fixed

You could implement hook_email_registration_name() in custom module to generate a user name as you need

Spleshka’s picture

Andy, please pay attention at the second patch. I kept possibility to implement hook_email_registration_name().

andypost’s picture

Status: Fixed » Needs work
+++ b/email_registration.module
@@ -6,9 +6,22 @@
- * Implements hook_user_insert().

@@ -28,39 +41,16 @@ function email_registration_user_insert(&$edit, &$account, $category = NULL) {
-  global $user;
-  if (!variable_get('user_email_verification', 1) && $user->uid == 0) {

as I said - users could be created by migrate|feeds or other programmatic way so this hook is required!

+++ b/email_registration.module
@@ -28,39 +41,16 @@ function email_registration_user_insert(&$edit, &$account, $category = NULL) {
-  global $user;
-  if (!variable_get('user_email_verification', 1) && $user->uid == 0) {

Also your patch removes this general ability

Spleshka’s picture

Sure, because Drupal will make it for me. If email verification is disabled I will be logged in automatically without this peace of code.

greggles’s picture

Title: Account name is not the first email part, but random characters » Switch from hook_user_insert to submit handler so the code fires earlier
Version: 7.x-1.0 » 7.x-1.x-dev

My sense is that the key part is:

+  // Provide first submit callback for user register form
+  array_unshift($form['#submit'], 'email_registration_user_regiser_form_submit');

That should let this code run very early in the registration process (before hook_user_insert is called) so that this module can generate a more reasonable username quickly.

I've updated the title to reflect that idea. I am not affected by this issue personally but am open to the change as long as it maintains the ability to override the name change via hook_email_registration_name.

greggles’s picture

Well, that said...this needs to work also with sites that create user's via user_save instead of the registration form so it will need to be smart about doing both.

greggles’s picture

Marked #1410994: Flaw in when the username gets created as a duplicate. It has the idea that some of this module's code should be moved to a validate hook for the form-based user creation so that it runs even before the submit function. As I think about that more, I think that just making this module's submit handler the first is the best idea.

kevin.klika’s picture

greggles, how would you resolve this issue? When using email_registration for standard registration, everything works fine -- however when I use it with drupal commerce (commerce kickstart, to be specific), this problem rears it's head. Every user gets an email with their new username (correct), then another email that specifies a random username. (in fact, now all of my users get a username like "email_registration_[random-characters]").
Is there a weight I can modify or something I can do to prevent this 'secondary' username generation?

greggles’s picture

I don't think this issue is the right one to resolve that problem. Can you create a new issue?

kevin.klika’s picture

sorry greggles, this is the exact issue I am having. I think I explained it poorly. Is there a patch against the current dev version to change these hooks? I can't get this module to work without it setting a random string as the username -- user even gets two emails -- one correct and one wrong. Even more oddly, the correct email comes first and the wrong one is sent after:-x

greggles’s picture

I created #1899720: Support commerce setting to create users during checkout. As I said there it's probably worth saying here - I'm not affected by this bug so I don't plan to work on it but I am happy to review a patch.