Merge pull request #170 from getgrav/feature/keepalive-in-admin

Keepalive in admin. Fires a 'keepAlive' task 5s before the end of the admin session
This commit is contained in:
Flavio Copes
2015-09-14 15:59:30 +02:00
3 changed files with 22 additions and 1 deletions

View File

@@ -193,6 +193,16 @@ class AdminController
return true;
}
/**
* Handle logout.
*
* @return bool True if the action was performed.
*/
protected function taskKeepAlive()
{
exit();
}
/**
* Handle the email password recovery procedure.
*

View File

@@ -20,6 +20,10 @@ var bytesToSize = function(bytes) {
var isFirefox = navigator.userAgent.toLowerCase().indexOf('firefox') > -1;
var keepAlive = function keepAlive() {
$.post(GravAdmin.config.base_url_relative + '/task' + GravAdmin.config.param_sep + 'keepAlive');
};
$(function () {
jQuery.substitute = function(str, sub) {
return str.replace(/\{(.+?)\}/g, function($0, $1) {
@@ -513,4 +517,10 @@ $(function () {
remodal.find('strong').text(name);
remodal.find('.button.continue').attr('href', $(e.target).attr('href'));
});
// Keep-alive
setInterval(function() {
keepAlive();
}, GravAdmin.config.admin_timeout*1000 - 5*1000); //Call keepAlive() 5s before the admin session timeout
});

View File

@@ -3,6 +3,7 @@
window.GravAdmin.config = {
base_url_relative: '{{ base_url_relative }}',
param_sep: '{{ config.system.param_sep }}',
enable_auto_updates_check: '{{ config.plugins.admin.enable_auto_updates_check }}'
enable_auto_updates_check: '{{ config.plugins.admin.enable_auto_updates_check }}',
admin_timeout: '{{ config.plugins.admin.session.timeout ?: 1800 }}'
};
</script>