mirrored from git://git.moodle.org/moodle.git
-
Notifications
You must be signed in to change notification settings - Fork 6.6k
/
index.php
106 lines (78 loc) · 2.85 KB
/
index.php
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
<?PHP // $Id$
require("../config.php");
// Check if the guest user exists. If not, create one.
if (! record_exists("user", "username", "guest")) {
$guest->username = "guest";
$guest->password = md5("guest");
$guest->firstname = "Guest";
$guest->lastname = "User";
$guest->email = "root@localhost";
$guest->description = "This user is a special user that allows read-only access to some courses.";
$guest->confirmed = 1;
$guest->timemodified= time();
if (! $guest->id = insert_record("user", $guest)) {
notify("Could not create guest user record !!!");
}
}
if (match_referer() && isset($HTTP_POST_VARS)) { // form submitted
$frm = (object)$HTTP_POST_VARS;
$user = verify_login($frm->username, $frm->password);
update_login_count();
if ($user) {
if (! $user->confirmed ) { // they never confirmed via email
print_header(get_string("mustconfirm"), get_string("mustconfirm") );
include("index_confirm.html");
print_footer();
die;
}
$USER = $user;
$USER->loggedin = true;
$USER->site = $CFG->wwwroot; // for added security
save_session("USER");
if (!update_user_in_db()) {
error("Weird error: User not found");
}
if (!update_user_login_times()) {
error("Wierd error: could not update login records");
}
set_moodle_cookie($USER->username);
if (empty($SESSION->wantsurl)) {
header("Location: $CFG->wwwroot");
} else {
header("Location: $SESSION->wantsurl");
unset($SESSION->wantsurl);
save_session("SESSION");
}
reset_login_count();
die;
} else {
$errormsg = get_string("invalidlogin");
}
}
if (empty($SESSION->wantsurl)) {
$SESSION->wantsurl = $HTTP_REFERER;
save_session("SESSION");
}
if (!$frm->username)
$frm->username = get_moodle_cookie();
if ($frm->username) {
$focus = "form.password";
} else {
$focus = "form.username";
}
$loginsite = get_string("loginsite");
print_header($loginsite, $loginsite, get_string("login"), $focus);
include("index_form.html");
print_footer();
exit;
// No footer on this page
function update_user_login_times() {
global $db, $USER;
$USER->lastlogin = $USER->currentlogin;
$USER->currentlogin = time();
save_session("USER");
return $db->Execute("UPDATE user
SET lastlogin='$USER->lastlogin', currentlogin='$USER->currentlogin'
WHERE id = '$USER->id'");
}
?>