--- user.module.old 2006-06-03 00:41:34.000000000 -0500 +++ user.module 2006-06-04 03:46:32.000000000 -0500 @@ -189,12 +189,6 @@ } 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'])); @@ -209,6 +203,14 @@ } 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'])); } @@ -1186,6 +1188,16 @@ '#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 %au role, and all roles selected here.', array('%au' => theme('placeholder', t('authenticated user')))) + ); + } $form['notify'] = array( '#type' => 'checkbox', '#title' => t('Notify user of new account') @@ -1199,8 +1211,9 @@ $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); @@ -1220,6 +1233,7 @@ $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')); @@ -1228,7 +1242,7 @@ 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));