adding a DELETE to /authtoken when user logs out

This commit is contained in:
jaredevantabor
2017-02-02 16:58:32 -08:00
parent 02c7f87185
commit 53208c22ec
3 changed files with 67 additions and 51 deletions

View File

@@ -15,9 +15,9 @@
*/ */
export default export default
['$http', '$rootScope', '$location', '$cookieStore', 'GetBasePath', 'Store', ['$http', '$rootScope', '$location', '$cookieStore', 'GetBasePath', 'Store', '$q',
'$injector', '$injector',
function ($http, $rootScope, $location, $cookieStore, GetBasePath, Store, function ($http, $rootScope, $location, $cookieStore, GetBasePath, Store, $q,
$injector) { $injector) {
return { return {
setToken: function (token, expires) { setToken: function (token, expires) {
@@ -58,16 +58,24 @@ export default
} }
}); });
}, },
deleteToken: function () {
return $http({
method: 'DELETE',
url: GetBasePath('authtoken')
});
},
logout: function () { logout: function () {
// the following puts our primary scope up for garbage collection, which // the following puts our primary scope up for garbage collection, which
// should prevent content flash from the prior user. // should prevent content flash from the prior user.
var x, var x,
deferred = $q.defer(),
ConfigService = $injector.get('ConfigService'), ConfigService = $injector.get('ConfigService'),
SocketService = $injector.get('SocketService'), SocketService = $injector.get('SocketService'),
scope = angular.element(document.getElementById('main-view')).scope(); scope = angular.element(document.getElementById('main-view')).scope();
this.deleteToken().then(() => {
if(scope){ if(scope){
scope.$destroy(); scope.$destroy();
} }
@@ -114,6 +122,11 @@ export default
if ($rootScope.sessionTimer) { if ($rootScope.sessionTimer) {
$rootScope.sessionTimer.clearTimers(); $rootScope.sessionTimer.clearTimers();
} }
deferred.resolve();
});
return deferred.promise;
}, },
licenseTested: function () { licenseTested: function () {

View File

@@ -142,11 +142,12 @@ export default ['$log', '$cookieStore', '$compile', '$window', '$rootScope',
}); });
}) })
.error(function (data, status) { .error(function (data, status) {
Authorization.logout(); Authorization.logout().then( () => {
Wait('stop'); Wait('stop');
Alert('Error', 'Failed to access user information. GET returned status: ' + status, 'alert-danger', loginAgain); Alert('Error', 'Failed to access user information. GET returned status: ' + status, 'alert-danger', loginAgain);
}); });
}); });
});
// Call the API to get an auth token // Call the API to get an auth token
scope.systemLogin = function (username, password) { scope.systemLogin = function (username, password) {

View File

@@ -10,8 +10,10 @@ export default {
name: 'signOut', name: 'signOut',
route: '/logout', route: '/logout',
controller: ['Authorization', '$state', function(Authorization, $state) { controller: ['Authorization', '$state', function(Authorization, $state) {
Authorization.logout(); Authorization.logout().then( () =>{
$state.go('signIn'); $state.go('signIn');
});
}], }],
ncyBreadcrumb: { ncyBreadcrumb: {
skip: true skip: true