summaryrefslogtreecommitdiff
diff options
context:
space:
mode:
-rw-r--r--modules/user/user.module24
1 files changed, 12 insertions, 12 deletions
diff --git a/modules/user/user.module b/modules/user/user.module
index 97835baff..f97811cc1 100644
--- a/modules/user/user.module
+++ b/modules/user/user.module
@@ -674,7 +674,7 @@ function user_user_view(&$edit, &$account, $category = NULL) {
function user_user_form(&$edit, &$account, $category = NULL) {
if ($category == 'account') {
$form_state = array();
- return user_edit_form($form_state, arg(1), $edit);
+ return user_edit_form($form_state, (isset($account->uid) ? $account->uid : FALSE), $edit);
}
}
@@ -683,7 +683,7 @@ function user_user_form(&$edit, &$account, $category = NULL) {
*/
function user_user_validate(&$edit, &$account, $category = NULL) {
if ($category == 'account') {
- return _user_edit_validate(arg(1), $edit);
+ return _user_edit_validate($account, $edit);
}
}
@@ -692,7 +692,7 @@ function user_user_validate(&$edit, &$account, $category = NULL) {
*/
function user_user_submit(&$edit, &$account, $category = NULL) {
if ($category == 'account') {
- return _user_edit_submit(arg(1), $edit);
+ return _user_edit_submit($account, $edit);
}
}
@@ -1458,7 +1458,8 @@ function user_edit_form(&$form_state, $uid, $edit, $register = FALSE) {
'#title' => t('Account information'),
'#weight' => -10,
);
- if (user_access('change own username') || $admin || $register) {
+ // 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',
'#title' => t('Username'),
'#default_value' => $edit['name'],
@@ -1559,10 +1560,10 @@ function user_edit_form(&$form_state, $uid, $edit, $register = FALSE) {
return $form;
}
-function _user_edit_validate($uid, &$edit) {
- $user = user_load(array('uid' => $uid));
- // Validate the username:
- if (user_access('change own username') || user_access('administer users') || !$user->uid) {
+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);
}
@@ -1580,12 +1581,11 @@ function _user_edit_validate($uid, &$edit) {
}
}
-function _user_edit_submit($uid, &$edit) {
- $user = user_load(array('uid' => $uid));
+function _user_edit_submit($account, &$edit) {
// Delete picture if requested, and if no replacement picture was given.
if (!empty($edit['picture_delete'])) {
- if ($user->picture && file_exists($user->picture)) {
- file_unmanaged_delete($user->picture);
+ if ($account->picture && file_exists($account->picture)) {
+ file_unmanaged_delete($account->picture);
}
$edit['picture'] = '';
}