diff --git a/core/modules/user/user.install b/core/modules/user/user.install index 492f1e0..2a8a29c 100644 --- a/core/modules/user/user.install +++ b/core/modules/user/user.install @@ -133,6 +133,13 @@ function user_schema() { 'default' => '', 'description' => 'E-mail address used for initial account creation.', ), + 'anonymous' => array( + 'type' => 'int', + 'not null' => TRUE, + 'default' => 0, + 'size' => 'tiny', + 'description' => 'Whether this user is anonymous (1) or registered (0)', + ), 'data' => array( 'type' => 'blob', 'not null' => FALSE, @@ -599,5 +606,21 @@ function user_update_8009(&$sandbox) { } /** + * Add an anonymous flag to the user table. + */ +function user_update_8010(&$sandbox) { + db_add_field('users', 'anonymous', array( + 'type' => 'int', + 'not null' => TRUE, + 'default' => 0, + 'size' => 'tiny', + 'description' => 'Whether this user is anonymous (1) or registered (0)', + )); + + // Set user to be anonymous + db_query('UPDATE {users} SET anonymous = 1 WHERE uid = 0'); +} + +/** * @} End of "addtogroup updates-7.x-to-8.x". */ diff --git a/core/modules/user/user.module b/core/modules/user/user.module index c064427..794857a 100644 --- a/core/modules/user/user.module +++ b/core/modules/user/user.module @@ -555,6 +555,25 @@ function user_is_blocked($name) { } /** + * Checks if a username is registered. + * + * @param $name + * A string containing the name of the user. + * + * @return + * True if the user is registered, false if they are anonymous. + */ +function user_is_registered($name) { + $result = db_select('users') + ->fields('users', array('name', 'uid')) + ->condition('name', db_like($name), 'LIKE') + ->condition('anonymous', 0) + ->execute()->fetchObject(); + + return ($result) ? TRUE : FALSE; +} + +/** * Implements hook_permission(). */ function user_permission() { @@ -1629,6 +1648,11 @@ function user_login_default_validators() { * 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_registered($form_state['values']['name'])) { + // Not a registered account. + form_set_error('name', t('No registered account exists with the username %name', array('%name' => $form_state['values']['name']))); + } + if (isset($form_state['values']['name']) && user_is_blocked($form_state['values']['name'])) { // 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']))); @@ -1653,7 +1677,7 @@ function user_login_authenticate_validate($form, &$form_state) { $form_state['flood_control_triggered'] = 'ip'; return; } - $account = db_query("SELECT * FROM {users} WHERE name = :name AND status = 1", array(':name' => $form_state['values']['name']))->fetchObject(); + $account = db_query("SELECT * FROM {users} WHERE name = :name AND status = 1 AND anonymous = 0", array(':name' => $form_state['values']['name']))->fetchObject(); if ($account) { if ($flood_config->get('uid_only')) { // Register flood events based on the uid only, so they apply for any