From 05375ac5cd95824efaf5d964fb40dca4035cc1aa Mon Sep 17 00:00:00 2001 From: Brian Teller Date: Thu, 3 Aug 2017 11:11:03 -0400 Subject: [PATCH 1/2] Added Keep Alive Response Checking I wanted to add the ability to actually check the response of the keep alive polling. Like other jQuery-idle-Timeout versions (specifically @ehynds 's version https://github.com/ehynds/jquery-idle-timeout) Added variable 'keepAliveResponse' If 'keepAliveResponse' is set to false, response is ignored/disregarded (like it already was prior to this PR). If 'keepAliveResponse' is set to a string (eg. 'OK') then the ajax response from keepAliveUrl is verified against the string. If its different, then the user is redirected to 'keepAliveBadUrl' Added variable 'keepAliveBadUrl' to set a given URL to redirect to if the above 'keepAliveResponse' is set to anything other than false. This is useful if you are using the polling of keepAliveUrl to check on settings (in my example, I verify the user's session still exists, if it does I return "OK" if it doesn't I return "ERROR" prompting the redirect to the login page). You could also use this to check on other critical information and redirect to an error page. keepAliveBadUrl could even be modified to show a model dialog window or something. --- src/jquery-idleTimeout-plus.js | 11 +++++++++-- 1 file changed, 9 insertions(+), 2 deletions(-) diff --git a/src/jquery-idleTimeout-plus.js b/src/jquery-idleTimeout-plus.js index b04c1b0..9e4e502 100644 --- a/src/jquery-idleTimeout-plus.js +++ b/src/jquery-idleTimeout-plus.js @@ -67,7 +67,9 @@ keepAliveUrl: window.location.href, // set URL to ping - does not apply if keepAliveInterval: false keepAliveAjaxType: 'GET', keepAliveAjaxData: '', - + keepAliveResponse: 'OK', // add ability to check keep alive's response. if user was logged out by other means, or something went wrong, redirect to keepAliveBadUrl - Set to false to disable KeepAliveBadUrl redirection + keepAliveBadUrl: window.location.href, // set URL to redirect to if keepAliveResponse wasnt what was expected and if keepAliveResponse isn't set to false + // Lock Screen settings lockEnabled: false, // Set to true to enable lock screen before redirecting lockTimeLimit: 7200, // 2 hrs @@ -421,7 +423,12 @@ $.ajax({ type: config.keepAliveAjaxType, url: config.keepAliveUrl, - data: config.keepAliveAjaxData + data: config.keepAliveAjaxData, + success: function(response){ + if($.trim(response) !== config.keepAliveResponse && config.keepAliveResponse !== false){ + window.location.replace(config.keepAliveBadUrl); + } + } }); }, config.keepAliveInterval); } From 7ea199a0c5e8a1ededef0e5bd7116bba9ef4960c Mon Sep 17 00:00:00 2001 From: Jason Abraham Date: Tue, 20 Mar 2018 13:08:55 -0600 Subject: [PATCH 2/2] Update jquery-idleTimeout-plus.js Reversed test on keepAliveResponse to check for false first Set default to false for keepAliveResponse --- src/jquery-idleTimeout-plus.js | 6 +++--- 1 file changed, 3 insertions(+), 3 deletions(-) diff --git a/src/jquery-idleTimeout-plus.js b/src/jquery-idleTimeout-plus.js index 9e4e502..c413c23 100644 --- a/src/jquery-idleTimeout-plus.js +++ b/src/jquery-idleTimeout-plus.js @@ -67,8 +67,8 @@ keepAliveUrl: window.location.href, // set URL to ping - does not apply if keepAliveInterval: false keepAliveAjaxType: 'GET', keepAliveAjaxData: '', - keepAliveResponse: 'OK', // add ability to check keep alive's response. if user was logged out by other means, or something went wrong, redirect to keepAliveBadUrl - Set to false to disable KeepAliveBadUrl redirection - keepAliveBadUrl: window.location.href, // set URL to redirect to if keepAliveResponse wasnt what was expected and if keepAliveResponse isn't set to false + keepAliveResponse: false, // add ability to check keep alive's response. if user was logged out by other means, or something went wrong, redirect to keepAliveBadUrl - Set to false to disable KeepAliveBadUrl redirection + keepAliveBadUrl: window.location.href, // set URL to redirect to if keepAliveResponse wasn't what was expected and if keepAliveResponse isn't set to false // Lock Screen settings lockEnabled: false, // Set to true to enable lock screen before redirecting @@ -425,7 +425,7 @@ url: config.keepAliveUrl, data: config.keepAliveAjaxData, success: function(response){ - if($.trim(response) !== config.keepAliveResponse && config.keepAliveResponse !== false){ + if(config.keepAliveResponse !== false && $.trim(response) !== config.keepAliveResponse){ window.location.replace(config.keepAliveBadUrl); } }