Closed (fixed)
Project:
Email Registration
Version:
5.x-1.x-dev
Component:
Code
Priority:
Critical
Category:
Bug report
Assigned:
Unassigned
Reporter:
Created:
10 Dec 2008 at 20:04 UTC
Updated:
11 Feb 2009 at 23:02 UTC
I discovered an error while using some other modules (advanced profile, node profile, etc), which modify the user edit form, in part due to the other recent change adding 'update' to the hook_user call.
If the mail field isn't defined/set as part of the submitted form, $namenew ends up (incorrectly) empty, causing the username to be set to "_1" (or similar)
The fix is pretty clear: add a check for $edit['mail'] being nonempty, otherwise, don't do anything.
function email_registration_user($op, &$edit, &$account, $category = NULL) {
switch ($op) {
case 'insert':
case 'update':
if (!empty($edit['mail'])){
$namenew = variable_get('email_registration_eq_email',FALSE) ? $edit['mail'] : preg_replace('/@.*$/', '', $edit['mail']);
// if username generated from email record already exists, append underscore and number eg:(chris_123)
if (db_num_rows(db_query("SELECT uid FROM {users} WHERE uid != %d AND LOWER(name) = LOWER('%s')", $account->uid, $namenew)) > 0) {
// find the next number available to append to the name
$sql = "SELECT SUBSTRING_INDEX(name,'_',-1) FROM {users} WHERE name REGEXP '^%s_[0-9]+$' ORDER BY CAST(SUBSTRING_INDEX(name,'_',-1) AS UNSIGNED) DESC LIMIT 1";
$nameidx = db_result(db_query($sql, $namenew));
$namenew .= '_'. ($nameidx + 1);
}
// replace with generated username
db_query("UPDATE {users} SET name = '%s' WHERE uid = '%s'", $namenew, $account->uid);
}
break;
}
return;
}
Comments
Comment #1
sbandyopadhyay commentedI have folded this patch into a master patch to the 5.x-1.x-dev version for easy updating on several issues: #366504: Master patch combining several recent issues.
Comment #2
Christopher Herberte commentedpatch applied to head