Index: signup.php =================================================================== RCS file: /cvsroot/moodle/moodle/login/signup.php,v retrieving revision 1.45 diff -u -r1.45 signup.php --- signup.php 12 Apr 2006 01:32:15 -0000 1.45 +++ signup.php 18 Oct 2006 09:42:16 -0000 @@ -2,34 +2,36 @@ require_once("../config.php"); require_once("../auth/$CFG->auth/lib.php"); + include_once $CFG->libdir.'/formslib.php'; //HTTPS is potentially required in this page httpsrequired(); + include("signup_form.php"); + $mform_signup = new user_signup_form('signup.php',''); if ($CFG->auth != 'email' and (empty($CFG->auth_user_create) or !(function_exists('auth_user_create'))) ) { error("Sorry, you may not use this page."); } - if ($user = data_submitted()) { + if ($fromform = $mform_signup->data_submitted()) { - $user->firstname = strip_tags($user->firstname); - $user->lastname = strip_tags($user->lastname); - $user->email = strip_tags($user->email); - - validate_form($user, $err); - $user->username= trim(moodle_strtolower($user->username)); - - if (count((array)$err) == 0) { - $plainpass = $user->password; - $user->password = hash_internal_user_password($plainpass); - $user->confirmed = 0; - $user->lang = current_language(); - $user->firstaccess = time(); - $user->secret = random_string(15); - $user->auth = $CFG->auth; + $fromform->firstname = strip_tags($fromform->firstname); + $fromform->lastname = strip_tags($fromform->lastname); + $fromform->email = strip_tags($fromform->email); + + $fromform->username= trim(moodle_strtolower($fromform->username)); + $error=array(); + if (count((array)$errors) == 0) { + $plainpass = $fromform->password; + $fromform->password = hash_internal_user_password($plainpass); + $fromform->confirmed = 0; + $fromform->lang = current_language(); + $fromform->firstaccess = time(); + $fromform->secret = random_string(15); + $fromform->auth = $CFG->auth; if (!empty($CFG->auth_user_create) and function_exists('auth_user_create') ){ - if (! auth_user_exists($user->username)) { - if (! auth_user_create($user,$plainpass)) { + if (! auth_user_exists($fromform->username)) { + if (! auth_user_create($fromform,$plainpass)) { error("Could not add user to authentication module!"); } } else { @@ -37,30 +39,28 @@ } } - if (! ($user->id = insert_record("user", $user)) ) { + if (! ($fromform->id = insert_record("user", $fromform)) ) { error("Could not add your record to the database!"); } - if (! send_confirmation_email($user)) { + if (! send_confirmation_email($fromform)) { error("Tried to send you an email but failed!"); } - + $emailconfirm = get_string("emailconfirm"); print_header($emailconfirm, $emailconfirm, $emailconfirm); - notice(get_string("emailconfirmsent", "", $user->email), "$CFG->wwwroot/index.php"); + notice(get_string("emailconfirmsent", "", $fromform->email), "$CFG->wwwroot/index.php"); exit; } } - if (!empty($err)) { - $focus = "form.".array_shift($temparr = array_flip(get_object_vars($err))); + if (!empty($errors)) { + $focus = "form.".array_shift($temparr = array_flip(get_object_vars($errors))); } else { $focus = ""; } - if (empty($user->country) and !empty($CFG->country)) { - $user->country = $CFG->country; - } + $newaccount = get_string("newaccount"); $login = get_string("login"); @@ -74,7 +74,8 @@ } print_header($newaccount, $newaccount, "$login -> $newaccount", $focus, "", true, "
$langmenu
"); - include("signup_form.html"); + + $mform_signup->display(); print_footer(); @@ -83,80 +84,5 @@ * FUNCTIONS *****************************************************************************/ -function validate_form($user, &$err) { - global $CFG; - - if (empty($user->username)){ - $err->username = get_string("missingusername"); - } else{ - $user->username = trim(moodle_strtolower($user->username)); - if (record_exists("user", "username", $user->username)){ - $err->username = get_string("usernameexists"); - } else { - if (empty($CFG->extendedusernamechars)) { - $string = eregi_replace("[^(-\.[:alnum:])]", "", $user->username); - if (strcmp($user->username, $string)) { - $err->username = get_string("alphanumerical"); - } - } - } - } - - if (isset($CFG->auth_user_create) and $CFG->auth_user_create==1 and function_exists('auth_user_exists') ){ - if (auth_user_exists($user->username)) { - $err->username = get_string("usernameexists"); - } - } - - - if (empty($user->password)) { - $err->password = get_string("missingpassword"); - } - - if (empty($user->firstname)) { - $err->firstname = get_string("missingfirstname"); - } - - if (empty($user->lastname)) { - $err->lastname = get_string("missinglastname"); - } - - - if (empty($user->email)) { - $err->email = get_string("missingemail"); - - } else if (! validate_email($user->email)) { - $err->email = get_string("invalidemail"); - - } else if (record_exists("user", "email", $user->email)) { - $err->email = get_string("emailexists")." ".get_string("newpassword")."?"; - } - - - if (empty($user->email2)) { - $err->email2 = get_string("missingemail"); - - } else if ($user->email2 != $user->email) { - $err->email2 = get_string("invalidemail"); - } - - - if (empty($user->city)) { - $err->city = get_string("missingcity"); - } - - if (empty($user->country)) { - $err->country = get_string("missingcountry"); - } - - if (empty($err->email)) { - if ($error = email_is_not_allowed($user->email)) { - $err->email = $error; - } - } - - return; -} - ?>