corrected the indenting of forumposts and set the width of the posts to screenwidth...
[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
792197b0 54 if ($frm and (get_moodle_cookie() == '')) { // Login without cookie
55
56 $errormsg = get_string("cookiesnotenabled");
57
30b88cb7 58 } else if ($frm) { // Login WITH cookies
792197b0 59
1e22bc9c 60 $frm->username = trim(moodle_strtolower($frm->username));
cf5560fb 61
62 if (($frm->username == 'guest') and empty($CFG->guestloginbutton)) {
63 $user = false; /// Can't log in as guest if guest button is disabled
64 $frm = false;
cfbe930c 65 } else {
cf5560fb 66 $user = authenticate_user_login($frm->username, $frm->password);
67 }
bee00f48 68 update_login_count();
f9903ed0 69
70 if ($user) {
71 if (! $user->confirmed ) { // they never confirmed via email
fa0626c6 72 print_header(get_string("mustconfirm"), get_string("mustconfirm") );
6bebcf8d 73 print_heading(get_string("mustconfirm"));
74 print_simple_box(get_string("emailconfirmsent", "", $user->email), "center");
8553b700 75 print_footer();
f9903ed0 76 die;
77 }
c21c671d 78
f9903ed0 79 $USER = $user;
dfa1fbac 80 if (!empty($USER->description)) {
1a33f699 81 $USER->description = true; // No need to cart all of it around
dfa1fbac 82 }
f9903ed0 83 $USER->loggedin = true;
1a33f699 84 $USER->site = $CFG->wwwroot; // for added security, store the site in the session
04280e85 85 sesskey(); // for added security, used to check script parameters
1a33f699 86
fcf8e836 87 if ($USER->username == "guest") {
801e1f0a 88 $USER->lang = $CFG->lang; // Guest language always same as site
89 $USER->firstname = get_string("guestuser"); // Name always in current language
4f3d1a63 90 $USER->lastname = " ";
910d1731 91 }
f9903ed0 92
f9903ed0 93 if (!update_user_login_times()) {
94 error("Wierd error: could not update login records");
95 }
8223d271 96
bee00f48 97 set_moodle_cookie($USER->username);
f9903ed0 98
9698bf15 99 $wantsurl = $SESSION->wantsurl;
100
101 unset($SESSION->wantsurl);
28e30091 102 unset($SESSION->lang);
553201b5 103 $SESSION->justloggedin = true;
28e30091 104
054193be 105 // Restore the calendar filters, if saved
106 if(intval(get_user_preferences('calendar_persistflt', 0))) {
107 include_once($CFG->dirroot.'/calendar/lib.php');
108 calendar_set_filters_status(get_user_preferences('calendar_savedflt', 0xff));
109 }
110
089b19f6 111 //Select password change url
112 if (is_internal_auth() || $CFG->{'auth_'.$USER->auth.'_stdchangepassword'}){
113 $passwordchangeurl=$CFG->wwwroot.'/login/change_password.php';
114 } elseif($CFG->changepassword) {
115 $passwordchangeurl=$CFG->changepassword;
116 }
117
118
d35757eb 119 // check whether the user should be changing password
7692b114 120 if (get_user_preferences('auth_forcepasswordchange', false)){
089b19f6 121 if (isset($passwordchangeurl)) {
122 redirect($passwordchangeurl);
d35757eb 123 } else {
124 error("You cannot proceed without changing your password.
125 However there is no available page for changing it.
126 Please contact your Moodle Administrator.");
127 }
128 }
129
089b19f6 130
bcdcbccc 131 add_to_log(SITEID, "user", "login", "view.php?id=$user->id&course=".SITEID, $user->id, 0, $user->id);
089b19f6 132
808a3baa 133 if (user_not_fully_set_up($USER)) {
089b19f6 134 $urltogo = $CFG->wwwroot.'/user/edit.php?id='.$USER->id.'&amp;course='.SITEID;
808a3baa 135
9698bf15 136 } else if (strpos($wantsurl, $CFG->wwwroot) === 0) { /// Matches site address
089b19f6 137 $urltogo = $wantsurl;
808a3baa 138
bee00f48 139 } else {
089b19f6 140 $urltogo = $CFG->wwwroot.'/'; /// Go to the standard home page
bee00f48 141 }
089b19f6 142
143 // check if user password has expired
144 // Currently supported only for ldap-authentication module
145 if (isset($CFG->ldap_expiration) && $CFG->ldap_expiration == 1 ) {
146 if (function_exists('auth_password_expire')){
147 $days2expire = auth_password_expire($USER->username);
148 if (intval($days2expire) > 0 && intval($days2expire) < intval($CFG->{$USER->auth.'_expiration_warning'})) {
149 print_header("$site->fullname: $loginsite", "$site->fullname", $loginsite, $focus, "", true, "<div align=\"right\">$langmenu</div>");
150 notice_yesno(get_string('auth_passwordwillexpire', 'auth', $days2expire), $passwordchangeurl, $urltogo);
151 print_footer();
152 exit;
153 } elseif (intval($days2expire) < 0 ) {
154 print_header("$site->fullname: $loginsite", "$site->fullname", $loginsite, $focus, "", true, "<div align=\"right\">$langmenu</div>");
155 notice_yesno(get_string('auth_passwordisexpired', 'auth'), $passwordchangeurl, $urltogo);
156 print_footer();
157 exit;
158 }
159 }
160 }
161
bee00f48 162 reset_login_count();
f9903ed0 163
bcdcbccc 164 redirect($urltogo);
165
f9903ed0 166 die;
167
168 } else {
fa0626c6 169 $errormsg = get_string("invalidlogin");
f9903ed0 170 }
171 }
8223d271 172
f9903ed0 173
9c9f7d77 174 if (empty($errormsg)) {
175 $errormsg = "";
176 }
177
f9903ed0 178 if (empty($SESSION->wantsurl)) {
ed90bc47 179 $SESSION->wantsurl = array_key_exists('HTTP_REFERER',$_SERVER) ? $_SERVER["HTTP_REFERER"] : $CFG->wwwroot;
f9903ed0 180 }
792197b0 181
182 if (get_moodle_cookie() == '') {
183 set_moodle_cookie('nobody'); // To help search for cookies
184 }
f9903ed0 185
9c9f7d77 186 if (empty($frm->username)) {
792197b0 187 $frm->username = get_moodle_cookie() === 'nobody' ? '' : get_moodle_cookie();
9c9f7d77 188 $frm->password = "";
189 }
f9903ed0 190
9c9f7d77 191 if (!empty($frm->username)) {
a46b14ef 192 $focus = "login.password";
f9903ed0 193 } else {
a46b14ef 194 $focus = "login.username";
f9903ed0 195 }
35a48c9a 196
5f2c35db 197 if ($CFG->auth == "email" or $CFG->auth == "none" or chop($CFG->auth_instructions) <> "" ) {
35a48c9a 198 $show_instructions = true;
199 } else {
200 $show_instructions = false;
201 }
f9903ed0 202
9a58f7cb 203 print_header("$site->fullname: $loginsite", "$site->fullname", $loginsite, $focus, "", true, "<div align=\"right\">$langmenu</div>");
f9903ed0 204 include("index_form.html");
8553b700 205 print_footer();
f9903ed0 206
207 exit;
208
209 // No footer on this page
210
f9903ed0 211?>