From 424cf1b18252389fbfbed6b0d7d30ec552a64e1e Mon Sep 17 00:00:00 2001 From: Angie Byron Date: Tue, 13 Jan 2009 06:27:01 +0000 Subject: [PATCH] #358021 by drewish: Remove unnecessary indirection of hook_user_X code. --- modules/user/user.module | 64 ++++++++++++++++++---------------------- 1 file changed, 28 insertions(+), 36 deletions(-) diff --git a/modules/user/user.module b/modules/user/user.module index 431a9477387..092c64e715b 100644 --- a/modules/user/user.module +++ b/modules/user/user.module @@ -692,7 +692,24 @@ function user_user_form(&$edit, &$account, $category = NULL) { */ function user_user_validate(&$edit, &$account, $category = NULL) { if ($category == 'account') { - return _user_edit_validate($account, $edit); + $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); + } + 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']))); + } + } + + // Validate the e-mail address: + if ($error = user_validate_mail($edit['mail'])) { + form_set_error('mail', $error); + } + elseif (db_result(db_query("SELECT COUNT(*) FROM {users} WHERE uid != %d AND LOWER(mail) = LOWER('%s')", $uid, $edit['mail'])) > 0) { + form_set_error('mail', t('The e-mail address %email is already registered. Have you forgotten your password?', array('%email' => $edit['mail'], '@password' => url('user/password')))); + } } } @@ -701,7 +718,16 @@ function user_user_validate(&$edit, &$account, $category = NULL) { */ function user_user_submit(&$edit, &$account, $category = NULL) { if ($category == 'account') { - return _user_edit_submit($account, $edit); + // Delete picture if requested, and if no replacement picture was given. + if (!empty($edit['picture_delete'])) { + if ($account->picture && file_exists($account->picture)) { + file_unmanaged_delete($account->picture); + } + $edit['picture'] = ''; + } + if (isset($edit['roles'])) { + $edit['roles'] = array_filter($edit['roles']); + } } } @@ -1599,40 +1625,6 @@ function user_edit_form(&$form_state, $uid, $edit, $register = FALSE) { return $form; } -function _user_edit_validate($account, &$edit) { - $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); - } - 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']))); - } - } - - // Validate the e-mail address: - if ($error = user_validate_mail($edit['mail'])) { - form_set_error('mail', $error); - } - elseif (db_result(db_query("SELECT COUNT(*) FROM {users} WHERE uid != %d AND LOWER(mail) = LOWER('%s')", $uid, $edit['mail'])) > 0) { - form_set_error('mail', t('The e-mail address %email is already registered. Have you forgotten your password?', array('%email' => $edit['mail'], '@password' => url('user/password')))); - } -} - -function _user_edit_submit($account, &$edit) { - // Delete picture if requested, and if no replacement picture was given. - if (!empty($edit['picture_delete'])) { - if ($account->picture && file_exists($account->picture)) { - file_unmanaged_delete($account->picture); - } - $edit['picture'] = ''; - } - if (isset($edit['roles'])) { - $edit['roles'] = array_filter($edit['roles']); - } -} - /** * Cancel a user account. *