diff --git a/public_html/index.php b/public_html/index.php index 1423c47..0fde11e 100755 --- a/public_html/index.php +++ b/public_html/index.php @@ -90,6 +90,9 @@ global $auth; + // session timeout warning + $session_warn = 5; // 5 minutes before expiration + // {1} Disable cache // header('Cache-Control: no-store, no-cache, must-revalidate, max-age=0'); 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"; + + 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 5 minutes. 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(); diff --git a/public_html/js/lib/api.js b/public_html/js/lib/api.js index 0867df4..74dc443 100755 --- a/public_html/js/lib/api.js +++ b/public_html/js/lib/api.js @@ -71,7 +71,7 @@ APIClass.prototype = { // Récupération token TreeToken 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 try{ @@ -81,15 +81,21 @@ APIClass.prototype = { // On lance la handler console.log('api response', parsedResponse); - if( parsedResponse.hasOwnProperty('ModuleError') && parsedResponse.ModuleError != 0 ) - console.error('ModuleError::'+parsedResponse.ModuleError); + if( parsedResponse.hasOwnProperty('error') && parsedResponse.error != 0 ) + 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]); } /* sinon retourne obj.request = 'unreachable' */ 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 this.xhr[i].setRequestHeader('X-Requested-With', 'XMLHttpRequest'); - - this.xhr[i].send( form ); } diff --git a/public_html/js/lib/min/api.js b/public_html/js/lib/min/api.js index 6d76cdf..c622732 100755 --- a/public_html/js/lib/min/api.js +++ b/public_html/js/lib/min/api.js @@ -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;s3)for(var o=3;o-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)}}; \ No newline at end of file +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;s3)for(var o=3;o-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)}}; \ No newline at end of file diff --git a/public_html/view/admin.php b/public_html/view/admin.php index 3b0591f..7a0a6ff 100755 --- a/public_html/view/admin.php +++ b/public_html/view/admin.php @@ -22,6 +22,8 @@ + +