Now filename is fixed to rss.xml. SC#23
[moodle.git] / login / index.php
CommitLineData
9a58f7cb 1<?php // $Id$
b0e3a925 2
3 require_once("../config.php");
fe657136 4 optional_variable($loginguest, false); // determines whether visitors are logged in as guest automatically
f9903ed0 5
a9b07c52 6 // Check if the guest user exists. If not, create one.
7 if (! record_exists("user", "username", "guest")) {
4e11ad4f 8 $guest->auth = "manual";
a9b07c52 9 $guest->username = "guest";
10 $guest->password = md5("guest");
b95c3ab8 11 $guest->firstname = addslashes(get_string("guestuser"));
cf38360f 12 $guest->lastname = " ";
a9b07c52 13 $guest->email = "root@localhost";
b95c3ab8 14 $guest->description = addslashes(get_string("guestuserinfo"));
a9b07c52 15 $guest->confirmed = 1;
ad6c33dc 16 $guest->lang = $CFG->lang;
a9b07c52 17 $guest->timemodified= time();
18
19 if (! $guest->id = insert_record("user", $guest)) {
20 notify("Could not create guest user record !!!");
21 }
22 }
089b19f6 23
24 //Define variables used in page
25 if (!$site = get_site()) {
26 error("No site found!");
27 }
28
29 if (empty($CFG->langmenu)) {
30 $langmenu = "";
31 } else {
32 $currlang = current_language();
33 $langs = get_list_of_languages();
34 if (empty($CFG->loginhttps)) {
35 $wwwroot = $CFG->wwwroot;
36 } else {
37 $wwwroot = str_replace('http','https',$CFG->wwwroot);
38 }
39 $langmenu = popup_form ("$wwwroot/login/index.php?lang=", $langs, "chooselang", $currlang, "", "", "", true);
40 }
41
42 $loginsite = get_string("loginsite");
43
a9b07c52 44
d00377f5 45 $frm = false;
fe657136 46 if ((!empty($SESSION->wantsurl) and strstr($SESSION->wantsurl,"username=guest")) or $loginguest) {
d00377f5 47 /// Log in as guest automatically (idea from Zbigniew Fiedorowicz)
48 $frm->username = "guest";
49 $frm->password = "guest";
50 } else {
51 $frm = data_submitted();
52 }
a9b07c52 53
d00377f5 54 if ($frm) {
1e22bc9c 55 $frm->username = trim(moodle_strtolower($frm->username));
faebaf0f 56 $user = authenticate_user_login($frm->username, $frm->password);
bee00f48 57 update_login_count();
f9903ed0 58
59 if ($user) {
60 if (! $user->confirmed ) { // they never confirmed via email
fa0626c6 61 print_header(get_string("mustconfirm"), get_string("mustconfirm") );
6bebcf8d 62 print_heading(get_string("mustconfirm"));
63 print_simple_box(get_string("emailconfirmsent", "", $user->email), "center");
8553b700 64 print_footer();
f9903ed0 65 die;
66 }
c21c671d 67
f9903ed0 68 $USER = $user;
dfa1fbac 69 if (!empty($USER->description)) {
70 $USER->description = true; // No need to cart all of it around
71 }
f9903ed0 72 $USER->loggedin = true;
7228f796 73 $USER->site = $CFG->wwwroot; // for added security, store the site in the session
74 $USER->sesskey = random_string(10); // for added security, used to check script parameters
1924074c 75
fcf8e836 76 if ($USER->username == "guest") {
801e1f0a 77 $USER->lang = $CFG->lang; // Guest language always same as site
78 $USER->firstname = get_string("guestuser"); // Name always in current language
4f3d1a63 79 $USER->lastname = " ";
910d1731 80 }
f9903ed0 81
f9903ed0 82 if (!update_user_login_times()) {
83 error("Wierd error: could not update login records");
84 }
8223d271 85
bee00f48 86 set_moodle_cookie($USER->username);
f9903ed0 87
9698bf15 88 $wantsurl = $SESSION->wantsurl;
89
90 unset($SESSION->wantsurl);
28e30091 91 unset($SESSION->lang);
553201b5 92 $SESSION->justloggedin = true;
28e30091 93
089b19f6 94 //Select password change url
95 if (is_internal_auth() || $CFG->{'auth_'.$USER->auth.'_stdchangepassword'}){
96 $passwordchangeurl=$CFG->wwwroot.'/login/change_password.php';
97 } elseif($CFG->changepassword) {
98 $passwordchangeurl=$CFG->changepassword;
99 }
100
101
d35757eb 102 // check whether the user should be changing password
7692b114 103 if (get_user_preferences('auth_forcepasswordchange', false)){
089b19f6 104 if (isset($passwordchangeurl)) {
105 redirect($passwordchangeurl);
d35757eb 106 } else {
107 error("You cannot proceed without changing your password.
108 However there is no available page for changing it.
109 Please contact your Moodle Administrator.");
110 }
111 }
112
089b19f6 113
114
808a3baa 115 if (user_not_fully_set_up($USER)) {
089b19f6 116 $urltogo = $CFG->wwwroot.'/user/edit.php?id='.$USER->id.'&amp;course='.SITEID;
808a3baa 117
9698bf15 118 } else if (strpos($wantsurl, $CFG->wwwroot) === 0) { /// Matches site address
089b19f6 119 $urltogo = $wantsurl;
808a3baa 120
bee00f48 121 } else {
089b19f6 122 $urltogo = $CFG->wwwroot.'/'; /// Go to the standard home page
bee00f48 123 }
089b19f6 124
125 // check if user password has expired
126 // Currently supported only for ldap-authentication module
127 if (isset($CFG->ldap_expiration) && $CFG->ldap_expiration == 1 ) {
128 if (function_exists('auth_password_expire')){
129 $days2expire = auth_password_expire($USER->username);
130 if (intval($days2expire) > 0 && intval($days2expire) < intval($CFG->{$USER->auth.'_expiration_warning'})) {
131 print_header("$site->fullname: $loginsite", "$site->fullname", $loginsite, $focus, "", true, "<div align=\"right\">$langmenu</div>");
132 notice_yesno(get_string('auth_passwordwillexpire', 'auth', $days2expire), $passwordchangeurl, $urltogo);
133 print_footer();
134 exit;
135 } elseif (intval($days2expire) < 0 ) {
136 print_header("$site->fullname: $loginsite", "$site->fullname", $loginsite, $focus, "", true, "<div align=\"right\">$langmenu</div>");
137 notice_yesno(get_string('auth_passwordisexpired', 'auth'), $passwordchangeurl, $urltogo);
138 print_footer();
139 exit;
140 }
141 }
142 }
143
144 redirect($urltogo);
145
bee00f48 146 reset_login_count();
f9903ed0 147
f9903ed0 148 die;
149
150 } else {
fa0626c6 151 $errormsg = get_string("invalidlogin");
f9903ed0 152 }
153 }
8223d271 154
f9903ed0 155
9c9f7d77 156 if (empty($errormsg)) {
157 $errormsg = "";
158 }
159
f9903ed0 160 if (empty($SESSION->wantsurl)) {
ed90bc47 161 $SESSION->wantsurl = array_key_exists('HTTP_REFERER',$_SERVER) ? $_SERVER["HTTP_REFERER"] : $CFG->wwwroot;
f9903ed0 162 }
163
9c9f7d77 164 if (empty($frm->username)) {
f9903ed0 165 $frm->username = get_moodle_cookie();
9c9f7d77 166 $frm->password = "";
167 }
f9903ed0 168
9c9f7d77 169 if (!empty($frm->username)) {
a46b14ef 170 $focus = "login.password";
f9903ed0 171 } else {
a46b14ef 172 $focus = "login.username";
f9903ed0 173 }
35a48c9a 174
5f2c35db 175 if ($CFG->auth == "email" or $CFG->auth == "none" or chop($CFG->auth_instructions) <> "" ) {
35a48c9a 176 $show_instructions = true;
177 } else {
178 $show_instructions = false;
179 }
f9903ed0 180
9a58f7cb 181 print_header("$site->fullname: $loginsite", "$site->fullname", $loginsite, $focus, "", true, "<div align=\"right\">$langmenu</div>");
f9903ed0 182 include("index_form.html");
8553b700 183 print_footer();
f9903ed0 184
185 exit;
186
187 // No footer on this page
188
f9903ed0 189?>