serverinfo.js now shows a popup when session time out + api.js reset the timeout when an API call have an error=0 + if no answer to popup in 5min logout
This commit is contained in:
parent
172f1e5935
commit
0faaee0040
|
@ -90,6 +90,9 @@
|
||||||
|
|
||||||
global $auth;
|
global $auth;
|
||||||
|
|
||||||
|
// session timeout warning
|
||||||
|
$session_warn = 5; // 5 minutes before expiration
|
||||||
|
|
||||||
// {1} Disable cache //
|
// {1} Disable cache //
|
||||||
header('Cache-Control: no-store, no-cache, must-revalidate, max-age=0');
|
header('Cache-Control: no-store, no-cache, must-revalidate, max-age=0');
|
||||||
header('Cache-Control: post-check=0, pre-check=0', false);
|
header('Cache-Control: post-check=0, pre-check=0', false);
|
||||||
|
@ -115,8 +118,44 @@
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
|
// session timeout
|
||||||
|
echo "\n\t},\n";
|
||||||
|
echo "\tsession: {\n";
|
||||||
|
echo "\t\ttimeout: '".( (ini_get('session.gc_maxlifetime')+$session_warn*60) * 1000 )."'\n";
|
||||||
echo "\n\t}\n";
|
echo "\n\t}\n";
|
||||||
echo "};\n";
|
|
||||||
|
echo "};\n\n";
|
||||||
|
|
||||||
|
// {3} Function that reloads or logout the user
|
||||||
|
echo "var KEEP_SESSION = function(keep){\n";
|
||||||
|
echo "\tif( keep )\n";
|
||||||
|
echo "\t\tdocument.location = '';\n";
|
||||||
|
echo "\telse\n";
|
||||||
|
echo "\t\tdocument.location = '/logout';\n";
|
||||||
|
echo "};\n\n";
|
||||||
|
|
||||||
|
// {4} Function called at session timeout
|
||||||
|
echo "var SESSION_TIMEOUT_FUNC = function(){\n";
|
||||||
|
|
||||||
|
// {4.1} setup POPUP window
|
||||||
|
echo "\tvar popup = new Popup();\n";
|
||||||
|
echo "\tvar popup_content = {\n";
|
||||||
|
echo "\t\ttitle: 'Expiration de connexion',\n";
|
||||||
|
echo "\t\tcontent: 'Vous n\'avez rien fait depuis un moment. Vous serez déconnecté dans <b>5 minutes</b>. Vous pouvez recharger la page pour garder votre connexion.',\n";
|
||||||
|
echo "\t\ttype: 'search',\n";
|
||||||
|
echo "\t\taction: 'Recharger la page'\n";
|
||||||
|
echo "\t}\n";
|
||||||
|
|
||||||
|
// {4.2} Show popup dialog -> on reload: reload page ; on cancel: logout
|
||||||
|
echo "\tpopup.ask(popup_content, KEEP_SESSION);\n";
|
||||||
|
|
||||||
|
// {4.3} Logout by default 5min if no popup response
|
||||||
|
echo "\tsetTimeout(function(){ KEEP_SESSION(false); }, $session_warn*60*1000);\n";
|
||||||
|
|
||||||
|
echo "};\n\n";
|
||||||
|
|
||||||
|
// {5} Set the timeout
|
||||||
|
echo "var SESSION_TIMEOUT = setTimeout(SESSION_TIMEOUT_FUNC, SERVER.session.timeout);\n";
|
||||||
|
|
||||||
die();
|
die();
|
||||||
|
|
||||||
|
|
|
@ -71,7 +71,7 @@ APIClass.prototype = {
|
||||||
// Récupération token TreeToken
|
// Récupération token TreeToken
|
||||||
window._tree_token_ = ptrAPI.xhr[i].getResponseHeader('X-Tree-Token');
|
window._tree_token_ = ptrAPI.xhr[i].getResponseHeader('X-Tree-Token');
|
||||||
|
|
||||||
var parsedResponse = {ModuleError:-1, ErrorDescription:'Erreur au niveau de api.js'};
|
var parsedResponse = {error:-1, ErrorDescription:'Erreur au niveau de api.js'};
|
||||||
|
|
||||||
// On essaie de parser le json
|
// On essaie de parser le json
|
||||||
try{
|
try{
|
||||||
|
@ -81,15 +81,21 @@ APIClass.prototype = {
|
||||||
// On lance la handler
|
// On lance la handler
|
||||||
console.log('api response', parsedResponse);
|
console.log('api response', parsedResponse);
|
||||||
|
|
||||||
if( parsedResponse.hasOwnProperty('ModuleError') && parsedResponse.ModuleError != 0 )
|
if( parsedResponse.hasOwnProperty('error') && parsedResponse.error != 0 )
|
||||||
console.error('ModuleError::'+parsedResponse.ModuleError);
|
console.error('ModuleError::'+parsedResponse.error);
|
||||||
|
|
||||||
|
// If success -> reload session_timeout
|
||||||
|
if( parsedResponse.hasOwnProperty('error') && parsedResponse.error == 0 ){
|
||||||
|
clearTimeout(SESSION_TIMEOUT);
|
||||||
|
SESSION_TIMEOUT = setTimeout(SESSION_TIMEOUT_FUNC, SERVER.session.timeout);
|
||||||
|
}
|
||||||
|
|
||||||
pHandler(parsedResponse, ptrAPI.optionalParams[i]);
|
pHandler(parsedResponse, ptrAPI.optionalParams[i]);
|
||||||
|
|
||||||
}
|
}
|
||||||
/* sinon retourne obj.request = 'unreachable' */
|
/* sinon retourne obj.request = 'unreachable' */
|
||||||
else
|
else
|
||||||
pHandler({ModuleError:-2, ModuleDescription:'Erreur au niveau d\'AJAX.'});
|
pHandler({error:-2, ErrorDescription:'Erreur au niveau d\'AJAX.'});
|
||||||
|
|
||||||
}
|
}
|
||||||
};
|
};
|
||||||
|
@ -124,8 +130,6 @@ APIClass.prototype = {
|
||||||
// Header pour dire que c'est AJAX
|
// Header pour dire que c'est AJAX
|
||||||
this.xhr[i].setRequestHeader('X-Requested-With', 'XMLHttpRequest');
|
this.xhr[i].setRequestHeader('X-Requested-With', 'XMLHttpRequest');
|
||||||
|
|
||||||
|
|
||||||
|
|
||||||
this.xhr[i].send( form );
|
this.xhr[i].send( form );
|
||||||
|
|
||||||
}
|
}
|
||||||
|
|
|
@ -1 +1 @@
|
||||||
function APIClass(e){this.target=e}APIClass.prototype={xhr:[],buffer:null,optionalParams:[],send:function(e,r,t){e.hasOwnProperty("path")||r({ModuleError:4});for(var s=0;s<this.xhr.length;s++)4==this.xhr[s].readyState&&this.xhr.splice(s,1);if(this.xhr.push(null),s=this.xhr.length-1,this.optionalParams[s]=[],arguments.length>3)for(var o=3;o<arguments.length;o++)this.optionalParams[s].push(arguments[o]);window.XMLHttpRequest?this.xhr[s]=new XMLHttpRequest:this.xhr[s]=new ActiveXObject("Microsoft.XMLHttpRequest");var n=this;this.xhr[s].onreadystatechange=function(){if(4==n.xhr[s].readyState)if(n.buffer=n.xhr[s].responseText,console.log("api request",e),[0,200,417].indexOf(n.xhr[s].status)>-1){window._tree_token_=n.xhr[s].getResponseHeader("X-Tree-Token");var t={ModuleError:-1,ErrorDescription:"Erreur au niveau de api.js"};try{t=JSON.parse(n.xhr[s].responseText)}catch(e){}console.log("api response",t),t.hasOwnProperty("ModuleError")&&0!=t.ModuleError&&console.error("ModuleError::"+t.ModuleError),r(t,n.optionalParams[s])}else r({ModuleError:-2,ModuleDescription:"Erreur au niveau d'AJAX."})};var a=new FormData;for(var i in e)"path"==i?a.append(i,e[i]):e[i]instanceof File?a.append(i,e[i]):a.append(i,JSON.stringify(e[i]));this.xhr[s].open("POST",this.target,!0),null!=t&&this.xhr[s].setRequestHeader("Authorization","Digest "+t),null==window._tree_token_?this.xhr[s].setRequestHeader("X-Tree-Token",JSON.parse('{"'+document.cookie.replace(/=/g,'":"').replace(/; /g,'","')+'"}')._PUBLIC_):this.xhr[s].setRequestHeader("X-Tree-Token",window._tree_token_),this.xhr[s].setRequestHeader("X-Requested-With","XMLHttpRequest"),this.xhr[s].send(a)}};
|
function APIClass(e){this.target=e}APIClass.prototype={xhr:[],buffer:null,optionalParams:[],send:function(e,r,t){e.hasOwnProperty("path")||r({ModuleError:4});for(var s=0;s<this.xhr.length;s++)4==this.xhr[s].readyState&&this.xhr.splice(s,1);if(this.xhr.push(null),s=this.xhr.length-1,this.optionalParams[s]=[],arguments.length>3)for(var o=3;o<arguments.length;o++)this.optionalParams[s].push(arguments[o]);window.XMLHttpRequest?this.xhr[s]=new XMLHttpRequest:this.xhr[s]=new ActiveXObject("Microsoft.XMLHttpRequest");var n=this;this.xhr[s].onreadystatechange=function(){if(4==n.xhr[s].readyState)if(n.buffer=n.xhr[s].responseText,console.log("api request",e),[0,200,417].indexOf(n.xhr[s].status)>-1){window._tree_token_=n.xhr[s].getResponseHeader("X-Tree-Token");var t={error:-1,ErrorDescription:"Erreur au niveau de api.js"};try{t=JSON.parse(n.xhr[s].responseText)}catch(e){}console.log("api response",t),t.hasOwnProperty("error")&&0!=t.error&&console.error("ModuleError::"+t.error),t.hasOwnProperty("error")&&0==t.error&&(clearTimeout(SESSION_TIMEOUT),SESSION_TIMEOUT=setTimeout(SESSION_TIMEOUT_FUNC,SERVER.session.timeout)),r(t,n.optionalParams[s])}else r({error:-2,ErrorDescription:"Erreur au niveau d'AJAX."})};var a=new FormData;for(var i in e)"path"==i?a.append(i,e[i]):e[i]instanceof File?a.append(i,e[i]):a.append(i,JSON.stringify(e[i]));this.xhr[s].open("POST",this.target,!0),null!=t&&this.xhr[s].setRequestHeader("Authorization","Digest "+t),null==window._tree_token_?this.xhr[s].setRequestHeader("X-Tree-Token",JSON.parse('{"'+document.cookie.replace(/=/g,'":"').replace(/; /g,'","')+'"}')._PUBLIC_):this.xhr[s].setRequestHeader("X-Tree-Token",window._tree_token_),this.xhr[s].setRequestHeader("X-Requested-With","XMLHttpRequest"),this.xhr[s].send(a)}};
|
|
@ -22,6 +22,8 @@
|
||||||
<script type='text/javascript' src='/js/lib/min/api.js' ></script> <!-- Gestion des transactions avec le serveur -->
|
<script type='text/javascript' src='/js/lib/min/api.js' ></script> <!-- Gestion des transactions avec le serveur -->
|
||||||
<script type='text/javascript' src='/js/lib/page-manager.js' ></script> <!-- Gestion des transactions avec le serveur -->
|
<script type='text/javascript' src='/js/lib/page-manager.js' ></script> <!-- Gestion des transactions avec le serveur -->
|
||||||
|
|
||||||
|
<script type='text/javascript' src='/serverinfo.js' ></script> <!-- Gestion dynamique des info server -->
|
||||||
|
|
||||||
</head>
|
</head>
|
||||||
<style type='text/css'>
|
<style type='text/css'>
|
||||||
body{
|
body{
|
||||||
|
|
Loading…
Reference in New Issue