migrated signup.php over to using new formslib
[moodle.git] / login / signup.php
CommitLineData
9a58f7cb 1<?php // $Id$
f9903ed0 2
5f2c35db 3 require_once("../config.php");
5f2c35db 4 require_once("../auth/$CFG->auth/lib.php");
f9903ed0 5
bd251e28 6 //HTTPS is potentially required in this page
7 httpsrequired();
e8a34ad4 8 include("signup_form.php");
9 $mform_signup = new login_signup_form('signup.php','');
bd251e28 10
249bdbe3 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 }
14
e8a34ad4 15 if ($fromform = $mform_signup->data_submitted()) {
16
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!");
5f2c35db 28 }
e8a34ad4 29 } else {
30 error("User already exists on authentication database.");
5f2c35db 31 }
e8a34ad4 32 }
f9903ed0 33
e8a34ad4 34 if (! ($fromform->id = insert_record("user", $fromform)) ) {
35 error("Could not add your record to the database!");
36 }
f9903ed0 37
e8a34ad4 38 if (! send_confirmation_email($fromform)) {
39 error("Tried to send you an email but failed!");
0305fe82 40 }
f9903ed0 41
e8a34ad4 42 $emailconfirm = get_string("emailconfirm");
43 print_header($emailconfirm, $emailconfirm, $emailconfirm);
44 notice(get_string("emailconfirmsent", "", $fromform->email), "$CFG->wwwroot/index.php");
45 exit;
93f03cc4 46 }
f9903ed0 47
e8a34ad4 48
49
778c2867 50
8553b700 51 $newaccount = get_string("newaccount");
52 $login = get_string("login");
f9903ed0 53
984a8bf3 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 }
e8a34ad4 61 print_header($newaccount, $newaccount, "<a href=\"index.php\">$login</a> -> $newaccount", $mform_signup->focus(), "", true, "<div align=\"right\">$langmenu</div>");
2f05b46e 62
e8a34ad4 63 $mform_signup->display();
8553b700 64 print_footer();
f9903ed0 65
66
67
f9903ed0 68
e8a34ad4 69?>