mirror of
https://github.com/pierre42100/ComunicWeb
synced 2024-12-24 18:08:50 +00:00
Improve bad token handling
This commit is contained in:
parent
9dfe0e39eb
commit
7c3946f376
@ -3,7 +3,7 @@
|
||||
*
|
||||
* @author Pierre HUBERT
|
||||
*/
|
||||
ComunicWeb.common.api = {
|
||||
const APIClient = {
|
||||
|
||||
/**
|
||||
* Make an asynchronous request over the API
|
||||
@ -151,14 +151,7 @@ ComunicWeb.common.api = {
|
||||
if(apiXHR.readyState == 4){
|
||||
|
||||
//Check if response code is 0
|
||||
if(apiXHR.status == 0){
|
||||
//An error occured
|
||||
ComunicWeb.common.network.setStatus(false);
|
||||
}
|
||||
else{
|
||||
//It is a success
|
||||
ComunicWeb.common.network.setStatus(true);
|
||||
}
|
||||
ComunicWeb.common.network.setStatus(apiXHR.status != 0);
|
||||
|
||||
//Check if response is empty
|
||||
if(apiXHR.responseText.length == ""){
|
||||
@ -199,6 +192,12 @@ ComunicWeb.common.api = {
|
||||
if(result.error){
|
||||
//Log error
|
||||
ComunicWeb.debug.logMessage("Got an error in a XHR request! \n Request URL: "+requestURL+" \n Response : "+apiXHR.responseText);
|
||||
|
||||
if (result.error.code == 412) {
|
||||
UserLogin.__userLogin = false;
|
||||
ComunicWeb.user.loginTokens.deleteLoginTokens();
|
||||
System.restart();
|
||||
}
|
||||
}
|
||||
|
||||
//We can do the next step
|
||||
@ -206,4 +205,6 @@ ComunicWeb.common.api = {
|
||||
nextAction(result);
|
||||
}
|
||||
},
|
||||
}
|
||||
}
|
||||
|
||||
ComunicWeb.common.api = APIClient;
|
@ -14,7 +14,7 @@
|
||||
* @return {Promise}
|
||||
*/
|
||||
function api(uri, args, withLogin){
|
||||
return ComunicWeb.common.api.exec(uri, args, withLogin);
|
||||
return APIClient.exec(uri, args, withLogin);
|
||||
}
|
||||
|
||||
/**
|
||||
|
@ -4,7 +4,7 @@
|
||||
* @author Pierre HUBERT
|
||||
*/
|
||||
|
||||
ComunicWeb.common.system = {
|
||||
const System = {
|
||||
/**
|
||||
* Initializate the application
|
||||
*
|
||||
@ -94,7 +94,7 @@ ComunicWeb.common.system = {
|
||||
ComunicWeb.common.page.showWaitSplashScreen("Restarting...");
|
||||
|
||||
//Reload the page
|
||||
location.href = document.location;
|
||||
location.href = document.location.href.split("#")[0];
|
||||
},
|
||||
|
||||
/**
|
||||
@ -120,4 +120,6 @@ ComunicWeb.common.system = {
|
||||
//Success
|
||||
return true;
|
||||
},
|
||||
};
|
||||
};
|
||||
|
||||
ComunicWeb.common.system = System;
|
@ -60,19 +60,7 @@ const UserLogin = {
|
||||
});
|
||||
|
||||
} catch(e) {
|
||||
|
||||
//Set user ID to 0 (security purpose)
|
||||
ComunicWeb.user.userLogin.__userID = 0;
|
||||
|
||||
//If error is 412, make user as logged out
|
||||
if(result.error.code == 412) {
|
||||
ComunicWeb.user.userLogin.__userLogin = false;
|
||||
ComunicWeb.user.loginTokens.deleteLoginTokens();
|
||||
|
||||
//Restart the application
|
||||
ComunicWeb.common.system.restart();
|
||||
}
|
||||
|
||||
console.error(e);
|
||||
}
|
||||
},
|
||||
|
||||
|
Loading…
Reference in New Issue
Block a user