-<?php // $Id$
+<?php // $Id$
- require_once("../config.php");
+ require_once('../config.php');
require_once("../auth/$CFG->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 {
}
}
- 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();
print_footer();
-
-
?>
\ No newline at end of file
-<?php
-include_once $CFG->libdir.'/formslib.php';
+<?php // $Id$
+
+require_once($CFG->libdir.'/formslib.php');
+
class login_signup_form extends moodleform {
function definition() {
global $USER, $CFG;
$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")." <a href=\"forgot_password.php\">".get_string("newpassword")."?</a>";
+ } else if (record_exists('user', 'email', $data['email'])) {
+ $errors['email'] = get_string('emailexists').' <a href="forgot_password.php">'.get_string('newpassword').'?</a>';
}
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'])) {