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

This commit is contained in:
Tim Hunt
2021-06-29 16:58:06 +01:00
parent a747fd3055
commit 0bb2d16337
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=0<c.sessiontimeoutwarning?1e3*c.sessiontimeoutwarning:2*l,n=0<c.sessiontimeoutwarning?Math.min(1e3*(c.sessiontimeout-c.sessiontimeoutwarning),5*l):5*l,o=function(a){k=!0;g=!1;p(a);q()},p=function(a){a.destroy()},q=function(){return b.call([{methodname:"core_session_time_remaining",args:{}}],!0,!0,!0)[0].then(function(a){if(1e3*a.timeremaining>m){return!1}else{return e.get_strings([{key:"sessionexpired",component:"error"},{key:"sessionerroruser",component:"error"},{key:"loginagain",component:"moodle"},{key:"cancel",component:"moodle"}]).then(function(a){d.confirm(a[0],a[1],a[2],a[3],function(){location.reload();return!0});return!0}).catch(d.exception)}})},r=function(){if(k){return q()}else{return b.call([{methodname:"core_session_touch",args:{}}],!0,!0,!1,i)[0].then(function(){if(0<h){setTimeout(r,h)}return!0}).catch(function(){d.alert("",j)})}},s=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){return q()}else if(1e3*a.timeremaining<=m&&!g){g=!0;e.get_strings([{key:"norecentactivity",component:"moodle"},{key:"sessiontimeoutsoon",component:"moodle"},{key:"extendsession",component:"moodle"},{key:"cancel",component:"moodle"}]).then(function(a){return d.confirm(a[0],a[1],a[2],a[3],function(){r();g=!1;setTimeout(s,n);return!0},function(){setTimeout(s,l)})}).then(function(b){setTimeout(o,1e3*a.timeremaining,b)}).catch(d.exception)}else{setTimeout(s,l)}return!0})},t=function(){if(0<h){setTimeout(r,h)}else{setTimeout(s,n)}},u=function(){if(f){return}f=!0;t()},v=function(a,b,c){if(f){return}f=!0;h=1e3*a;j=c;i=1e3*b;t()};return{keepalive:v,init:u}});
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=0<c.sessiontimeoutwarning?1e3*c.sessiontimeoutwarning:2*l,n=0<c.sessiontimeoutwarning?Math.min(1e3*(c.sessiontimeout-c.sessiontimeoutwarning),5*l):5*l,o=function(a){k=!0;g=!1;p(a);q()},p=function(a){a.destroy()},q=function(){return b.call([{methodname:"core_session_time_remaining",args:{}}],!0,!0,!0)[0].then(function(a){if(1e3*a.timeremaining>m){return!1}else{return e.get_strings([{key:"sessionexpired",component:"error"},{key:"sessionerroruser",component:"error"},{key:"loginagain",component:"moodle"},{key:"cancel",component:"moodle"}]).then(function(a){d.confirm(a[0],a[1],a[2],a[3],function(){location.reload();return!0});return!0}).catch(d.exception)}})},r=function(){if(k){return q()}else{return b.call([{methodname:"core_session_touch",args:{}}],!0,!0,!1,i)[0].then(function(){if(0<h){setTimeout(r,h)}return!0}).catch(function(){d.alert("",j)})}},s=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){return q()}else if(1e3*a.timeremaining<=m&&!g){g=!0;e.get_strings([{key:"norecentactivity",component:"moodle"},{key:"sessiontimeoutsoon",component:"moodle"},{key:"extendsession",component:"moodle"},{key:"cancel",component:"moodle"}]).then(function(a){return d.confirm(a[0],a[1],a[2],a[3],function(){r();g=!1;setTimeout(s,n);return!0},function(){setTimeout(s,l)})}).then(function(b){setTimeout(o,1e3*a.timeremaining,b)}).catch(d.exception)}else{setTimeout(s,l)}return!0})},t=function(){if(0<h){setTimeout(r,h)}else{setTimeout(s,n)}},u=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)},v=function(){if(f){return}f=!0;if(u()){window.console.log("Not starting Moodle session timeout warning in this iframe.");return}window.console.log("Starting Moodle session timeout warning.");t()},w=function(a,b,c){if(f){window.console.warn("Ignoring session keep-alive. The core/network module was already initialised.");return}f=!0;if(u()){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;t()};return{keepalive:w,init:v}});
//# sourceMappingURL=network.min.js.map
File diff suppressed because one or more lines are too long
+38
View File
@@ -188,6 +188,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.
*/
@@ -198,6 +221,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();
};
@@ -211,10 +241,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;