2011-05-20 01:39:44 +02:00
|
|
|
/**
|
2012-05-23 07:15:17 +02:00
|
|
|
* File: LeftAndMain.Ping.js
|
2011-05-20 01:39:44 +02:00
|
|
|
*/
|
|
|
|
(function($) {
|
2012-05-23 07:15:17 +02:00
|
|
|
$.entwine('ss.ping', function($){
|
2011-05-20 01:39:44 +02:00
|
|
|
|
2012-05-23 07:15:17 +02:00
|
|
|
$('.cms-container').entwine(/** @lends ss.Form_EditForm */{
|
2011-05-20 01:39:44 +02:00
|
|
|
/**
|
|
|
|
* Variable: PingIntervalSeconds
|
|
|
|
* (Number) Interval in which /Security/ping will be checked for a valid login session.
|
|
|
|
*/
|
|
|
|
PingIntervalSeconds: 5*60,
|
|
|
|
|
2012-06-12 12:48:08 +02:00
|
|
|
onadd: function() {
|
2012-05-23 07:15:17 +02:00
|
|
|
this._setupPinging();
|
|
|
|
this._super();
|
|
|
|
},
|
|
|
|
|
2011-05-20 01:39:44 +02:00
|
|
|
/**
|
|
|
|
* Function: _setupPinging
|
2012-05-23 07:15:17 +02:00
|
|
|
*
|
2011-05-20 01:39:44 +02:00
|
|
|
* This function is called by prototype when it receives notification that the user was logged out.
|
|
|
|
* It uses /Security/ping for this purpose, which should return '1' if a valid user session exists.
|
|
|
|
* It redirects back to the login form if the URL is either unreachable, or returns '0'.
|
|
|
|
*/
|
|
|
|
_setupPinging: function() {
|
|
|
|
var onSessionLost = function(xmlhttp, status) {
|
|
|
|
if(xmlhttp.status > 400 || xmlhttp.responseText == 0) {
|
|
|
|
// TODO will pile up additional alerts when left unattended
|
|
|
|
if(window.open('Security/login')) {
|
2012-05-23 07:15:17 +02:00
|
|
|
alert('Please log in and then try again');
|
2011-05-20 01:39:44 +02:00
|
|
|
} else {
|
2012-05-23 07:15:17 +02:00
|
|
|
alert('Please enable pop-ups for this site');
|
2011-05-20 01:39:44 +02:00
|
|
|
}
|
|
|
|
}
|
|
|
|
};
|
|
|
|
|
|
|
|
// setup pinging for login expiry
|
|
|
|
setInterval(function() {
|
2012-05-23 07:15:17 +02:00
|
|
|
$.ajax({
|
|
|
|
url: 'admin/security/ping',
|
2011-05-20 01:39:44 +02:00
|
|
|
global: false,
|
|
|
|
complete: onSessionLost
|
|
|
|
});
|
|
|
|
}, this.getPingIntervalSeconds() * 1000);
|
|
|
|
}
|
|
|
|
});
|
|
|
|
});
|
2012-05-14 01:43:36 +02:00
|
|
|
}(jQuery));
|