MINOR Refactored onSessionLost() javascript functionality

git-svn-id: svn://svn.silverstripe.com/silverstripe/open/modules/cms/trunk@92651 467b73ca-7a2a-4603-9d3b-597d59a354a9
This commit is contained in:
Ingo Schommer 2009-11-21 02:38:22 +00:00
parent 9980de9c1d
commit baf23e5883

View File

@ -15,7 +15,7 @@
return/** @lends ss.EditMemberProfile */ {
/**
* @type Number
* @type Number Interval in which /Security/ping will be checked for a valid login session.
*/
PingIntervalSeconds: 5*60,
@ -40,11 +40,32 @@
this._super();
},
/**
* 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(response, type, XMLHttpRequest) {
if(XMLHttpRequest.status > 400 || response == 0) {
// TODO will pile up additional alerts when left unattended
if(window.open('Security/login')) {
alert("Please log in and then try again");
} else {
alert("Please enable pop-ups for this site");
}
}
};
// setup pinging for login expiry
setInterval(function() {
jQuery.get("Security/ping");
jQuery.ajax({
url: "Security/ping",
global: false,
error: onSessionLost,
success: onSessionLost
});
}, this.PingIntervalSeconds() * 1000);
},
@ -582,19 +603,6 @@ returnFalse = function() {
return false;
}
/**
* This function is called by prototype when it receives notification that the user was logged out.
* It redirects back to the login form.
*/
function onSessionLost() {
w = window.open('Security/login');
if(w) {
alert("Please log in and then try again");
} else {
alert("Please enable pop-ups for this site");
}
}
var _CURRENT_CONTEXT_MENU = null;
/**