diff --git a/data/System/JQAutoLogoutContrib.txt b/data/System/JQAutoLogoutContrib.txt index 17ffbe8..1b6d03b 100644 --- a/data/System/JQAutoLogoutContrib.txt +++ b/data/System/JQAutoLogoutContrib.txt @@ -1,6 +1,7 @@ %META:TOPICINFO{author="micha" comment="reprev" date="1543502605" format="1.1" reprev="2" version="2"}% ---+!! %TOPIC% -%$SHORTDESCRIPTION% +%FORMFIELD{"Description"}% + %TOC% @@ -59,13 +60,14 @@ Note that a single sign on login manager might log you in right after having you ---++ Change History %TABLE{columnwidths="7em" tablewidth="100%"}% +| 07 Dec 2018 | make it work on multiple tabs | | 29 Nov 2018 | initial release | %META:FORM{name="PackageForm"}% %META:FIELD{name="Author" title="Author" value="Michael Daum"}% %META:FIELD{name="Version" title="Version" value="%25$VERSION%25"}% %META:FIELD{name="Release" title="Release" value="%25$RELEASE%25"}% -%META:FIELD{name="Description" title="Description" value=""}% +%META:FIELD{name="Description" title="Description" value="%25$SHORTDESCRIPTION%25"}% %META:FIELD{name="Repository" title="Repository" value="https://github.com/foswiki/%25$ROOTMODULE%25"}% %META:FIELD{name="Copyright" title="Copyright" value="2018, MichaelDaum, All Rights Reserved"}% %META:FIELD{name="License" title="License" value="GPL ([[http://www.gnu.org/copyleft/gpl.html][GNU General Public License]])"}% diff --git a/lib/Foswiki/Contrib/JQAutoLogoutContrib.pm b/lib/Foswiki/Contrib/JQAutoLogoutContrib.pm index e408b21..3874710 100644 --- a/lib/Foswiki/Contrib/JQAutoLogoutContrib.pm +++ b/lib/Foswiki/Contrib/JQAutoLogoutContrib.pm @@ -20,8 +20,8 @@ use warnings; use Foswiki::Func (); -our $VERSION = '1.00'; -our $RELEASE = '29 Nov 2018'; +our $VERSION = '1.01'; +our $RELEASE = '07 Dec 2018'; our $SHORTDESCRIPTION = 'Log out idle user after a certain period of time'; our $NO_PREFS_IN_TOPIC = 1; diff --git a/lib/Foswiki/Contrib/JQAutoLogoutContrib/Core.pm b/lib/Foswiki/Contrib/JQAutoLogoutContrib/Core.pm index 2461f85..3bf6995 100644 --- a/lib/Foswiki/Contrib/JQAutoLogoutContrib/Core.pm +++ b/lib/Foswiki/Contrib/JQAutoLogoutContrib/Core.pm @@ -29,7 +29,7 @@ sub new { my $this = bless( $class->SUPER::new( name => 'JQAutoLogoutContrib', - version => '1.0', + version => '1.01', author => 'Michael Daum', homepage => 'http://foswiki.org/Extensions/JQAutoLogoutContrib', javascript => ['autologout.js'], diff --git a/pub/System/JQAutoLogoutContrib/autologout.uncompressed.js b/pub/System/JQAutoLogoutContrib/autologout.uncompressed.js index 8a4ef38..713f560 100644 --- a/pub/System/JQAutoLogoutContrib/autologout.uncompressed.js +++ b/pub/System/JQAutoLogoutContrib/autologout.uncompressed.js @@ -1,5 +1,5 @@ /* - * AutoLogout + * AutoLogout 1.01 * * Copyright (c) 2018 Michael Daum https://michaeldaumconsulting.com * @@ -18,7 +18,8 @@ disableIf: null, idleTimeout: 900, // 15 minutes countdown: 10, - logoutUrl: null + logoutUrl: null, + localStorageId: "jqAutoLogout.startTime" }; // The actual plugin constructor @@ -83,8 +84,9 @@ AutoLogout.prototype.tickCountdown = function (val) { var self = this; - if (self.idleTimer) { + if (self.idleTimer || self.getIdleTime() < self.opts.idleTimeout) { //console.log("countdown aborted"); + self.elem.dialog("close"); return; // abort } @@ -106,12 +108,45 @@ self.stopTimer(); if (self.isEnabled()) { + + // remember when this timer started + self.setStartTime(); + self.idleTimer = setTimeout(function() { - self.openDialog(); + if (self.getIdleTime() >= self.opts.idleTimeout) { + self.openDialog(); + } else { + self.startTimer(); + } }, self.opts.idleTimeout * 1000); } }; + AutoLogout.prototype.setStartTime = function() { + var self = this; + + localStorage.setItem(self.opts.localStorageId, Date.now()); + }; + + AutoLogout.prototype.getStartTime = function() { + var self = this, startTime; + + startTime = localStorage.getItem(self.opts.localStorageId); + + if (typeof(startTime) !== 'string') { + //console.log("no idle start time"); + return 0; + } + + return parseInt(startTime, 10) + }; + + AutoLogout.prototype.getIdleTime = function() { + var self = this; + + return Math.floor((Date.now() - self.getStartTime()) / 1000); + }; + AutoLogout.prototype.stopTimer = function () { var self = this; @@ -126,6 +161,7 @@ //console.log("redirecting to ",self.opts.logoutUrl); window.location.href = self.opts.logoutUrl; + localStore.removeItem(self.opts.localStorageId); }; AutoLogout.prototype.openDialog = function() { @@ -133,7 +169,6 @@ self.stopTimer(); - self.elem.dialog("open"); };