mirror of
https://github.com/pierre42100/ComunicWeb
synced 2024-11-22 20:19:21 +00:00
Improve bad token handling
This commit is contained in:
parent
9dfe0e39eb
commit
7c3946f376
@ -3,7 +3,7 @@
|
|||||||
*
|
*
|
||||||
* @author Pierre HUBERT
|
* @author Pierre HUBERT
|
||||||
*/
|
*/
|
||||||
ComunicWeb.common.api = {
|
const APIClient = {
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* Make an asynchronous request over the API
|
* Make an asynchronous request over the API
|
||||||
@ -151,14 +151,7 @@ ComunicWeb.common.api = {
|
|||||||
if(apiXHR.readyState == 4){
|
if(apiXHR.readyState == 4){
|
||||||
|
|
||||||
//Check if response code is 0
|
//Check if response code is 0
|
||||||
if(apiXHR.status == 0){
|
ComunicWeb.common.network.setStatus(apiXHR.status != 0);
|
||||||
//An error occured
|
|
||||||
ComunicWeb.common.network.setStatus(false);
|
|
||||||
}
|
|
||||||
else{
|
|
||||||
//It is a success
|
|
||||||
ComunicWeb.common.network.setStatus(true);
|
|
||||||
}
|
|
||||||
|
|
||||||
//Check if response is empty
|
//Check if response is empty
|
||||||
if(apiXHR.responseText.length == ""){
|
if(apiXHR.responseText.length == ""){
|
||||||
@ -199,6 +192,12 @@ ComunicWeb.common.api = {
|
|||||||
if(result.error){
|
if(result.error){
|
||||||
//Log error
|
//Log error
|
||||||
ComunicWeb.debug.logMessage("Got an error in a XHR request! \n Request URL: "+requestURL+" \n Response : "+apiXHR.responseText);
|
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
|
//We can do the next step
|
||||||
@ -207,3 +206,5 @@ ComunicWeb.common.api = {
|
|||||||
}
|
}
|
||||||
},
|
},
|
||||||
}
|
}
|
||||||
|
|
||||||
|
ComunicWeb.common.api = APIClient;
|
@ -14,7 +14,7 @@
|
|||||||
* @return {Promise}
|
* @return {Promise}
|
||||||
*/
|
*/
|
||||||
function api(uri, args, withLogin){
|
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
|
* @author Pierre HUBERT
|
||||||
*/
|
*/
|
||||||
|
|
||||||
ComunicWeb.common.system = {
|
const System = {
|
||||||
/**
|
/**
|
||||||
* Initializate the application
|
* Initializate the application
|
||||||
*
|
*
|
||||||
@ -94,7 +94,7 @@ ComunicWeb.common.system = {
|
|||||||
ComunicWeb.common.page.showWaitSplashScreen("Restarting...");
|
ComunicWeb.common.page.showWaitSplashScreen("Restarting...");
|
||||||
|
|
||||||
//Reload the page
|
//Reload the page
|
||||||
location.href = document.location;
|
location.href = document.location.href.split("#")[0];
|
||||||
},
|
},
|
||||||
|
|
||||||
/**
|
/**
|
||||||
@ -121,3 +121,5 @@ ComunicWeb.common.system = {
|
|||||||
return true;
|
return true;
|
||||||
},
|
},
|
||||||
};
|
};
|
||||||
|
|
||||||
|
ComunicWeb.common.system = System;
|
@ -60,19 +60,7 @@ const UserLogin = {
|
|||||||
});
|
});
|
||||||
|
|
||||||
} catch(e) {
|
} catch(e) {
|
||||||
|
console.error(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();
|
|
||||||
}
|
|
||||||
|
|
||||||
}
|
}
|
||||||
},
|
},
|
||||||
|
|
||||||
|
Loading…
Reference in New Issue
Block a user