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,62 +58,75 @@ 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();
if(scope){ this.deleteToken().then(() => {
scope.$destroy(); if(scope){
} scope.$destroy();
}
if($cookieStore.get('lastPath')==='/portal'){ if($cookieStore.get('lastPath')==='/portal'){
$cookieStore.put( 'lastPath', '/portal'); $cookieStore.put( 'lastPath', '/portal');
$rootScope.lastPath = '/portal'; $rootScope.lastPath = '/portal';
} }
else if ($cookieStore.get('lastPath') !== '/home' || $cookieStore.get('lastPath') !== '/' || $cookieStore.get('lastPath') !== '/login' || $cookieStore.get('lastPath') !== '/logout'){ else if ($cookieStore.get('lastPath') !== '/home' || $cookieStore.get('lastPath') !== '/' || $cookieStore.get('lastPath') !== '/login' || $cookieStore.get('lastPath') !== '/logout'){
// do nothing // do nothing
$rootScope.lastPath = $cookieStore.get('lastPath'); $rootScope.lastPath = $cookieStore.get('lastPath');
} }
else { else {
// your last path was home // your last path was home
$cookieStore.remove('lastPath'); $cookieStore.remove('lastPath');
$rootScope.lastPath = '/home'; $rootScope.lastPath = '/home';
} }
x = Store('sessionTime'); x = Store('sessionTime');
if ($rootScope.current_user) { if ($rootScope.current_user) {
x[$rootScope.current_user.id].loggedIn = false; x[$rootScope.current_user.id].loggedIn = false;
} }
Store('sessionTime', x); Store('sessionTime', x);
if ($cookieStore.get('current_user')) {
$rootScope.lastUser = $cookieStore.get('current_user').id;
}
ConfigService.delete();
SocketService.disconnect();
$cookieStore.remove('token_expires');
$cookieStore.remove('current_user');
$cookieStore.remove('token');
$cookieStore.put('userLoggedIn', false);
$cookieStore.put('sessionExpired', false);
$cookieStore.put('current_user', {});
$rootScope.current_user = {};
$rootScope.license_tested = undefined;
$rootScope.userLoggedIn = false;
$rootScope.sessionExpired = false;
$rootScope.licenseMissing = true;
$rootScope.token = null;
$rootScope.token_expires = null;
$rootScope.login_username = null;
$rootScope.login_password = null;
if ($rootScope.sessionTimer) {
$rootScope.sessionTimer.clearTimers();
}
deferred.resolve();
});
return deferred.promise;
if ($cookieStore.get('current_user')) {
$rootScope.lastUser = $cookieStore.get('current_user').id;
}
ConfigService.delete();
SocketService.disconnect();
$cookieStore.remove('token_expires');
$cookieStore.remove('current_user');
$cookieStore.remove('token');
$cookieStore.put('userLoggedIn', false);
$cookieStore.put('sessionExpired', false);
$cookieStore.put('current_user', {});
$rootScope.current_user = {};
$rootScope.license_tested = undefined;
$rootScope.userLoggedIn = false;
$rootScope.sessionExpired = false;
$rootScope.licenseMissing = true;
$rootScope.token = null;
$rootScope.token_expires = null;
$rootScope.login_username = null;
$rootScope.login_password = null;
if ($rootScope.sessionTimer) {
$rootScope.sessionTimer.clearTimers();
}
}, },
licenseTested: function () { licenseTested: function () {

View File

@@ -142,9 +142,10 @@ 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);
});
}); });
}); });

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