migrated signup.php over to using new formslib
[moodle.git] / login / signup.php
1 <?php // $Id$
3     require_once("../config.php");
4     require_once("../auth/$CFG->auth/lib.php");
6     //HTTPS is potentially required in this page
7     httpsrequired();
8     include("signup_form.php");
9     $mform_signup = new login_signup_form('signup.php','');
11     if ($CFG->auth != 'email' and (empty($CFG->auth_user_create) or !(function_exists('auth_user_create'))) ) {
12         error("Sorry, you may not use this page.");
13     }
15     if ($fromform = $mform_signup->data_submitted()) {
17         $plainpass = $fromform->password;
18         $fromform->password = hash_internal_user_password($plainpass);
19         $fromform->confirmed = 0;
20         $fromform->lang = current_language();
21         $fromform->firstaccess = time();
22         $fromform->secret = random_string(15);
23         $fromform->auth = $CFG->auth;
24         if (!empty($CFG->auth_user_create) and function_exists('auth_user_create') ){
25             if (! auth_user_exists($fromform->username)) {
26                 if (! auth_user_create($fromform,$plainpass)) {
27                     error("Could not add user to authentication module!");
28                 }
29             } else {
30                 error("User already exists on authentication database.");
31             }
32         }
34         if (! ($fromform->id = insert_record("user", $fromform)) ) {
35             error("Could not add your record to the database!");
36         }
38         if (! send_confirmation_email($fromform)) {
39             error("Tried to send you an email but failed!");
40         }
42         $emailconfirm = get_string("emailconfirm");
43         print_header($emailconfirm, $emailconfirm, $emailconfirm);
44         notice(get_string("emailconfirmsent", "", $fromform->email), "$CFG->wwwroot/index.php");
45         exit;
46     }
51     $newaccount = get_string("newaccount");
52     $login = get_string("login");
54     if (empty($CFG->langmenu)) {
55         $langmenu = "";
56     } else {
57         $currlang = current_language();
58         $langs    = get_list_of_languages();
59         $langmenu = popup_form ("$CFG->wwwroot/login/signup.php?lang=", $langs, "chooselang", $currlang, "", "", "", true);
60     }
61     print_header($newaccount, $newaccount, "<a href=\"index.php\">$login</a> -> $newaccount", $mform_signup->focus(), "", true, "<div align=\"right\">$langmenu</div>");
63     $mform_signup->display();
64     print_footer();
69 ?>