~ubuntu-branches/ubuntu/jaunty/moodle/jaunty

« back to all changes in this revision

Viewing changes to login/index.php

  • Committer: Bazaar Package Importer
  • Author(s): Jordan Mantha, Matt Oquist
  • Date: 2009-02-25 15:16:22 UTC
  • mfrom: (1.1.11 upstream)
  • Revision ID: james.westby@ubuntu.com-20090225151622-0ekt1liwhv2obfza
Tags: 1.9.4.dfsg-0ubuntu1
* Merge with Debian git (Closes LP: #322961, #239481, #334611):
  - use Ubuntu's smarty lib directory for linking
  - use internal yui library 
  - add update-notifier support back in

[Matt Oquist]
  * renamed prerm script
  * significantly rewrote postinst and other maintainer scripts to improve
    user experience and package maintainability
    (Closes LP: #225662, #325450, #327843, #303078, #234609)

Show diffs side-by-side

added added

removed removed

Lines of Context:
1
 
<?php // $Id: index.php,v 1.109.2.13 2007/07/06 17:39:56 stronk7 Exp $
 
1
<?php // $Id: index.php,v 1.129.2.3 2008/05/18 21:26:57 iarenaza Exp $
2
2
 
3
3
 
4
4
    require_once("../config.php");
14
14
 
15
15
    //initialize variables
16
16
    $errormsg = '';
 
17
    $errorcode = 0;
17
18
 
18
19
/// Check for timed out sessions
19
20
    if (!empty($SESSION->has_timed_out)) {
24
25
    }
25
26
 
26
27
/// Check if the guest user exists.  If not, create one.
27
 
    if (! record_exists('user', 'username', 'guest')) {
 
28
    if (! record_exists('user', 'username', 'guest', 'mnethostid', $CFG->mnet_localhost_id)) {
28
29
        if (! $guest = create_guest_record()) {
29
30
            notify('Could not create guest user record !!!');
30
31
        }
63
64
    } else {
64
65
        $currlang = current_language();
65
66
        $langs    = get_list_of_languages();
66
 
        $langlabel = '<span class="accesshide">'.get_string('language').':</span>';
 
67
        $langlabel = get_accesshide(get_string('language'));
67
68
        $langmenu = popup_form ("$CFG->httpswwwroot/login/index.php?lang=", $langs, "chooselang", $currlang, "", "", "", true, 'self', $langlabel);
68
69
    }
69
70
 
70
71
    $loginsite = get_string("loginsite");
71
 
 
72
 
    $loginurl = (!empty($CFG->alternateloginurl)) ? $CFG->alternateloginurl : '';
73
 
 
 
72
    $navlinks = array(array('name' => $loginsite, 'link' => null, 'type' => 'misc'));
 
73
    $navigation = build_navigation($navlinks);
74
74
 
75
75
    if ($user !== false or $frm !== false) {
76
76
        // some auth plugin already supplied these
90
90
        if ($user) {
91
91
            $frm->username = $user->username;
92
92
        } else {
93
 
            $frm = data_submitted($loginurl);
 
93
            $frm = data_submitted();
94
94
        }
95
95
 
96
96
    } else {
97
 
        $frm = data_submitted($loginurl);
 
97
        $frm = data_submitted();
98
98
    }
99
99
 
100
100
/// Check if the user has actually submitted login data to us
102
102
    if (empty($CFG->usesid) and $testcookies and (get_moodle_cookie() == '')) {    // Login without cookie when test requested
103
103
 
104
104
        $errormsg = get_string("cookiesnotenabled");
 
105
        $errorcode = 1;
105
106
 
106
107
    } else if ($frm) {                             // Login WITH cookies
107
108
 
111
112
            $string = eregi_replace("[^(-\.[:alnum:])]", "", $frm->username);
112
113
            if (strcmp($frm->username, $string)) {
113
114
                $errormsg = get_string('username').': '.get_string("alphanumerical");
 
115
                $errorcode = 2;
 
116
 
114
117
                $user = null;
115
118
            }
116
119
        }
140
143
            }
141
144
 
142
145
            if (empty($user->confirmed)) {       // This account was never confirmed
143
 
                print_header(get_string("mustconfirm"), get_string("mustconfirm") ); 
 
146
                print_header(get_string("mustconfirm"), get_string("mustconfirm") );
144
147
                print_heading(get_string("mustconfirm"));
145
148
                print_simple_box(get_string("emailconfirmsent", "", $user->email), "center");
146
149
                print_footer();
147
150
                die;
148
151
            }
149
152
 
150
 
            // Let's get them all set up.
151
 
            $USER = $user;
152
 
 
153
 
            add_to_log(SITEID, 'user', 'login', "view.php?id=$USER->id&course=".SITEID, $USER->id, 0, $USER->id);
154
 
 
155
 
 
156
 
            update_user_login_times();
157
 
            if (empty($CFG->nolastloggedin)) {
158
 
                set_moodle_cookie($USER->username);
159
 
            } else {
160
 
                // do not store last logged in user in cookie
161
 
                // auth plugins can temporarily override this from loginpage_hook()
162
 
                // do not save $CFG->nolastloggedin in database!
163
 
                set_moodle_cookie('nobody');
164
 
            }
165
 
            set_login_session_preferences();
166
 
 
167
 
            /// This is what lets the user do anything on the site :-)
168
 
            load_all_capabilities();
169
 
 
170
 
            //Select password change url
171
 
            $userauth = get_auth_plugin($USER->auth);
172
 
            if ($userauth->can_change_password()) {
173
 
                if ($userauth->change_password_url()) {
174
 
                    $passwordchangeurl = $userauth->change_password_url();
175
 
                } else {
176
 
                    $passwordchangeurl = $CFG->httpswwwroot.'/login/change_password.php';
177
 
                }
178
 
            } else {
179
 
                $passwordchangeurl = '';
180
 
            }
181
 
 
182
 
            // check whether the user should be changing password
183
 
            if (get_user_preferences('auth_forcepasswordchange', false) || $frm->password == 'changeme'){
184
 
                if ($passwordchangeurl != '') {
185
 
                    redirect($passwordchangeurl);
186
 
                } else {
187
 
                    error(get_strin('nopasswordchangeforced', 'auth'));
188
 
                }
189
 
            }
190
 
 
191
 
 
192
 
          /// Prepare redirection
 
153
            if ($frm->password == 'changeme') {
 
154
                //force the change
 
155
                set_user_preference('auth_forcepasswordchange', true, $user->id);
 
156
            }
 
157
 
 
158
        /// Let's get them all set up.
 
159
            add_to_log(SITEID, 'user', 'login', "view.php?id=$USER->id&course=".SITEID,
 
160
                       $user->id, 0, $user->id);
 
161
            $USER = complete_user_login($user);
 
162
 
 
163
        /// Prepare redirection
193
164
            if (user_not_fully_set_up($USER)) {
194
165
                $urltogo = $CFG->wwwroot.'/user/edit.php';
195
166
                // We don't delete $SESSION->wantsurl yet, so we get there later
204
175
                unset($SESSION->wantsurl);
205
176
            }
206
177
 
207
 
          /// Go to my-moodle page instead of homepage if mymoodleredirect enabled
 
178
        /// Go to my-moodle page instead of homepage if mymoodleredirect enabled
208
179
            if (!has_capability('moodle/site:config',get_context_instance(CONTEXT_SYSTEM)) and !empty($CFG->mymoodleredirect) and !isguest()) {
209
180
                if ($urltogo == $CFG->wwwroot or $urltogo == $CFG->wwwroot.'/' or $urltogo == $CFG->wwwroot.'/index.php') {
210
181
                    $urltogo = $CFG->wwwroot.'/my/';
212
183
            }
213
184
 
214
185
 
215
 
            // check if user password has expired
216
 
            // Currently supported only for ldap-authentication module
 
186
        /// check if user password has expired
 
187
        /// Currently supported only for ldap-authentication module
 
188
            $userauth = get_auth_plugin($USER->auth);
217
189
            if (!empty($userauth->config->expiration) and $userauth->config->expiration == 1) {
218
 
                    $days2expire = $userauth->password_expire($USER->username);
219
 
                        if (intval($days2expire) > 0 && intval($days2expire) < intval($userauth->config->expiration_warning)) {
220
 
                        print_header("$site->fullname: $loginsite", "$site->fullname", $loginsite, $focus, "", true, "<div class=\"langmenu\">$langmenu</div>"); 
221
 
                        notice_yesno(get_string('auth_passwordwillexpire', 'auth', $days2expire), $passwordchangeurl, $urltogo); 
222
 
                        print_footer();
223
 
                        exit;
224
 
                    } elseif (intval($days2expire) < 0 ) {
225
 
                        print_header("$site->fullname: $loginsite", "$site->fullname", $loginsite, $focus, "", true, "<div class=\"langmenu\">$langmenu</div>"); 
226
 
                        notice_yesno(get_string('auth_passwordisexpired', 'auth'), $passwordchangeurl, $urltogo);
227
 
                        print_footer();
228
 
                        exit;
229
 
                    }    
 
190
                if ($userauth->can_change_password()) {
 
191
                    $passwordchangeurl = $userauth->change_password_url();
 
192
                } else {
 
193
                    $passwordchangeurl = $CFG->httpswwwroot.'/login/change_password.php';
 
194
                }
 
195
                $days2expire = $userauth->password_expire($USER->username);
 
196
                if (intval($days2expire) > 0 && intval($days2expire) < intval($userauth->config->expiration_warning)) {
 
197
                    print_header("$site->fullname: $loginsite", "$site->fullname", $navigation, '', '', true, "<div class=\"langmenu\">$langmenu</div>");
 
198
                    notice_yesno(get_string('auth_passwordwillexpire', 'auth', $days2expire), $passwordchangeurl, $urltogo);
 
199
                    print_footer();
 
200
                    exit;
 
201
                } elseif (intval($days2expire) < 0 ) {
 
202
                    print_header("$site->fullname: $loginsite", "$site->fullname", $navigation, '', '', true, "<div class=\"langmenu\">$langmenu</div>");
 
203
                    notice_yesno(get_string('auth_passwordisexpired', 'auth'), $passwordchangeurl, $urltogo);
 
204
                    print_footer();
 
205
                    exit;
 
206
                }
230
207
            }
231
208
 
232
209
            reset_login_count();
234
211
            redirect($urltogo);
235
212
 
236
213
            exit;
237
 
    
 
214
 
238
215
        } else {
239
216
            if (empty($errormsg)) {
240
217
                $errormsg = get_string("invalidlogin");
 
218
                $errorcode = 3;
241
219
            }
242
220
 
243
221
            // TODO: if the user failed to authenticate, check if the username corresponds to a remote mnet user
244
 
            if ( !empty($CFG->mnet_dispatcher_mode) 
 
222
            if ( !empty($CFG->mnet_dispatcher_mode)
245
223
                 && $CFG->mnet_dispatcher_mode === 'strict'
246
224
                 && is_enabled_auth('mnet')) {
247
225
                $errormsg .= get_string('loginlinkmnetuser', 'mnet', "mnet_email.php?u=$frm->username");
249
227
        }
250
228
    }
251
229
 
252
 
    
253
 
/// We need to show a login form
 
230
/// Detect problems with timedout sessions
 
231
    if ($session_has_timed_out and !data_submitted()) {
 
232
        $errormsg = get_string('sessionerroruser', 'error');
 
233
        $errorcode = 4;
 
234
    }
254
235
 
255
236
/// First, let's remember where the user was trying to get to before they got here
256
237
 
257
238
    if (empty($SESSION->wantsurl)) {
258
 
        $SESSION->wantsurl = (array_key_exists('HTTP_REFERER',$_SERVER) && 
259
 
                              $_SERVER["HTTP_REFERER"] != $CFG->wwwroot && 
 
239
        $SESSION->wantsurl = (array_key_exists('HTTP_REFERER',$_SERVER) &&
 
240
                              $_SERVER["HTTP_REFERER"] != $CFG->wwwroot &&
260
241
                              $_SERVER["HTTP_REFERER"] != $CFG->wwwroot.'/' &&
261
242
                              $_SERVER["HTTP_REFERER"] != $CFG->httpswwwroot.'/login/' &&
262
243
                              $_SERVER["HTTP_REFERER"] != $CFG->httpswwwroot.'/login/index.php')
263
244
            ? $_SERVER["HTTP_REFERER"] : NULL;
264
245
    }
265
246
 
266
 
    if (!empty($loginurl)) {   // We don't want the standard forms, go elsewhere
 
247
/// Redirect to alternative login URL if needed
 
248
    if (!empty($CFG->alternateloginurl)) {
 
249
        $loginurl = $CFG->alternateloginurl;
 
250
 
 
251
        if (strpos($SESSION->wantsurl, $loginurl) === 0) {
 
252
            //we do not want to return to alternate url
 
253
            $SESSION->wantsurl = NULL;
 
254
        }
 
255
 
 
256
        if ($errorcode) {
 
257
            if (strpos($loginurl, '?') === false) {
 
258
                $loginurl .= '?';
 
259
            } else {
 
260
                $loginurl .= '&';
 
261
            }
 
262
            $loginurl .= 'errorcode='.$errorcode;
 
263
        }
 
264
 
267
265
        redirect($loginurl);
268
266
    }
269
 
    
 
267
 
270
268
 
271
269
/// Generate the login page with forms
272
270
 
273
 
    if ($session_has_timed_out) {
274
 
        $errormsg = get_string('sessionerroruser', 'error');
275
 
    }
276
 
 
277
 
    if (get_moodle_cookie() == '') {   
 
271
    if (get_moodle_cookie() == '') {
278
272
        set_moodle_cookie('nobody');   // To help search for cookies
279
273
    }
280
 
    
 
274
 
281
275
    if (empty($frm->username) && $authsequence[0] != 'shibboleth') {  // See bug 5184
282
276
        $frm->username = get_moodle_cookie() === 'nobody' ? '' : get_moodle_cookie();
283
277
        $frm->password = "";
284
278
    }
285
 
    
 
279
 
286
280
    if (!empty($frm->username)) {
287
281
        $focus = "password";
288
282
    } else {
295
289
        $show_instructions = false;
296
290
    }
297
291
 
298
 
    print_header("$site->fullname: $loginsite", $site->fullname, $loginsite, $focus, 
299
 
                 '', true, '<div class="langmenu">'.$langmenu.'</div>'); 
 
292
    print_header("$site->fullname: $loginsite", $site->fullname, $navigation, $focus,
 
293
                 '', true, '<div class="langmenu">'.$langmenu.'</div>');
300
294
 
301
295
    include("index_form.html");
302
296