MDL-54551 core: AJAX call redirects to login page when session expired
This commit is contained in:
+15
-4
@@ -25,7 +25,7 @@
|
||||
* @license http://www.gnu.org/copyleft/gpl.html GNU GPL v3 or later
|
||||
* @since 2.9
|
||||
*/
|
||||
define(['jquery', 'core/config', 'core/log'], function($, config, Log) {
|
||||
define(['jquery', 'core/config', 'core/log', 'core/yui', 'core/url'], function($, config, Log, Y, URL) {
|
||||
|
||||
// Keeps track of when the user leaves the page so we know not to show an error.
|
||||
var unloading = false;
|
||||
@@ -79,9 +79,20 @@ define(['jquery', 'core/config', 'core/log'], function($, config, Log) {
|
||||
}
|
||||
// Something failed, reject the remaining promises.
|
||||
if (exception !== null) {
|
||||
for (; i < requests.length; i++) {
|
||||
request = requests[i];
|
||||
request.deferred.reject(exception);
|
||||
// If the user isn't doing anything too important, redirect to the login page.
|
||||
if (exception.errorcode === "servicerequireslogin") {
|
||||
Y.use('moodle-core-formchangechecker', function() {
|
||||
if (!M.core_formchangechecker.get_form_dirty_state()) {
|
||||
// If we reach here, the user isn't editing anything on the page.
|
||||
var loginUrl = URL.relativeUrl("/login/index.php");
|
||||
window.location.replace(loginUrl);
|
||||
}
|
||||
});
|
||||
} else {
|
||||
for (; i < requests.length; i++) {
|
||||
request = requests[i];
|
||||
request.deferred.reject(exception);
|
||||
}
|
||||
}
|
||||
}
|
||||
};
|
||||
|
||||
Reference in New Issue
Block a user