3 require_once("../config.php");
4 require_once("../auth/$CFG->auth/lib.php");
6 if ($CFG->auth
!= 'email' and (empty($CFG->auth_user_create
) or !(function_exists('auth_user_create'))) ) {
7 error("Sorry, you may not use this page.");
10 if ($user = data_submitted()) {
12 $user->firstname
= strip_tags($user->firstname
);
13 $user->lastname
= strip_tags($user->lastname
);
14 $user->email
= strip_tags($user->email
);
16 validate_form($user, $err);
17 $user->username
= trim(moodle_strtolower($user->username
));
19 if (count((array)$err) == 0) {
20 $plainpass = $user->password
;
21 $user->password
= md5($user->password
);
23 $user->lang
= current_language();
24 $user->firstaccess
= time();
25 $user->secret
= random_string(15);
26 $user->auth
= $CFG->auth
;
27 if (!empty($CFG->auth_user_create
) and function_exists('auth_user_create') ){
28 if (! auth_user_exists($user->username
)) {
29 if (! auth_user_create($user,$plainpass)) {
30 error("Could not add user to authentication module!");
33 error("User already exists on authentication database.");
37 if (! ($user->id
= insert_record("user", $user)) ) {
38 error("Could not add your record to the database!");
41 if (! send_confirmation_email($user)) {
42 error("Tried to send you an email but failed!");
45 $emailconfirm = get_string("emailconfirm");
46 print_header($emailconfirm, $emailconfirm, $emailconfirm);
47 notice(get_string("emailconfirmsent", "", $user->email
), "$CFG->wwwroot/");
53 $focus = "form.".array_shift(array_flip(get_object_vars($err)));
58 if (empty($user->country
) and !empty($CFG->country
)) {
59 $user->country
= $CFG->country
;
62 $newaccount = get_string("newaccount");
63 $login = get_string("login");
65 if (empty($CFG->langmenu
)) {
68 $currlang = current_language();
69 $langs = get_list_of_languages();
70 $langmenu = popup_form ("$CFG->wwwroot/login/signup.php?lang=", $langs, "chooselang", $currlang, "", "", "", true);
73 print_header($newaccount, $newaccount, "<a href=\"index.php\">$login</a> -> $newaccount", $focus, "", true, "<div align=\"right\">$langmenu</div>");
74 include("signup_form.html");
79 /******************************************************************************
81 *****************************************************************************/
83 function validate_form($user, &$err) {
86 if (empty($user->username
)){
87 $err->username
= get_string("missingusername");
89 $user->username
= trim(moodle_strtolower($user->username
));
90 if (record_exists("user", "username", $user->username
)){
91 $err->username
= get_string("usernameexists");
93 if (empty($CFG->extendedusernamechars
)) {
94 $string = eregi_replace("[^(-\.[:alnum:])]", "", $user->username
);
95 if (strcmp($user->username
, $string)) {
96 $err->username
= get_string("alphanumerical");
102 if (isset($CFG->auth_user_create
) and $CFG->auth_user_create
==1 and function_exists('auth_user_exists') ){
103 if (auth_user_exists($user->username
)) {
104 $err->username
= get_string("usernameexists");
109 if (empty($user->password
)) {
110 $err->password
= get_string("missingpassword");
113 if (empty($user->firstname
)) {
114 $err->firstname
= get_string("missingfirstname");
117 if (empty($user->lastname
)) {
118 $err->lastname
= get_string("missinglastname");
122 if (empty($user->email
)) {
123 $err->email
= get_string("missingemail");
125 } else if (! validate_email($user->email
)) {
126 $err->email
= get_string("invalidemail");
128 } else if (record_exists("user", "email", $user->email
)) {
129 $err->email
= get_string("emailexists")." <a href=\"forgot_password.php\">".get_string("newpassword")."?</a>";
133 if (empty($user->email2
)) {
134 $err->email2
= get_string("missingemail");
136 } else if ($user->email2
!= $user->email
) {
137 $err->email2
= get_string("invalidemail");
141 if (empty($user->city
)) {
142 $err->city
= get_string("missingcity");
145 if (empty($user->country
)) {
146 $err->country
= get_string("missingcountry");
149 if (empty($err->email
)) {
150 if ($error = email_is_not_allowed($user->email
)) {
151 $err->email
= $error;