Allow STRIKE tag
[moodle.git] / login / index.php
CommitLineData
f9903ed0 1<?PHP // $Id$
2 require("../config.php");
3
a9b07c52 4 // Check if the guest user exists. If not, create one.
5 if (! record_exists("user", "username", "guest")) {
6 $guest->username = "guest";
7 $guest->password = md5("guest");
cf38360f 8 $guest->firstname = get_string("guestuser");
9 $guest->lastname = " ";
a9b07c52 10 $guest->email = "root@localhost";
cf38360f 11 $guest->description = get_string("guestuserinfo");
a9b07c52 12 $guest->confirmed = 1;
ad6c33dc 13 $guest->lang = $CFG->lang;
a9b07c52 14 $guest->timemodified= time();
15
16 if (! $guest->id = insert_record("user", $guest)) {
17 notify("Could not create guest user record !!!");
18 }
19 }
20
21
f9903ed0 22 if (match_referer() && isset($HTTP_POST_VARS)) { // form submitted
23
24 $frm = (object)$HTTP_POST_VARS;
faebaf0f 25 $user = authenticate_user_login($frm->username, $frm->password);
f9903ed0 26
27 update_login_count();
28
29 if ($user) {
30 if (! $user->confirmed ) { // they never confirmed via email
fa0626c6 31 print_header(get_string("mustconfirm"), get_string("mustconfirm") );
f9903ed0 32 include("index_confirm.html");
8553b700 33 print_footer();
f9903ed0 34 die;
35 }
c21c671d 36
f9903ed0 37 $USER = $user;
38 $USER->loggedin = true;
c21c671d 39 $USER->site = $CFG->wwwroot; // for added security
fcf8e836 40 if ($USER->username == "guest") {
910d1731 41 $USER->lang = $CFG->lang; // Guest language always same as site
42 }
8223d271 43 save_session("USER");
f9903ed0 44
45 if (!update_user_in_db()) {
46 error("Weird error: User not found");
47 }
48
49 if (!update_user_login_times()) {
50 error("Wierd error: could not update login records");
51 }
8223d271 52
f9903ed0 53 set_moodle_cookie($USER->username);
54
55
56 if (empty($SESSION->wantsurl)) {
57 header("Location: $CFG->wwwroot");
58 } else {
59 header("Location: $SESSION->wantsurl");
60 unset($SESSION->wantsurl);
8223d271 61 save_session("SESSION");
f9903ed0 62 }
63
64 reset_login_count();
f9903ed0 65
f9903ed0 66 die;
67
68 } else {
fa0626c6 69 $errormsg = get_string("invalidlogin");
f9903ed0 70 }
71 }
8223d271 72
f9903ed0 73
9c9f7d77 74 if (empty($errormsg)) {
75 $errormsg = "";
76 }
77
f9903ed0 78 if (empty($SESSION->wantsurl)) {
8223d271 79 $SESSION->wantsurl = $HTTP_REFERER;
80 save_session("SESSION");
f9903ed0 81 }
82
9c9f7d77 83 if (empty($frm->username)) {
f9903ed0 84 $frm->username = get_moodle_cookie();
9c9f7d77 85 $frm->password = "";
86 }
f9903ed0 87
9c9f7d77 88 if (!empty($frm->username)) {
f9903ed0 89 $focus = "form.password";
90 } else {
91 $focus = "form.username";
92 }
35a48c9a 93
94 if ($CFG->auth == "email" or $CFG->auth == "none" or $CFG->auth_instructions) {
95 $show_instructions = true;
96 } else {
97 $show_instructions = false;
98 }
f9903ed0 99
35a48c9a 100 if (!$site = get_site()) {
101 error("No site found!");
102 }
fa0626c6 103 $loginsite = get_string("loginsite");
104
35a48c9a 105 print_header("$site->fullname: $loginsite", "$loginsite", get_string("login"), $focus);
f9903ed0 106 include("index_form.html");
8553b700 107 print_footer();
f9903ed0 108
109 exit;
110
111 // No footer on this page
112
f9903ed0 113?>