Hi, I'm implementing hook_email_registration_name() in my own module, and noticed that if the username I'm passing in has already been generated, an error is thrown and the user creation fails. I think it would be better if the module checked for an existing username when using the hook, the same way it does when the module itself is generating the username.
I've moved the duplicate name check out into its own function to avoid code duplication. Patch to follow momentarily.
Please take a moment to review this if you can. It's my first contributed patch, hope I've done it right!
Comments
Comment #1
kris_mcl commentedHere's my patch. I've tested it using the following steps:
1 - In a custom module, implement hook_email_registration_name()
2 - Create a new user with first name Joey
3 - Create a second user with the exact same first name
4 - Note that the second user's username will be set to "Joey_2".
Without this patch, you will receive an error after step 3 as the username Joey already exists in the system.
Comment #2
andyposttrailing whitespace
this query should be simplified and probably should be replaced according #1430058: email_registration_user_insert isn't compatible with SQL Server
Comment #3
gregglesI didn't see this issue before and made a change that should fix this in #421078: Abstract name unique check for re-use, make it is cross-database compatible, make it more robust, us it on external names. The two changes are in such close areas of code so marking this issue as a duplicate of that.
@kris_mcl - could you test out that other patch?
Comment #4
gclicon commentedAnother issue to account for is that with a presave, the $account doesn't have a UID yet so you email_registration_unique_username is passed a null value as the second parameter. This causes the email_registration_unique_username function to not match with any existing usernames.