Commit 2281088a authored by Steve Gerbino's avatar Steve Gerbino

* Modifications to hook_user_presave()

parent deda84cd
......@@ -71,12 +71,16 @@ function realname_registration_user_presave(&$edit, $account, $category) {
$first_init = drupal_substr($edit['firstname'], 0, 1);
$lastname = $edit['lastname'];
$username = strtolower($first_init . $lastname);
$original_username = $username;
$i = 0;
// Check if the username already exists in the database.
$result = db_query("SELECT name FROM {users} WHERE name = :username", array(':username' => $username));
// While the username is taken, append a number and increment it until our username is unique.
while (db_query("SELECT name FROM {users} WHERE name = :username", array(':username' => $username))) {
$username = $original_username . ++$i;
$i = 0;
while ($result->rowCount()) {
$result = db_query("SELECT name FROM {users} WHERE name = :username", array(':username' => $username . ++$i));
if (!($result->rowCount())) {
$username = $username . $i;
}
}
$edit['name'] = $username;
}
......
Markdown is supported
0% or
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment