lib MDL-1975 Users who have been auto logged in by guest are now redirected to login...
authorSam Hemelryk <sam@moodle.com>
Fri, 12 Nov 2010 07:53:55 +0000 (07:53 +0000)
committerSam Hemelryk <sam@moodle.com>
Fri, 12 Nov 2010 07:53:55 +0000 (07:53 +0000)
lib/moodlelib.php
lib/setuplib.php

index 60dbcc9..82b82b0 100644 (file)
@@ -2330,6 +2330,7 @@ function require_login($courseorid = NULL, $autologinguest = true, $cm = NULL, $
             }
             $lang = isset($SESSION->lang) ? $SESSION->lang : $CFG->lang;
             complete_user_login($guest, false);
+            $USER->autologinguest = true;
             $SESSION->lang = $lang;
         } else {
             //NOTE: $USER->site check was obsoleted by session test cookie,
index ae94128..116b4b4 100644 (file)
@@ -274,11 +274,16 @@ class invalid_dataroot_permissions extends moodle_exception {
  * @return void -does not return. Terminates execution!
  */
 function default_exception_handler($ex) {
-    global $DB, $OUTPUT;
+    global $CFG, $DB, $OUTPUT, $USER, $FULLME, $SESSION;
 
     // detect active db transactions, rollback and log as error
     abort_all_db_transactions();
 
+    if (($ex instanceof required_capability_exception) && !CLI_SCRIPT && !AJAX_SCRIPT && !empty($CFG->autologinguests) && !empty($USER->autologinguest)) {
+        $SESSION->wantsurl = $FULLME;
+        redirect(get_login_url());
+    }
+
     $info = get_exception_info($ex);
 
     if (debugging('', DEBUG_MINIMAL)) {