token-validator: use cookies instead of localStorage to store auth token

This commit is contained in:
nemunaire 2020-03-01 18:15:19 +01:00
parent 72a4015288
commit a4a7b48a4f
6 changed files with 98 additions and 92 deletions

View file

@ -35,18 +35,9 @@ angular.module("AdLinApp")
angular.module("AdLinApp")
.run(function($rootScope, $interval, $http) {
$rootScope.checkLoginState = function() {
if (sessionStorage.token === undefined) {
$rootScope.isLogged = false;
return;
}
var token = sessionStorage.token;
$http({
method: 'GET',
url: "/api/auth",
headers: {
'Authorization': "Bearer " + token
}
}).then(function(response) {
$rootScope.isLogged = response.data;
$rootScope.student = response.data;
@ -58,9 +49,13 @@ angular.module("AdLinApp")
$interval($rootScope.checkLoginState, 20000);
$rootScope.disconnectCurrentUser = function() {
sessionStorage.token = undefined;
delete sessionStorage.token;
$rootScope.isLogged = false;
$http({
method: 'POST',
url: "/api/auth/logout"
}).then(function(response) {
$rootScope.isLogged = false;
$rootScope.student = null;
});
}
})
@ -88,7 +83,6 @@ angular.module("AdLinApp")
url: "/api/auth",
data: $scope.auth
}).then(function(response) {
sessionStorage.token = response.data.id_session
$scope.pleaseWait = false;
$rootScope.checkLoginState();
$location.url("/");
@ -105,9 +99,6 @@ angular.module("AdLinApp")
$http({
method: 'GET',
url: "/api/wginfo",
headers: {
'Authorization': "Bearer " + sessionStorage.token
}
}).then(function(response) {
$scope.wginfo = response.data;
});
@ -118,9 +109,6 @@ angular.module("AdLinApp")
$http({
method: 'GET',
url: "/api/wg/",
headers: {
'Authorization': "Bearer " + sessionStorage.token
}
}).then(function(response) {
$scope.tunnels = response.data;
}, function(response) {
@ -136,9 +124,6 @@ angular.module("AdLinApp")
$http({
method: 'POST',
url: "/api/wg/",
headers: {
'Authorization': "Bearer " + sessionStorage.token
},
data: {}
}).then(function(response) {
$scope.updateTunnelsList();
@ -154,9 +139,6 @@ angular.module("AdLinApp")
$http({
method: 'DELETE',
url: "/api/wg/" + tunnel.TokenText,
headers: {
'Authorization': "Bearer " + sessionStorage.token
},
data: {}
}).then(function(response) {
$scope.updateTunnelsList();
@ -184,18 +166,12 @@ angular.module("AdLinApp")
$http({
method: 'GET',
url: "/api/adomains/",
headers: {
'Authorization': "Bearer " + sessionStorage.token
},
}).then(function(response) {
$scope.adomains = [];
response.data.forEach(function(domain) {
$http({
method: 'GET',
url: "/api/adomains/" + domain,
headers: {
'Authorization': "Bearer " + sessionStorage.token
},
}).then(function(response) {
response.data.forEach(function(rr) {
$scope.adomains.push(rr);
@ -213,9 +189,6 @@ angular.module("AdLinApp")
$http({
method: 'GET',
url: "/api/ddomains/",
headers: {
'Authorization': "Bearer " + sessionStorage.token
},
}).then(function(response) {
response.data.forEach(function(domain) {
$scope.ddomains = response.data;
@ -231,9 +204,6 @@ angular.module("AdLinApp")
$http({
method: 'POST',
url: "/api/adomains/",
headers: {
'Authorization': "Bearer " + sessionStorage.token
},
}).then(function(response) {
$scope.updateAssociationD();
$scope.pleaseWaitNewAssociation = false;
@ -308,9 +278,6 @@ angular.module("AdLinApp")
$http({
method: (nsrr.valuesfrom !== undefined)?'PATCH':'POST',
url: "/api/ddomains/" + nsrr.domain + "/" + nsrr.rr,
headers: {
'Authorization': "Bearer " + sessionStorage.token
},
data: nsrr,
}).then(function(response) {
$('#NSModal').modal('hide');
@ -325,9 +292,6 @@ angular.module("AdLinApp")
$http({
method: 'DELETE',
url: "/api/ddomains/" + domain + "/" + rr.rr,
headers: {
'Authorization': "Bearer " + sessionStorage.token
},
data: rr,
}).then(function(response) {
callOnUpdateEvt();
@ -344,9 +308,6 @@ angular.module("AdLinApp")
$http({
method: 'GET',
url: "/api/ddomains/" + $scope.domain + "/NS",
headers: {
'Authorization': "Bearer " + sessionStorage.token
},
}).then(function(response) {
$scope.domainNS = response.data;
});
@ -360,9 +321,6 @@ angular.module("AdLinApp")
$http({
method: 'GET',
url: "/api/ddomains/" + $scope.domain + "/GLUE",
headers: {
'Authorization': "Bearer " + sessionStorage.token
},
}).then(function(response) {
$scope.domainGLUE = response.data;
});
@ -376,9 +334,6 @@ angular.module("AdLinApp")
$http({
method: 'GET',
url: "/api/ddomains/" + $scope.domain + "/DS",
headers: {
'Authorization': "Bearer " + sessionStorage.token
},
}).then(function(response) {
$scope.domainDS = response.data;
});