Added missing parameter to update_module_icon (courseid)
[moodle.git] / login / index.php
CommitLineData
f9903ed0 1<?PHP // $Id$
2 require("../config.php");
3
4
a9b07c52 5 // Check if the guest user exists. If not, create one.
6 if (! record_exists("user", "username", "guest")) {
7 $guest->username = "guest";
8 $guest->password = md5("guest");
9 $guest->firstname = "Guest";
10 $guest->lastname = "User";
11 $guest->email = "root@localhost";
12 $guest->description = "This user is a special user that allows read-only access to some courses.";
13 $guest->confirmed = 1;
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;
25 $user = verify_login($frm->username, $frm->password);
26
27 update_login_count();
28
29 if ($user) {
30 if (! $user->confirmed ) { // they never confirmed via email
31 print_header("Need to confirm", "Not confirmed yet", "", "");
32 include("index_confirm.html");
33 die;
34 }
35
36 $USER = $user;
37 $USER->loggedin = true;
38
39 if (!update_user_in_db()) {
40 error("Weird error: User not found");
41 }
42
43 if (!update_user_login_times()) {
44 error("Wierd error: could not update login records");
45 }
46
47 set_moodle_cookie($USER->username);
48
49
50 if (empty($SESSION->wantsurl)) {
51 header("Location: $CFG->wwwroot");
52 } else {
53 header("Location: $SESSION->wantsurl");
54 unset($SESSION->wantsurl);
55 }
56
57 reset_login_count();
f9903ed0 58
59 if ($CFG->smsnotify) {
60 $time = date("H:i D j M", time());
61 $smstring = "$time - $USER->firstname $USER->lastname logged in to $CFG->sitename";
62 system("echo \"$smstring \" | /opt/bin/sendsms &> /dev/null &");
63 }
64
65 die;
66
67 } else {
68 $errormsg = "Invalid login, please try again";
69 }
70 }
71
72 if (empty($SESSION->wantsurl)) {
73 $SESSION->wantsurl = $HTTP_REFERER;
74 }
75
76 if (!$frm->username)
77 $frm->username = get_moodle_cookie();
78
79 if ($frm->username) {
80 $focus = "form.password";
81 } else {
82 $focus = "form.username";
83 }
84
85 print_header("Login to the site", "Login to the site", "Login", $focus);
86
87 include("index_form.html");
88
89 exit;
90
91 // No footer on this page
92
93function update_user_login_times() {
94 global $db, $USER;
95
96 $USER->lastlogin = $USER->currentlogin;
97 $USER->currentlogin = time();
98
99 return $db->Execute("UPDATE user
100 SET lastlogin='$USER->lastlogin', currentlogin='$USER->currentlogin'
101 WHERE id = '$USER->id'");
102}
103?>