summaryrefslogtreecommitdiff
path: root/modules/user/user.module
diff options
context:
space:
mode:
authorDries Buytaert <dries@buytaert.net>2006-06-11 19:23:47 +0000
committerDries Buytaert <dries@buytaert.net>2006-06-11 19:23:47 +0000
commita3667dc567992d7618fa6c0750a42d872cde92a5 (patch)
tree008be9f6cdbc3f2b13cd73fccdf3cbf6485b661f /modules/user/user.module
parente1a55712ca21d9ab4f4176424833c8a6959ac264 (diff)
downloadbrdo-a3667dc567992d7618fa6c0750a42d872cde92a5.tar.gz
brdo-a3667dc567992d7618fa6c0750a42d872cde92a5.tar.bz2
- Patch #67036 by naudefj: make it possible to add roles from the user creation page.
Diffstat (limited to 'modules/user/user.module')
-rw-r--r--modules/user/user.module30
1 files changed, 22 insertions, 8 deletions
diff --git a/modules/user/user.module b/modules/user/user.module
index ee69debd9..94a473495 100644
--- a/modules/user/user.module
+++ b/modules/user/user.module
@@ -190,12 +190,6 @@ function user_save($account, $array = array(), $category = 'account') {
}
db_query('INSERT INTO {users} ('. implode(', ', $fields) .') VALUES ('. implode(', ', $s) .')', $values);
- // Reload user roles (delete just to be safe).
- db_query('DELETE FROM {users_roles} WHERE uid = %d', $array['uid']);
- foreach ((array)$array['roles'] as $rid) {
- db_query('INSERT INTO {users_roles} (uid, rid) VALUES (%d, %d)', $array['uid'], $rid);
- }
-
// Build the initial user object.
$user = user_load(array('uid' => $array['uid']));
@@ -210,6 +204,14 @@ function user_save($account, $array = array(), $category = 'account') {
}
db_query("UPDATE {users} SET data = '%s' WHERE uid = %d", serialize($data), $user->uid);
+ // Save user roles (delete just to be safe).
+ db_query('DELETE FROM {users_roles} WHERE uid = %d', $array['uid']);
+ foreach (array_keys($array['roles']) as $rid) {
+ if (!in_array($rid, array(DRUPAL_ANONYMOUS_RID, DRUPAL_AUTHENTICATED_RID))) {
+ db_query('INSERT INTO {users_roles} (uid, rid) VALUES (%d, %d)', $array['uid'], $rid);
+ }
+ }
+
// Build the finished user object.
$user = user_load(array('uid' => $array['uid']));
}
@@ -1187,6 +1189,16 @@ function user_register() {
'#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(
'#type' => 'checkbox',
'#title' => t('Notify user of new account')
@@ -1202,8 +1214,9 @@ function user_register() {
$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['notify']);
+ unset($form['name'], $form['mail'], $form['pass'], $form['roles'], $form['notify']);
$form = array_merge($form, $extra);
}
$form['submit'] = array('#type' => 'submit', '#value' => t('Create new account'), '#weight' => 30);
@@ -1223,6 +1236,7 @@ function user_register_submit($form_id, $form_values) {
$mail = $form_values['mail'];
$name = $form_values['name'];
$pass = $admin ? $form_values['pass'] : user_password();
+ $roles = array_filter($form_values['roles']); // Remove unset roles
$notify = $form_values['notify'];
$from = variable_get('site_mail', ini_get('sendmail_from'));
@@ -1231,7 +1245,7 @@ function user_register_submit($form_id, $form_values) {
return 'user/register';
}
- $account = user_save('', array_merge($form_values, array('pass' => $pass, 'init' => $mail, 'status' => ($admin || variable_get('user_register', 1) == 1))));
+ $account = user_save('', array_merge($form_values, array('pass' => $pass, 'init' => $mail, 'roles' => $roles, 'status' => ($admin || variable_get('user_register', 1) == 1))));
watchdog('user', t('New user: %name %email.', array('%name' => theme('placeholder', $name), '%email' => theme('placeholder', '<'. $mail .'>'))), WATCHDOG_NOTICE, l(t('edit'), 'user/'. $account->uid .'/edit'));
$variables = array('%username' => $name, '%site' => variable_get('site_name', 'drupal'), '%password' => $pass, '%uri' => $base_url, '%uri_brief' => substr($base_url, strlen('http://')), '%mailto' => $mail, '%date' => format_date(time()), '%login_uri' => url('user', NULL, NULL, TRUE), '%edit_uri' => url('user/'. $account->uid .'/edit', NULL, NULL, TRUE), '%login_url' => user_pass_reset_url($account));