diff --git a/lib/amd/build/network.min.js b/lib/amd/build/network.min.js index 5b2c28230db..435d01789dd 100644 --- a/lib/amd/build/network.min.js +++ b/lib/amd/build/network.min.js @@ -1 +1 @@ -define(["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=c.sessiontimeout/10*1e3,l=2*k,m=function(){var a={methodname:"core_session_touch",args:{}};return b.call([a],!0,!0,!1,i)[0].then(function(){return h>0&&setTimeout(m,h),!0}).fail(function(){d.alert("",j)})},n=function(){var a={methodname:"core_session_time_remaining",args:{}};return b.call([a],!0,!0,!0)[0].then(function(a){return!(a.userid<=0)&&(a.timeremaining<0?e.get_strings([{key:"sessionexpired",component:"error"},{key:"sessionerroruser",component:"error"}]).then(function(a){return d.alert(a[0],a[1]),!0}).fail(d.exception):1e3*a.timeremaining0?setTimeout(m,h):setTimeout(n,5*k)},p=function(){f||(f=!0,o())},q=function(a,b,c){f||(f=!0,h=1e3*a,j=c,i=1e3*b,o())};return{keepalive:q,init:p}}); \ No newline at end of file +define(["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=2*l,n=function(){k=!0},o=function(){var a={methodname:"core_session_touch",args:{}};return k?e.get_strings([{key:"sessionexpired",component:"error"},{key:"sessionerroruser",component:"error"}]).then(function(a){return d.alert(a[0],a[1]),!0}).fail(d.exception):b.call([a],!0,!0,!1,i)[0].then(function(){return h>0&&setTimeout(o,h),!0}).fail(function(){d.alert("",j)})},p=function(){var a={methodname:"core_session_time_remaining",args:{}};return k=!1,b.call([a],!0,!0,!0)[0].then(function(a){return!(a.userid<=0)&&(a.timeremaining<0?e.get_strings([{key:"sessionexpired",component:"error"},{key:"sessionerroruser",component:"error"}]).then(function(a){return d.alert(a[0],a[1]),!0}).fail(d.exception):1e3*a.timeremaining0?setTimeout(o,h):setTimeout(p,5*l)},r=function(){f||(f=!0,q())},s=function(a,b,c){f||(f=!0,h=1e3*a,j=c,i=1e3*b,q())};return{keepalive:s,init:r}}); \ No newline at end of file diff --git a/lib/amd/src/network.js b/lib/amd/src/network.js index 6a313420d50..5e21a6a6fba 100644 --- a/lib/amd/src/network.js +++ b/lib/amd/src/network.js @@ -29,8 +29,18 @@ define(['jquery', 'core/ajax', 'core/config', 'core/notification', 'core/str'], var keepAliveFrequency = 0; var requestTimeout = 0; var keepAliveMessage = false; - var checkFrequency = (Config.sessiontimeout / 10) * 1000; - var warningLimit = checkFrequency * 2; // 1/5 of sessiontimeout. + var sessionTimeout = false; + // 1/10 of session timeout, max of 10 minutes. + var checkFrequency = Math.min((Config.sessiontimeout / 10), 600) * 1000; + // 1/5 of sessiontimeout. + var warningLimit = checkFrequency * 2; + + /** + * The session time has expired - we can't extend it now. + */ + var timeoutSessionExpired = function() { + sessionTimeout = true; + }; /** * Ping the server to keep the session alive. @@ -43,14 +53,28 @@ define(['jquery', 'core/ajax', 'core/config', 'core/notification', 'core/str'], args: { } }; - return Ajax.call([request], true, true, false, requestTimeout)[0].then(function() { - if (keepAliveFrequency > 0) { - setTimeout(touchSession, keepAliveFrequency); - } - return true; - }).fail(function() { - Notification.alert('', keepAliveMessage); - }); + if (sessionTimeout) { + // We timed out before we extended the session. + return Str.get_strings([ + {key: 'sessionexpired', component: 'error'}, + {key: 'sessionerroruser', component: 'error'} + ]).then(function(strings) { + Notification.alert( + strings[0], // Title. + strings[1] // Message. + ); + return true; + }).fail(Notification.exception); + } else { + return Ajax.call([request], true, true, false, requestTimeout)[0].then(function() { + if (keepAliveFrequency > 0) { + setTimeout(touchSession, keepAliveFrequency); + } + return true; + }).fail(function() { + Notification.alert('', keepAliveMessage); + }); + } }; /** @@ -65,6 +89,7 @@ define(['jquery', 'core/ajax', 'core/config', 'core/notification', 'core/str'], args: { } }; + sessionTimeout = false; return Ajax.call([request], true, true, true)[0].then(function(args) { if (args.userid <= 0) { return false; @@ -82,6 +107,8 @@ define(['jquery', 'core/ajax', 'core/config', 'core/notification', 'core/str'], }).fail(Notification.exception); } else if (args.timeremaining * 1000 < warningLimit && !warningDisplayed) { + // If we don't extend the session before the timeout - warn. + setTimeout(timeoutSessionExpired, args.timeremaining * 1000); warningDisplayed = true; Str.get_strings([ {key: 'norecentactivity', component: 'moodle'},