Permalink
Browse files

MINOR Refactored onSessionLost() javascript functionality

git-svn-id: svn://svn.silverstripe.com/silverstripe/open/modules/cms/trunk@92651 467b73ca-7a2a-4603-9d3b-597d59a354a9
  • Loading branch information...
1 parent 9980de9 commit baf23e58837291f49a5758a9a4696e972bf2ab3f @chillu chillu committed Nov 21, 2009
Showing with 24 additions and 16 deletions.
  1. +24 −16 javascript/LeftAndMain.js
View
@@ -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;
/**

0 comments on commit baf23e5

Please sign in to comment.