MDL-29678 lib: Require login now overrides to false for AJAX scripts
authorSam Hemelryk <sam@moodle.com>
Mon, 26 Mar 2012 22:48:51 +0000 (11:48 +1300)
committerSam Hemelryk <sam@moodle.com>
Thu, 29 Mar 2012 21:23:46 +0000 (10:23 +1300)
lib/moodlelib.php

index fe642a9..0353c86 100644 (file)
@@ -2682,6 +2682,13 @@ function require_login($courseorid = NULL, $autologinguest = true, $cm = NULL, $
         }
     }
 
+    // If this is an AJAX request and $setwantsurltome is true then we need to override it and set it to false.
+    // Otherwise the AJAX request URL will be set to $SESSION->wantsurl and events such as self enrolment in the future
+    // risk leading the user back to the AJAX request URL.
+    if ($setwantsurltome && defined('AJAX_SCRIPT') && AJAX_SCRIPT) {
+        $setwantsurltome = false;
+    }
+
     // If the user is not even logged in yet then make sure they are
     if (!isloggedin()) {
         if ($autologinguest and !empty($CFG->guestloginbutton) and !empty($CFG->autologinguests)) {