MDL-54551 core: AJAX call redirects to login page when session expired

This commit is contained in:
Thom Rawson
2018-07-18 18:07:16 +08:00
committed by Mark Nelson
parent 8c51626841
commit acf94de6d5
4 changed files with 19 additions and 7 deletions
+15 -4
View File
@@ -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);
}
}
}
};