Index: user.module =================================================================== RCS file: /cvs/drupal/drupal/modules/user.module,v retrieving revision 1.288 diff -u -r1.288 user.module --- user.module 13 Jan 2004 19:25:37 -0000 1.288 +++ user.module 14 Jan 2004 04:21:34 -0000 @@ -149,6 +149,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) < variable_get("user_password_length", 6)) { + return t("You must enter a password that is at least %num characters in length.", array("%num" => variable_get("user_password_length", 6))); + } +} + 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) { @@ -157,7 +164,7 @@ } } -function user_password($length = 10) { +function user_password($length = 6) { /* ** Generate a random alphanumeric password. */ @@ -176,6 +183,7 @@ // Declare the password as a blank string: $pass = ""; + $length = ($length < variable_get("user_password_length", 6)) ? variable_get("user_password_length", 6) : $length; // Loop the number of times specified by $length: for ($i = 0; $i < $length; $i++) { @@ -587,7 +595,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; @@ -785,6 +793,9 @@ if ($error = user_validate_name($edit["name"])) { // do nothing } + else if (variable_get("user_register", 2) == 1 && $error = user_validate_password($edit["pass"])) { + // do nothing + } else if ($error = user_validate_mail($edit["mail"])) { // do nothing } @@ -825,13 +836,14 @@ if ($success) { $from = variable_get("site_mail", ini_get("sendmail_from")); - $pass = user_password(); + $pass = (variable_get("user_register", 2) == 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)); + $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())); @@ -856,7 +868,20 @@ $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", 2) == 1) { + + /* Let the developer control where the user is redirected. */ + if (empty($edit["destination"])) { + $edit["destination"] = url($_GET["q"]); + } + drupal_set_message(t("Your new account has been created.")); + user_login($edit); + } + else { + return t("Your password and further instructions have been sent to your e-mail address."); + } } else { /* @@ -883,8 +908,13 @@ $affiliates = implode(", ", $affiliates); $output .= "
". t("Note: If you have an account with one of our affiliates (%s), you may ". l("login now", "user/login") ." instead of registering.", array("%s" => $affiliates)) ."
"; } + + $email_help = (variable_get("user_register", 2) == 1) ? t("A password and instructions will be sent to this e-mail address, so make sure it is accurate.") : t("Login instructions will be sent to this e-mail address, so make sure it is accurate."); $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_textfield(t("E-mail address"), "mail", $edit["mail"], 30, 64, $email_help); + if (variable_get("user_register", 2) == 1) { + $output .= form_password(t("Password"), "pass", $edit["pass"], 30, 55, t("Provide a password for the new account. Your password must contain at least %num characters.", array("%num" => variable_get("user_password_length", 6)))); + } foreach (module_list() as $module) { if (module_hook($module, "user")) { $output .= module_invoke($module, "user", "register_form", $edit, $user); @@ -1117,8 +1147,9 @@ 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_select(t("Mininum length of passwords"), "user_password_length", variable_get("user_password_length", 6), array(4 => 4, 5 => 5, 6 => 6, 7 => 7, 8 => 8, 9 => 9, 10 => 10, 11 => 11, 12 => 12, 13 => 13, 14 => 14, 15 => 15), t("The minimum number of characters required for a password.")); $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);