All users are viewable in the "site" course.
[moodle.git] / login / index.php
CommitLineData
f9903ed0 1<?PHP // $Id$
2 require("../config.php");
3
4
5 if (match_referer() && isset($HTTP_POST_VARS)) { // form submitted
6
7 $frm = (object)$HTTP_POST_VARS;
8 $user = verify_login($frm->username, $frm->password);
9
10 update_login_count();
11
12 if ($user) {
13 if (! $user->confirmed ) { // they never confirmed via email
14 print_header("Need to confirm", "Not confirmed yet", "", "");
15 include("index_confirm.html");
16 die;
17 }
18
19 $USER = $user;
20 $USER->loggedin = true;
21
22 if (!update_user_in_db()) {
23 error("Weird error: User not found");
24 }
25
26 if (!update_user_login_times()) {
27 error("Wierd error: could not update login records");
28 }
29
30 set_moodle_cookie($USER->username);
31
32
33 if (empty($SESSION->wantsurl)) {
34 header("Location: $CFG->wwwroot");
35 } else {
36 header("Location: $SESSION->wantsurl");
37 unset($SESSION->wantsurl);
38 }
39
40 reset_login_count();
f9903ed0 41
42 if ($CFG->smsnotify) {
43 $time = date("H:i D j M", time());
44 $smstring = "$time - $USER->firstname $USER->lastname logged in to $CFG->sitename";
45 system("echo \"$smstring \" | /opt/bin/sendsms &> /dev/null &");
46 }
47
48 die;
49
50 } else {
51 $errormsg = "Invalid login, please try again";
52 }
53 }
54
55 if (empty($SESSION->wantsurl)) {
56 $SESSION->wantsurl = $HTTP_REFERER;
57 }
58
59 if (!$frm->username)
60 $frm->username = get_moodle_cookie();
61
62 if ($frm->username) {
63 $focus = "form.password";
64 } else {
65 $focus = "form.username";
66 }
67
68 print_header("Login to the site", "Login to the site", "Login", $focus);
69
70 include("index_form.html");
71
72 exit;
73
74 // No footer on this page
75
76function update_user_login_times() {
77 global $db, $USER;
78
79 $USER->lastlogin = $USER->currentlogin;
80 $USER->currentlogin = time();
81
82 return $db->Execute("UPDATE user
83 SET lastlogin='$USER->lastlogin', currentlogin='$USER->currentlogin'
84 WHERE id = '$USER->id'");
85}
86?>