From 296c2a79e8303e4cf30d523f2dbdcc4dc3984a13 Mon Sep 17 00:00:00 2001 From: skodak Date: Thu, 9 Nov 2006 22:33:52 +0000 Subject: [PATCH] coding style changes MDL-MDL-6956 --- login/signup.php | 46 +++++++++++++------------- login/signup_form.php | 76 +++++++++++++++++++++++-------------------- 2 files changed, 62 insertions(+), 60 deletions(-) diff --git a/login/signup.php b/login/signup.php index 057c5f9563..71dab6d594 100644 --- a/login/signup.php +++ b/login/signup.php @@ -1,29 +1,31 @@ -auth/lib.php"); + require_once('signup_form.php'); //HTTPS is potentially required in this page httpsrequired(); - include("signup_form.php"); - $mform_signup = new login_signup_form('signup.php',''); + + $mform_signup = new login_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 ($fromform = $mform_signup->data_submitted()) { + if ($user = $mform_signup->data_submitted()) { + + $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; - $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($fromform->username)) { - if (! auth_user_create($fromform,$plainpass)) { + if (! auth_user_exists($user->username)) { + if (! auth_user_create($user, $plainpass)) { error("Could not add user to authentication module!"); } } else { @@ -31,28 +33,26 @@ } } - if (! ($fromform->id = insert_record("user", $fromform)) ) { + if (! ($user->id = insert_record('user', $user))) { error("Could not add your record to the database!"); } - if (! send_confirmation_email($fromform)) { + if (! send_confirmation_email($user)) { error("Tried to send you an email but failed!"); } $emailconfirm = get_string("emailconfirm"); print_header($emailconfirm, $emailconfirm, $emailconfirm); - notice(get_string("emailconfirmsent", "", $fromform->email), "$CFG->wwwroot/index.php"); + notice(get_string("emailconfirmsent", "", $user->email), "$CFG->wwwroot/index.php"); exit; } - - - $newaccount = get_string("newaccount"); - $login = get_string("login"); + $newaccount = get_string('newaccount'); + $login = get_string('login'); if (empty($CFG->langmenu)) { - $langmenu = ""; + $langmenu = ''; } else { $currlang = current_language(); $langs = get_list_of_languages(); @@ -64,6 +64,4 @@ print_footer(); - - ?> \ No newline at end of file diff --git a/login/signup_form.php b/login/signup_form.php index a9aa0de7cc..e8f2c4afee 100644 --- a/login/signup_form.php +++ b/login/signup_form.php @@ -1,5 +1,7 @@ -libdir.'/formslib.php'; +libdir.'/formslib.php'); + class login_signup_form extends moodleform { function definition() { global $USER, $CFG; @@ -7,89 +9,91 @@ class login_signup_form extends moodleform { $mform =& $this->_form; $renderer =& $mform->defaultRenderer(); - $mform->addElement('header', '', get_string("createuserandpass"),''); + $mform->addElement('header', '', get_string('createuserandpass'), ''); - $mform->addElement('text', 'username', get_string("username"),'size="12"'); + $mform->addElement('text', 'username', get_string('username'), 'size="12"'); $mform->setType('username', PARAM_NOTAGS); - $mform->addRule('username', get_string("missingusername"), 'required', null, 'client'); + $mform->addRule('username', get_string('missingusername'), 'required', null, 'client'); - $mform->addElement('password', 'password', get_string("password"), 'size="12"'); + $mform->addElement('password', 'password', get_string('password'), 'size="12"'); $mform->setType('password', PARAM_RAW); - $mform->addRule('password', get_string("missingpassword"), 'required', null, 'client'); + $mform->addRule('password', get_string('missingpassword'), 'required', null, 'client'); $mform->addElement('header', '', get_string('supplyinfo'),''); - $mform->addElement('text', 'email', get_string("email"), 'size="25"'); + $mform->addElement('text', 'email', get_string('email'), 'size="25"'); $mform->setType('email', PARAM_NOTAGS); - $mform->addRule('email', get_string("missingemail"), 'required', null, 'client'); + $mform->addRule('email', get_string('missingemail'), 'required', null, 'client'); - $mform->addElement('text', 'email2', get_string("emailagain"), 'size="25"'); + $mform->addElement('text', 'email2', get_string('emailagain'), 'size="25"'); $mform->setType('email2', PARAM_NOTAGS); - $mform->addRule('email2', get_string("missingemail"), 'required', null, 'client'); + $mform->addRule('email2', get_string('missingemail'), 'required', null, 'client'); - $mform->addElement('text', 'firstname', get_string("firstname"), 'size="25"'); + $mform->addElement('text', 'firstname', get_string('firstname'), 'size="25"'); $mform->setType('firstname', PARAM_TEXT); - $mform->addRule('firstname', get_string("missingfirstname"), 'required', null, 'client'); + $mform->addRule('firstname', get_string('missingfirstname'), 'required', null, 'client'); - $mform->addElement('text', 'lastname', get_string("lastname"), 'size="25"'); + $mform->addElement('text', 'lastname', get_string('lastname'), 'size="25"'); $mform->setType('lastname', PARAM_TEXT); - $mform->addRule('lastname', get_string("missinglastname"), 'required', null, 'client'); + $mform->addRule('lastname', get_string('missinglastname'), 'required', null, 'client'); - $mform->addElement('text', 'city', get_string("city"), 'size="25"'); + $mform->addElement('text', 'city', get_string('city'), 'size="25"'); $mform->setType('city', PARAM_TEXT); - $mform->addRule('city', get_string("missingcity"), 'required', null, 'client'); + $mform->addRule('city', get_string('missingcity'), 'required', null, 'client'); - $country=get_list_of_countries(); - $default_country['']=get_string("selectacountry"); - $country=array_merge($default_country,$country); - $mform->setDefault('country', ''); - $mform->addElement('select', 'country', get_string("country"), $country); - $mform->addRule('country', get_string("missingcountry"), 'required', null, 'client'); + $country = get_list_of_countries(); + $default_country[''] = get_string('selectacountry'); + $country = array_merge($default_country, $country); + $mform->addElement('select', 'country', get_string('country'), $country); + $mform->addRule('country', get_string('missingcountry'), 'required', null, 'client'); + $mform->setDefault('country', ''); - $mform->addElement('submit', 'submit', get_string("createaccount")); + $mform->addElement('submit', 'submit', get_string('createaccount')); $renderer->addStopFieldsetElements('submit'); } + function definition_after_data(){ - $mform =& $this->_form; + $mform =& $this->_form; + $mform->applyFilter('username', 'moodle_strtolower'); $mform->applyFilter('username', 'trim'); } function validation($data) { global $CFG; - $errors=array(); + $errors = array(); - if (record_exists("user", "username", $data['username'])){ - $errors['username'] = get_string("usernameexists"); + if (record_exists('user', 'username', $data['username'])){ + $errors['username'] = get_string('usernameexists'); } else { if (empty($CFG->extendedusernamechars)) { - $string = eregi_replace("[^(-\.[:alnum:])]", "", $data['username']); + $string = eregi_replace("[^(-\.[:alnum:])]", '', $data['username']); if (strcmp($data['username'], $string)) { - $errors['username'] = get_string("alphanumerical"); + $errors['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($data['username'])) { - $errors['username'] = get_string("usernameexists"); + $errors['username'] = get_string('usernameexists'); } } if (! validate_email($data['email'])) { - $errors['email'] = get_string("invalidemail"); + $errors['email'] = get_string('invalidemail'); - }else if (record_exists("user", "email", $data['email'])) { - $errors['email'] = get_string("emailexists")." ".get_string("newpassword")."?"; + } else if (record_exists('user', 'email', $data['email'])) { + $errors['email'] = get_string('emailexists').' '.get_string('newpassword').'?'; } if (empty($data['email2'])) { - $errors['email2'] = get_string("missingemail"); + $errors['email2'] = get_string('missingemail'); } else if ($data['email2'] != $data['email']) { - $errors['email2'] = get_string("invalidemail"); + $errors['email2'] = get_string('invalidemail'); } if (!isset($errors['email'])) { if ($err = email_is_not_allowed($data['email'])) { -- 2.39.5