summaryrefslogtreecommitdiff
path: root/modules/user/user.module
diff options
context:
space:
mode:
Diffstat (limited to 'modules/user/user.module')
-rw-r--r--modules/user/user.module83
1 files changed, 36 insertions, 47 deletions
diff --git a/modules/user/user.module b/modules/user/user.module
index d1b2ab8db..f4b259014 100644
--- a/modules/user/user.module
+++ b/modules/user/user.module
@@ -1123,6 +1123,8 @@ function user_register() {
drupal_goto('user/'. $user->uid);
}
+ $form = array();
+
// Display the registration form.
if (!$admin) {
$form['user_registration_help'] = array('#type' => 'markup', '#value' => filter_xss_admin(variable_get('user_registration_help', '')));
@@ -1132,37 +1134,10 @@ function user_register() {
$affiliates = implode(', ', $affiliates);
$form['affiliates'] = array('#type' => 'markup', '#value' => '<p>'. t('Note: if you have an account with one of our affiliates (%s), you may <a href="%login_uri">login now</a> instead of registering.', array('%s' => $affiliates, '%login_uri' => url('user'))) .'</p>');
}
- $form['name'] = array('#type' => 'textfield',
- '#title' => t('Username'),
- '#size' => 30,
- '#maxlength' => 60,
- '#description' => t('Your full name or your preferred username; only letters, numbers and spaces are allowed.'),
- '#required' => TRUE);
- $form['mail'] = array('#type' => 'textfield',
- '#title' => t('E-mail address'),
- '#size' => 30,
- '#maxlength' => 64,
- '#description' => t('A password and instructions will be sent to this e-mail address, so make sure it is accurate.'),
- '#required' => TRUE,
- );
+ // Merge in the default user edit fields.
+ $form = array_merge($form, user_edit_form(NULL, NULL, TRUE));
if ($admin) {
- $form['pass'] = array('#type' => 'password',
- '#title' => t('Password'),
- '#size' => 30,
- '#description' => t('Provide a password for the new account.'),
- '#required' => TRUE,
- );
- $roles = user_roles(1);
- unset($roles[DRUPAL_AUTHENTICATED_RID]);
- if ($roles) {
- $form['roles'] = array('#type' => 'checkboxes',
- '#title' => t('Roles'),
- '#default_value' => array_keys((array)$edit['roles']),
- '#options' => $roles,
- '#description' => t('The user receives the combined permissions of the authenticated user role and all roles selected here.')
- );
- }
- $form['notify'] = array(
+ $form['account']['notify'] = array(
'#type' => 'checkbox',
'#title' => t('Notify user of new account')
);
@@ -1171,15 +1146,17 @@ function user_register() {
}
$extra = _user_forms($null, $null, $null, 'register');
- // Only display form_group around default fields if there are other groups.
- if ($extra) {
- $form['account'] = array('#type' => 'fieldset', '#title' => t('Account information'));
- $form['account']['name'] = $form['name'];
- $form['account']['mail'] = $form['mail'];
- $form['account']['pass'] = $form['pass'];
- $form['account']['roles'] = $form['roles'];
- $form['account']['notify'] = $form['notify'];
- unset($form['name'], $form['mail'], $form['pass'], $form['roles'], $form['notify']);
+ // Remove form_group around default fields if there are no other groups.
+ if (!$extra) {
+ $form['name'] = $form['account']['name'];
+ $form['mail'] = $form['account']['mail'];
+ $form['pass'] = $form['account']['pass'];
+ $form['status'] = $form['account']['status'];
+ $form['roles'] = $form['account']['roles'];
+ $form['notify'] = $form['account']['notify'];
+ unset($form['account']);
+ }
+ else {
$form = array_merge($form, $extra);
}
$form['submit'] = array('#type' => 'submit', '#value' => t('Create new account'), '#weight' => 30);
@@ -1259,12 +1236,14 @@ function user_register_submit($form_id, $form_values) {
}
}
-function user_edit_form($uid, $edit) {
+function user_edit_form($uid, $edit, $register = FALSE) {
+ $admin = user_access('administer users');
+
// Account information:
$form['account'] = array('#type' => 'fieldset',
'#title' => t('Account information'),
);
- if (user_access('change own username') || user_access('administer users')) {
+ if (user_access('change own username') || $admin) {
$form['account']['name'] = array('#type' => 'textfield',
'#title' => t('Username'),
'#default_value' => $edit['name'],
@@ -1280,12 +1259,22 @@ function user_edit_form($uid, $edit) {
'#description' => t('Insert a valid e-mail address. All e-mails from the system will be sent to this address. The e-mail address is not made public and will only be used if you wish to receive a new password or wish to receive certain news or notifications by e-mail.'),
'#required' => TRUE,
);
- $form['account']['pass'] = array('#type' => 'password_confirm',
- '#title' => t('Password'),
- '#description' => t('To change the current user password, enter the new password in both fields.'),
- );
- if (user_access('administer users')) {
- $form['account']['status'] = array('#type' => 'radios', '#title' => t('Status'), '#default_value' => $edit['status'], '#options' => array(t('Blocked'), t('Active')));
+ if (!$register) {
+ $form['account']['pass'] = array('#type' => 'password_confirm',
+ '#title' => t('Password'),
+ '#description' => t('To change the current user password, enter the new password in both fields.'),
+ );
+ }
+ elseif ($register && $admin) {
+ $form['account']['pass'] = array('#type' => 'password',
+ '#title' => t('Password'),
+ '#size' => 30,
+ '#description' => t('Provide a password for the new account.'),
+ '#required' => TRUE,
+ );
+ }
+ if ($admin) {
+ $form['account']['status'] = array('#type' => 'radios', '#title' => t('Status'), '#default_value' => isset($edit['status']) ? $edit['status'] : 1, '#options' => array(t('Blocked'), t('Active')));
}
if (user_access('administer access control')) {
$roles = user_roles(1);