Index: install.php =================================================================== RCS file: /cvs/drupal/drupal/install.php,v retrieving revision 1.159 diff -u -r1.159 install.php --- install.php 1 Mar 2009 09:32:16 -0000 1.159 +++ install.php 8 Mar 2009 19:51:07 -0000 @@ -988,7 +988,7 @@ '#weight' => -10, ); - $form['admin_account']['account']['name'] = array('#type' => 'textfield', + $form['admin_account']['account']['name_login'] = array('#type' => 'textfield', '#title' => st('Username'), '#maxlength' => USERNAME_MAX_LENGTH, '#description' => st('Spaces are allowed; punctuation is not allowed except for periods, hyphens, and underscores.'), @@ -1069,7 +1069,7 @@ * Form API validate for the site configuration form. */ function install_configure_form_validate($form, &$form_state) { - if ($error = user_validate_name($form_state['values']['account']['name'])) { + if ($error = user_validate_name($form_state['values']['account']['name_login'])) { form_error($form['admin_account']['account']['name'], $error); } if ($error = user_validate_mail($form_state['values']['account']['mail'])) { Index: modules/system/system.install =================================================================== RCS file: /cvs/drupal/drupal/modules/system/system.install,v retrieving revision 1.311 diff -u -r1.311 system.install --- modules/system/system.install 1 Mar 2009 09:32:17 -0000 1.311 +++ modules/system/system.install 8 Mar 2009 19:51:07 -0000 @@ -342,17 +342,17 @@ // uid 2 which is not what we want. So we insert the first user here, the // anonymous user. uid is 1 here for now, but very soon it will be changed // to 0. - db_query("INSERT INTO {users} (name, mail) VALUES('%s', '%s')", '', ''); + db_query("INSERT INTO {users} (name, name_login, mail) VALUES('%s', '%s', '%s')", '', '', ''); // We need some placeholders here as name and mail are uniques and data is // presumed to be a serialized array. Install will change uid 1 immediately // anyways. So we insert the superuser here, the uid is 2 here for now, but // very soon it will be changed to 1. - db_query("INSERT INTO {users} (name, mail, created, status, data) VALUES('%s', '%s', %d, %d, '%s')", 'placeholder-for-uid-1', 'placeholder-for-uid-1', REQUEST_TIME, 1, serialize(array())); + db_query("INSERT INTO {users} (name, name_login, mail, created, status, data) VALUES('%s', '%s', '%s', %d, %d, '%s')", 'placeholder-for-uid-1', 'placeholder-for-uid-1', 'placeholder-for-uid-1', REQUEST_TIME, 1, serialize(array())); // This sets the above two users uid 0 (anonymous). We avoid an explicit 0 // otherwise MySQL might insert the next auto_increment value. db_query("UPDATE {users} SET uid = uid - uid WHERE name = '%s'", ''); // This sets uid 1 (superuser). We skip uid 2 but that's not a big problem. - db_query("UPDATE {users} SET uid = 1 WHERE name = '%s'", 'placeholder-for-uid-1'); + db_query("UPDATE {users} SET uid = 1 WHERE name_login = '%s'", 'placeholder-for-uid-1'); // Built-in roles. db_query("INSERT INTO {role} (name) VALUES ('%s')", 'anonymous user'); Index: modules/user/user.install =================================================================== RCS file: /cvs/drupal/drupal/modules/user/user.install,v retrieving revision 1.19 diff -u -r1.19 user.install --- modules/user/user.install 26 Feb 2009 07:30:29 -0000 1.19 +++ modules/user/user.install 8 Mar 2009 19:51:07 -0000 @@ -101,7 +101,14 @@ 'length' => 60, 'not null' => TRUE, 'default' => '', - 'description' => 'Unique user name.', + 'description' => 'Display name.', + ), + 'name_login' => array( + 'type' => 'varchar', + 'length' => 60, + 'not null' => TRUE, + 'default' => '', + 'description' => 'Unique name for authentication.', ), 'pass' => array( 'type' => 'varchar', @@ -196,7 +203,7 @@ 'mail' => array('mail'), ), 'unique keys' => array( - 'name' => array('name'), + 'name_login' => array('name_login'), ), 'primary key' => array('uid'), ); @@ -463,6 +470,24 @@ return $ret; } +function user_update_7005() { + $ret = array(); + + // New column for unique login name. + db_add_column($ret, 'users', 'name_login', 'varchar', + array('not null' => TRUE, 'default' => '')); + db_add_unique_key($ret, 'users', 'name_login', array('name_login')); + + // Default for display name is same as login name. + // Can this be done via db_update??? + $ret[] = update_sql('UPDATE {users} SET name_login=name WHERE 1'); + + // Display name need not be unique + db_drop_unique_key($ret, 'users', 'name'); + + return $ret; +} + /** * @} End of "defgroup user-updates-6.x-to-7.x" * The next series of updates should start at 8000. Index: modules/user/user.module =================================================================== RCS file: /cvs/drupal/drupal/modules/user/user.module,v retrieving revision 1.966 diff -u -r1.966 user.module --- modules/user/user.module 26 Feb 2009 07:30:29 -0000 1.966 +++ modules/user/user.module 8 Mar 2009 19:51:08 -0000 @@ -283,8 +283,14 @@ $edit = (array) $edit; + // Display name defaults to login name. + if (!isset($edit['name'])) { + $edit['name'] = $edit['name_login']; + } + if (is_object($account) && $account->uid) { user_module_invoke('update', $edit, $account, $category); + $data = unserialize(db_result(db_query('SELECT data FROM {users} WHERE uid = %d', $account->uid))); // Consider users edited by an administrator as logged in, if they haven't // already, so anonymous users can view the profile (if allowed). @@ -644,7 +650,7 @@ * @return boolean TRUE for blocked users, FALSE for active. */ function user_is_blocked($name) { - $deny = db_fetch_object(db_query("SELECT name FROM {users} WHERE status = 0 AND name = LOWER('%s')", $name)); + $deny = db_fetch_object(db_query("SELECT name_login FROM {users} WHERE status = 0 AND name_login = LOWER('%s')", $name)); return $deny; } @@ -804,11 +810,11 @@ $uid = isset($account->uid) ? $account->uid : FALSE; // Validate the username when: new user account; or user is editing own account and can change username; or an admin user. if (!$uid || ($GLOBALS['user']->uid == $uid && user_access('change own username')) || user_access('administer users')) { - if ($error = user_validate_name($edit['name'])) { - form_set_error('name', $error); + if ($error = user_validate_name($edit['name_login'])) { + form_set_error('name_login', $error); } - elseif (db_result(db_query("SELECT COUNT(*) FROM {users} WHERE uid != %d AND LOWER(name) = LOWER('%s')", $uid, $edit['name'])) > 0) { - form_set_error('name', t('The name %name is already taken.', array('%name' => $edit['name']))); + elseif (db_result(db_query("SELECT COUNT(*) FROM {users} WHERE uid != %d AND LOWER(name_login) = LOWER('%s')", $uid, $edit['name_login'])) > 0) { + form_set_error('name_login', t('The name %name is already taken.', array('%name' => $edit['name_login']))); } } @@ -864,7 +870,7 @@ '#validate' => user_login_default_validators(), '#submit' => array('user_login_submit'), ); - $form['name'] = array('#type' => 'textfield', + $form['name_login'] = array('#type' => 'textfield', '#title' => t('Username'), '#maxlength' => USERNAME_MAX_LENGTH, '#size' => 15, @@ -1455,7 +1461,7 @@ } // Display login form: - $form['name'] = array('#type' => 'textfield', + $form['name_login'] = array('#type' => 'textfield', '#title' => t('Username'), '#size' => 60, '#maxlength' => USERNAME_MAX_LENGTH, @@ -1463,7 +1469,7 @@ '#attributes' => array('tabindex' => '1'), ); - $form['name']['#description'] = t('Enter your @s username.', array('@s' => variable_get('site_name', 'Drupal'))); + $form['name_login']['#description'] = t('Enter your @s username.', array('@s' => variable_get('site_name', 'Drupal'))); $form['pass'] = array('#type' => 'password', '#title' => t('Password'), '#description' => t('Enter the password that accompanies your username.'), @@ -1501,9 +1507,9 @@ * A FAPI validate handler. Sets an error if supplied username has been blocked. */ function user_login_name_validate($form, &$form_state) { - if (isset($form_state['values']['name']) && user_is_blocked($form_state['values']['name'])) { + if (isset($form_state['values']['name_login']) && user_is_blocked($form_state['values']['name_login'])) { // Blocked in user administration. - form_set_error('name', t('The username %name has not been activated or is blocked.', array('%name' => $form_state['values']['name']))); + form_set_error('name_login', t('The username %name has not been activated or is blocked.', array('%name' => $form_state['values']['name_login']))); } } @@ -1522,8 +1528,8 @@ function user_login_final_validate($form, &$form_state) { global $user; if (!$user->uid) { - form_set_error('name', t('Sorry, unrecognized username or password. Have you forgotten your password?', array('@password' => url('user/password')))); - watchdog('user', 'Login attempt failed for %user.', array('%user' => $form_state['values']['name'])); + form_set_error('name_login', t('Sorry, unrecognized username or password. Have you forgotten your password?', array('@password' => url('user/password')))); + watchdog('user', 'Login attempt failed for %user.', array('%user' => $form_state['values']['name_login'])); } } @@ -1531,7 +1537,7 @@ * Try to log in the user locally. * * @param $form_values - * Form values with at least 'name' and 'pass' keys, as well as anything else + * Form values with at least 'name_login' and 'pass' keys, as well as anything else * which should be passed along to hook_user op 'login'. * * @return @@ -1542,8 +1548,8 @@ $password = trim($form_values['pass']); // Name and pass keys are required. - if (!empty($form_values['name']) && !empty($password)) { - $account = db_fetch_object(db_query("SELECT * FROM {users} WHERE name = '%s' AND status = 1", $form_values['name'])); + if (!empty($form_values['name_login']) && !empty($password)) { + $account = db_fetch_object(db_query("SELECT * FROM {users} WHERE name_login = '%s' AND status = 1", $form_values['name_login'])); if ($account) { // Allow alternate password hashing schemes. require_once DRUPAL_ROOT . '/' . variable_get('password_inc', 'includes/password.inc'); @@ -1608,14 +1614,14 @@ function user_external_login_register($name, $module) { global $user; - $existing_user = user_load(array('name' => $name)); + $existing_user = user_load(array('name_login' => $name)); if (isset($existing_user->uid)) { $user = $existing_user; } else { // Register this new user. $userinfo = array( - 'name' => $name, + 'name_login' => $name, 'pass' => user_password(), 'init' => $name, 'status' => 1, @@ -1666,9 +1672,9 @@ ); // Only show name field when: registration page; or user is editing own account and can change username; or an admin user. if ($register || ($GLOBALS['user']->uid == $uid && user_access('change own username')) || $admin) { - $form['account']['name'] = array('#type' => 'textfield', + $form['account']['name_login'] = array('#type' => 'textfield', '#title' => t('Username'), - '#default_value' => $edit['name'], + '#default_value' => $edit['name_login'], '#maxlength' => USERNAME_MAX_LENGTH, '#description' => t('Spaces are allowed; punctuation is not allowed except for periods, hyphens, apostrophes, and underscores.'), '#required' => TRUE, @@ -2611,7 +2617,12 @@ $admin = user_access('administer users'); $mail = $form_state['values']['mail']; - $name = $form_state['values']['name']; + $name_login = $form_state['values']['name_login']; + // Display name defaults to login name, if no modules have provided it. + if (!isset($form_state['values']['name'])) { + $form_state['values']['name'] = $name_login; + } + if (!variable_get('user_email_verification', TRUE) || $admin) { $pass = $form_state['values']['pass']; } @@ -2651,7 +2662,7 @@ } $form_state['user'] = $account; - watchdog('user', 'New user: %name (%email).', array('%name' => $name, '%email' => $mail), WATCHDOG_NOTICE, l(t('edit'), 'user/' . $account->uid . '/edit')); + watchdog('user', 'New user: %name (%email).', array('%name' => $name_login, '%email' => $mail), WATCHDOG_NOTICE, l(t('edit'), 'user/' . $account->uid . '/edit')); // The first user may login immediately, and receives a customized welcome e-mail. if ($account->uid == 1) { @@ -2669,7 +2680,7 @@ // Add plain text password into user account to generate mail tokens. $account->password = $pass; if ($admin && !$notify) { - drupal_set_message(t('Created a new user account for %name. No e-mail has been sent.', array('@url' => url("user/$account->uid"), '%name' => $account->name))); + drupal_set_message(t('Created a new user account for %name. No e-mail has been sent.', array('@url' => url("user/$account->uid"), '%name' => $account->name_login))); } elseif (!variable_get('user_email_verification', TRUE) && $account->status && !$admin) { // No e-mail verification is required, create new user account, and login @@ -2686,7 +2697,7 @@ $op = $notify ? 'register_admin_created' : 'register_no_approval_required'; _user_mail_notify($op, $account); if ($notify) { - drupal_set_message(t('Password and further instructions have been e-mailed to the new user %name.', array('@url' => url("user/$account->uid"), '%name' => $account->name))); + drupal_set_message(t('Password and further instructions have been e-mailed to the new user %name.', array('@url' => url("user/$account->uid"), '%name' => $account->name_login))); } else { drupal_set_message(t('Your password and further instructions have been sent to your e-mail address.')); @@ -2747,7 +2758,7 @@ // Remove form_group around default fields if there are no other groups. if (!$extra) { - foreach (array('name', 'mail', 'pass', 'status', 'roles', 'notify') as $key) { + foreach (array('name_login', 'mail', 'pass', 'status', 'roles', 'notify') as $key) { if (isset($form['account'][$key])) { $form[$key] = $form['account'][$key]; } Index: modules/user/user.pages.inc =================================================================== RCS file: /cvs/drupal/drupal/modules/user/user.pages.inc,v retrieving revision 1.30 diff -u -r1.30 user.pages.inc --- modules/user/user.pages.inc 26 Feb 2009 07:30:29 -0000 1.30 +++ modules/user/user.pages.inc 8 Mar 2009 19:51:08 -0000 @@ -12,9 +12,9 @@ function user_autocomplete($string = '') { $matches = array(); if ($string) { - $result = db_query_range("SELECT name FROM {users} WHERE LOWER(name) LIKE LOWER(:name)", array(':name' => $string .'%'), 0, 10); + $result = db_query_range("SELECT name_login FROM {users} WHERE LOWER(name_login) LIKE LOWER(:name)", array(':name' => $string .'%'), 0, 10); while ($user = db_fetch_object($result)) { - $matches[$user->name] = check_plain($user->name); + $matches[$user->name_login] = check_plain($user->name_login); } }