MDL-68003 session timeout warning: don't show in iframes

This commit is contained in:
Tim Hunt
2021-06-29 17:00:12 +01:00
parent 017dce9cc3
commit ce80aa2a90
3 changed files with 40 additions and 2 deletions
+1 -1
View File
@@ -1,2 +1,2 @@
define ("core/network",["jquery","core/ajax","core/config","core/notification","core/str"],function(a,b,c,d,e){var f=!1,g=!1,h=0,i=0,j=!1,k=!1,l=1e3*Math.min(c.sessiontimeout/10,600),m=function(){k=!0},n=function(){if(k){return e.get_strings([{key:"sessionexpired",component:"error"},{key:"sessionerroruser",component:"error"}]).then(function(a){d.alert(a[0],a[1]);return!0}).fail(d.exception)}else{return b.call([{methodname:"core_session_touch",args:{}}],!0,!0,!1,i)[0].then(function(){if(0<h){setTimeout(n,h)}return!0}).fail(function(){d.alert("",j)})}},o=function(){k=!1;return b.call([{methodname:"core_session_time_remaining",args:{}}],!0,!0,!0)[0].then(function(a){if(0>=a.userid){return!1}if(0>a.timeremaining){e.get_strings([{key:"sessionexpired",component:"error"},{key:"sessionerroruser",component:"error"}]).then(function(a){d.alert(a[0],a[1]);return!0}).fail(d.exception)}else if(1e3*a.timeremaining<2*l&&!g){setTimeout(m,1e3*a.timeremaining);g=!0;e.get_strings([{key:"norecentactivity",component:"moodle"},{key:"sessiontimeoutsoon",component:"moodle"},{key:"extendsession",component:"moodle"},{key:"cancel",component:"moodle"}]).then(function(a){d.confirm(a[0],a[1],a[2],a[3],function(){n();g=!1;setTimeout(o,5*l);return!0},function(){g=!1;setTimeout(o,l)});return!0}).fail(d.exception)}else{setTimeout(o,l)}return!0})},p=function(){if(0<h){setTimeout(n,h)}else{setTimeout(o,5*l)}},q=function(){if(f){return}f=!0;p()},r=function(a,b,c){if(f){return}f=!0;h=1e3*a;j=c;i=1e3*b;p()};return{keepalive:r,init:q}});
define ("core/network",["jquery","core/ajax","core/config","core/notification","core/str"],function(a,b,c,d,e){var f=!1,g=!1,h=0,i=0,j=!1,k=!1,l=1e3*Math.min(c.sessiontimeout/10,600),m=function(){k=!0},n=function(){if(k){return e.get_strings([{key:"sessionexpired",component:"error"},{key:"sessionerroruser",component:"error"}]).then(function(a){d.alert(a[0],a[1]);return!0}).fail(d.exception)}else{return b.call([{methodname:"core_session_touch",args:{}}],!0,!0,!1,i)[0].then(function(){if(0<h){setTimeout(n,h)}return!0}).fail(function(){d.alert("",j)})}},o=function(){k=!1;return b.call([{methodname:"core_session_time_remaining",args:{}}],!0,!0,!0)[0].then(function(a){if(0>=a.userid){return!1}if(0>a.timeremaining){e.get_strings([{key:"sessionexpired",component:"error"},{key:"sessionerroruser",component:"error"}]).then(function(a){d.alert(a[0],a[1]);return!0}).fail(d.exception)}else if(1e3*a.timeremaining<2*l&&!g){setTimeout(m,1e3*a.timeremaining);g=!0;e.get_strings([{key:"norecentactivity",component:"moodle"},{key:"sessiontimeoutsoon",component:"moodle"},{key:"extendsession",component:"moodle"},{key:"cancel",component:"moodle"}]).then(function(a){d.confirm(a[0],a[1],a[2],a[3],function(){n();g=!1;setTimeout(o,5*l);return!0},function(){g=!1;setTimeout(o,l)});return!0}).fail(d.exception)}else{setTimeout(o,l)}return!0})},p=function(){if(0<h){setTimeout(n,h)}else{setTimeout(o,5*l)}},q=function(){if(window.parent===window){return!1}var a;try{a=window.parent.location.href}catch(a){return!1}return a.startsWith(M.cfg.wwwroot)},r=function(){if(f){return}f=!0;if(q()){window.console.log("Not starting Moodle session timeout warning in this iframe.");return}window.console.log("Starting Moodle session timeout warning.");p()},s=function(a,b,c){if(f){window.console.warn("Ignoring session keep-alive. The core/network module was already initialised.");return}f=!0;if(q()){window.console.warn("Ignoring session keep-alive in this iframe inside another Moodle page.");return}window.console.log("Starting Moodle session keep-alive.");h=1e3*a;j=c;i=1e3*b;p()};return{keepalive:s,init:r}});
//# sourceMappingURL=network.min.js.map
File diff suppressed because one or more lines are too long
+38
View File
@@ -155,6 +155,29 @@ define(['jquery', 'core/ajax', 'core/config', 'core/notification', 'core/str'],
}
};
/**
* Are we in an iframe and the parent page is from the same Moodle site?
*
* @return {boolean} true if we are in an iframe in a page from this Moodle site.
*/
const isMoodleIframe = function() {
if (window.parent === window) {
// Not in an iframe.
return false;
}
// We are in an iframe. Is the parent from the same Moodle site?
let parentUrl;
try {
parentUrl = window.parent.location.href;
} catch (e) {
// If we cannot access the URL of the parent page, it must be another site.
return false;
}
return parentUrl.startsWith(M.cfg.wwwroot);
};
/**
* Don't allow more than one of these polling loops in a single page.
*/
@@ -165,6 +188,13 @@ define(['jquery', 'core/ajax', 'core/config', 'core/notification', 'core/str'],
}
started = true;
if (isMoodleIframe()) {
window.console.log('Not starting Moodle session timeout warning in this iframe.');
return;
}
window.console.log('Starting Moodle session timeout warning.');
start();
};
@@ -178,10 +208,18 @@ define(['jquery', 'core/ajax', 'core/config', 'core/notification', 'core/str'],
var keepalive = function(freq, timeout, message) {
// We only allow one concurrent instance of this checker.
if (started) {
window.console.warn('Ignoring session keep-alive. The core/network module was already initialised.');
return;
}
started = true;
if (isMoodleIframe()) {
window.console.warn('Ignoring session keep-alive in this iframe inside another Moodle page.');
return;
}
window.console.log('Starting Moodle session keep-alive.');
keepAliveFrequency = freq * 1000;
keepAliveMessage = message;
requestTimeout = timeout * 1000;