Index: user.module =================================================================== RCS file: /cvs/drupal/drupal/modules/user.module,v retrieving revision 1.285 diff -u -r1.285 user.module --- user.module 5 Jan 2004 19:33:58 -0000 1.285 +++ user.module 8 Jan 2004 05:39:20 -0000 @@ -154,6 +154,13 @@ } } +function user_validate_password($pwd) { + if (!$pwd) return t("You must enter a password that is at least 6 characters in length."); + if (strlen($pwd) < 6) { + return t("You must enter a password that is at least 6 characters in length."); + } +} + function user_validate_authmap($account, $authname, $module) { $result = db_query("SELECT COUNT(*) from {authmap} WHERE uid != %d AND authname = '%s'", $account->uid, $authname); if (db_result($result) > 0) { @@ -592,7 +599,7 @@ foreach (module_list() as $module) { if (module_hook($module, "auth")) { if (module_invoke($module, "auth", $name, $pass, $server)) { - if (variable_get("user_register", 1) == 1 && !user_load(array("name" => "$name@$server"))) { //register this new user + if ((variable_get("user_register", 1) == 1 || variable_get("user_register", 1) == 2) && !user_load(array("name" => "$name@$server"))) { //register this new user $user = user_save("", array("name" => "$name@$server", "pass" => user_password(), "init" => "$name@$server", "status" => 1, "authname_$module" => "$name@$server", "rid" => _user_authenticated_id())); watchdog("user", "new user: $name@$server ($module ID)", l(t("edit user"), "admin/user/edit/$user->uid")); break; @@ -790,6 +797,9 @@ if ($error = user_validate_name($edit["name"])) { // do nothing } + else if (variable_get("user_register", 1) == 1 && $error = user_validate_password($edit["pass"])) { + // do nothing + } else if ($error = user_validate_mail($edit["mail"])) { // do nothing } @@ -830,13 +840,15 @@ if ($success) { $from = variable_get("site_mail", ini_get("sendmail_from")); - $pass = user_password(); + $pass = (variable_get("user_register", 1) == 1) ? $edit['pass'] : user_password(); // create new user account, noting whether administrator approval is required user_role_init(); // TODO: is this necessary? Won't session_write replicate this? unset($edit["session"]); - $account = user_save("", array_merge(array("name" => $edit["name"], "pass" => $pass, "init" => $edit["mail"], "mail" => $edit["mail"], "rid" => _user_authenticated_id(), "status" => (variable_get("user_register", 1) == 1 ? 1 : 0)), $data)); + //$account = user_save("", array_merge(array("name" => $edit["name"], "pass" => $pass, "init" => $edit["mail"], "mail" => $edit["mail"], "rid" => _user_authenticated_id(), "status" => (variable_get("user_register", 1) == 1 || variable_get("user_register", 1) == 2 ? 1 : 0)), $data)); + $edit = array_merge(array("pass" => $pass, "init" => $edit["mail"], "rid" => _user_authenticated_id(), "status" => (variable_get("user_register", 1) == 1 || variable_get("user_register", 1) == 2 ? 1 : 0)), $edit); + $account = user_save("", array_merge($edit, $data)); watchdog("user", "new user: '". $edit["name"] ."' <". $edit["mail"] .">", l(t("edit user"), "admin/user/edit/$account->uid")); $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())); @@ -858,10 +870,21 @@ ** Create new user account, no administrator approval required: */ - $subject = strtr(variable_get("user_mail_welcome_subject", _user_mail_text("welcome_subject")), $variables); - $body = strtr(variable_get("user_mail_welcome_body", _user_mail_text("welcome_body")), $variables); - user_mail($edit["mail"], $subject, $body, "From: $from\nReply-to: $from\nX-Mailer: Drupal\nReturn-path: $from\nErrors-to: $from"); - return t("Your password and further instructions have been sent to your e-mail address."); + /* User has created their own password and gets to login immediately */ + if (variable_get("user_register", 1) == 1) { + drupal_set_message(t("Your new account has been created.")); + + /* Let the developer control where the user is redirected. */ + $edit["destination"] = url("user"); + drupal_goto($edit["destination"]); + } + else { + /* User will be emailed password to access account. */ + $subject = strtr(variable_get("user_mail_welcome_subject", _user_mail_text("welcome_subject")), $variables); + $body = strtr(variable_get("user_mail_welcome_body", _user_mail_text("welcome_body")), $variables); + user_mail($edit["mail"], $subject, $body, "From: $from\nReply-to: $from\nX-Mailer: Drupal\nReturn-path: $from\nErrors-to: $from"); + return t("Your password and further instructions have been sent to your e-mail address."); + } } else { /* @@ -890,6 +913,8 @@ } $output .= form_textfield(t("Username"), "name", $edit["name"], 30, 64, t("Your full name or your preferred username: only letters, numbers and spaces are allowed.")); $output .= form_textfield(t("E-mail address"), "mail", $edit["mail"], 30, 64, t("A password and instructions will be sent to this e-mail address, so make sure it is accurate.")); + $output .= form_password(t("Password"), "pass", $edit["pass"], 30, 55, t("Provide a password for the new account.")); + foreach (module_list() as $module) { if (module_hook($module, "user")) { $output .= module_invoke($module, "user", "register_form", $edit, $user); @@ -1122,7 +1147,7 @@ function user_settings() { // user registration settings - $group = form_radios(t("Public registrations"), "user_register", variable_get("user_register", 1), array(t("Only site administrators can create new user accounts."), t("Visitors can create accounts and no administrator approval is required."), t("Visitors can create accounts but administrator approval is required."))); + $group = form_radios(t("Public registrations"), "user_register", variable_get("user_register", 1), array(t("Only site administrators can create new user accounts."), t("Visitors can create accounts and sign in immediately."), t("Visitors can create accounts and will receive their password via email."), t("Visitors can create accounts but administrator approval is required."))); $group .= form_radios(t("Remember authenticated users"), "user_remember", variable_get("user_remember", 0), array(t("Let the user decide whether he should be logged out when leaving the site."), t("Authenticated users are not logged out upon leaving the site."), t("Authenticated users are logged out upon leaving the site."))); $group .= form_textarea(t("User registration guidelines"), "user_registration_help", variable_get("user_registration_help", ""), 70, 4, t("This text is displayed at the top of the user registration form. It's useful for helping or instructing your users.")); $output = form_group(t("User registration settings"), $group);