Commit 8c07aaa9 authored by Steven Wittens's avatar Steven Wittens

#10733: fixing problems when creating users.

parent f6033d29
......@@ -928,7 +928,6 @@ function user_register($edit = array()) {
}
if ($edit) {
$edit['roles'] = array(_user_authenticated_id()); // needed for validation
user_module_invoke('validate', $edit, $edit, 'account');
if (!form_get_errors()) {
......@@ -937,7 +936,7 @@ function user_register($edit = array()) {
// TODO: Is this necessary? Won't session_write() replicate this?
unset($edit['session']);
$account = user_save('', array('name' => $edit['name'], 'pass' => $pass, 'init' => $edit['mail'], 'mail' => $edit['mail'], 'roles' => $edit['roles'], 'status' => (variable_get('user_register', 1) == 1 ? 1 : 0)));
$account = user_save('', array('name' => $edit['name'], 'pass' => $pass, 'init' => $edit['mail'], 'mail' => $edit['mail'], 'roles' => array(_user_authenticated_id()), 'status' => (variable_get('user_register', 1) == 1 ? 1 : 0)));
watchdog('user', t('New user: %name %e-mail.', array('%name' => '<em>'. $edit['name'] .'</em>', '%e-mail' => '<em>&lt;'. $edit['mail'] .'&gt;</em>')), l(t('edit'), 'user/'. $account->uid .'/edit'));
$variables = array('%username' => $edit['name'], '%site' => variable_get('site_name', 'drupal'), '%password' => $pass, '%uri' => $base_url, '%uri_brief' => substr($base_url, strlen('http://')), '%mailto' => $edit['mail'], '%date' => format_date(time()), '%login_uri' => url('user/login', NULL, NULL, TRUE), '%edit_uri' => url('user/'. $account->uid .'/edit', NULL, NULL, TRUE));
......@@ -1043,7 +1042,7 @@ function user_edit_validate($uid, &$edit) {
}
// Validate the roles
if (!$edit['roles']) {
if (user_access('administer users') && !$edit['roles']) {
form_set_error('roles', t('You must select at least one role.'));
$edit['roles'] = array();
}
......@@ -1271,12 +1270,14 @@ function user_configure_settings() {
function user_admin_create($edit = array()) {
if ($edit) {
// Because the admin form doesn't have roles selection they need to be set to validate properly
$edit['roles'] = array(_user_authenticated_id());
user_module_invoke('validate', $edit, $edit, 'account');
if (!form_get_errors()) {
watchdog('user', t('New user: %name %e-mail.', array('%name' => '<em>'. $edit['name'] .'</em>', '%e-mail' => '<em>&lt;'. $edit['mail'] .'&gt;</em>')));
user_save('', array('name' => $edit['name'], 'pass' => $edit['pass'], 'init' => $edit['mail'], 'mail' => $edit['mail'], 'roles' => array(_user_authenticated_id()), 'status' => 1));
user_save('', array('name' => $edit['name'], 'pass' => $edit['pass'], 'init' => $edit['mail'], 'mail' => $edit['mail'], 'roles' => $edit['roles'], 'status' => 1));
drupal_set_message(t('Created a new user account. No e-mail has been sent.'));
......
......@@ -928,7 +928,6 @@ function user_register($edit = array()) {
}
if ($edit) {
$edit['roles'] = array(_user_authenticated_id()); // needed for validation
user_module_invoke('validate', $edit, $edit, 'account');
if (!form_get_errors()) {
......@@ -937,7 +936,7 @@ function user_register($edit = array()) {
// TODO: Is this necessary? Won't session_write() replicate this?
unset($edit['session']);
$account = user_save('', array('name' => $edit['name'], 'pass' => $pass, 'init' => $edit['mail'], 'mail' => $edit['mail'], 'roles' => $edit['roles'], 'status' => (variable_get('user_register', 1) == 1 ? 1 : 0)));
$account = user_save('', array('name' => $edit['name'], 'pass' => $pass, 'init' => $edit['mail'], 'mail' => $edit['mail'], 'roles' => array(_user_authenticated_id()), 'status' => (variable_get('user_register', 1) == 1 ? 1 : 0)));
watchdog('user', t('New user: %name %e-mail.', array('%name' => '<em>'. $edit['name'] .'</em>', '%e-mail' => '<em>&lt;'. $edit['mail'] .'&gt;</em>')), l(t('edit'), 'user/'. $account->uid .'/edit'));
$variables = array('%username' => $edit['name'], '%site' => variable_get('site_name', 'drupal'), '%password' => $pass, '%uri' => $base_url, '%uri_brief' => substr($base_url, strlen('http://')), '%mailto' => $edit['mail'], '%date' => format_date(time()), '%login_uri' => url('user/login', NULL, NULL, TRUE), '%edit_uri' => url('user/'. $account->uid .'/edit', NULL, NULL, TRUE));
......@@ -1043,7 +1042,7 @@ function user_edit_validate($uid, &$edit) {
}
// Validate the roles
if (!$edit['roles']) {
if (user_access('administer users') && !$edit['roles']) {
form_set_error('roles', t('You must select at least one role.'));
$edit['roles'] = array();
}
......@@ -1271,12 +1270,14 @@ function user_configure_settings() {
function user_admin_create($edit = array()) {
if ($edit) {
// Because the admin form doesn't have roles selection they need to be set to validate properly
$edit['roles'] = array(_user_authenticated_id());
user_module_invoke('validate', $edit, $edit, 'account');
if (!form_get_errors()) {
watchdog('user', t('New user: %name %e-mail.', array('%name' => '<em>'. $edit['name'] .'</em>', '%e-mail' => '<em>&lt;'. $edit['mail'] .'&gt;</em>')));
user_save('', array('name' => $edit['name'], 'pass' => $edit['pass'], 'init' => $edit['mail'], 'mail' => $edit['mail'], 'roles' => array(_user_authenticated_id()), 'status' => 1));
user_save('', array('name' => $edit['name'], 'pass' => $edit['pass'], 'init' => $edit['mail'], 'mail' => $edit['mail'], 'roles' => $edit['roles'], 'status' => 1));
drupal_set_message(t('Created a new user account. No e-mail has been sent.'));
......
Markdown is supported
0% or .
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment