diff --git a/awx/ui/client/src/app.js b/awx/ui/client/src/app.js index b07df48373..9e56c7af35 100644 --- a/awx/ui/client/src/app.js +++ b/awx/ui/client/src/app.js @@ -947,7 +947,8 @@ var tower = angular.module('Tower', [ control_socket.init(); control_socket.on("limit_reached", function(data) { $log.debug(data.reason); - Timer.expireSession('session_limit'); + $rootScope.sessionTimer.expireSession('session_limit'); + $location.url('/login'); }); } openSocket(); @@ -1023,9 +1024,11 @@ var tower = angular.module('Tower', [ $rootScope.user_is_superuser = Authorization.getUserInfo('is_superuser'); // when the user refreshes we want to open the socket, except if the user is on the login page, which should happen after the user logs in (see the AuthService module for that call to OpenSocket) if(!_.contains($location.$$url, '/login')){ - $rootScope.sessionTimer = Timer.init(); - $rootScope.$emit('OpenSocket'); - pendoService.issuePendoIdentity(); + Timer.init().then(function(timer){ + $rootScope.sessionTimer = timer; + $rootScope.$emit('OpenSocket'); + pendoService.issuePendoIdentity(); + }); } } diff --git a/awx/ui/client/src/login/authenticationServices/authentication.service.js b/awx/ui/client/src/login/authenticationServices/authentication.service.js index 5ab9aced88..511cb4ab83 100644 --- a/awx/ui/client/src/login/authenticationServices/authentication.service.js +++ b/awx/ui/client/src/login/authenticationServices/authentication.service.js @@ -82,7 +82,7 @@ export default x = Store('sessionTime'); x[$rootScope.current_user.id].loggedIn = false; Store('sessionTime', x); - + $rootScope.lastUser = $cookieStore.get('current_user').id; $cookieStore.remove('token_expires'); $cookieStore.remove('current_user'); @@ -98,7 +98,7 @@ export default $rootScope.token_expires = null; $rootScope.login_username = null; $rootScope.login_password = null; - $rootScope.sessionTimer.expireSession(); + $rootScope.sessionTimer.clearTimers(); }, getLicense: function () { @@ -153,7 +153,6 @@ export default // store the response values in $rootScope so we can get to them later $rootScope.current_user = response.results[0]; $cookieStore.put('current_user', response.results[0]); //keep in session cookie in the event of browser refresh - $rootScope.$emit('OpenSocket'); }, restoreUserInfo: function () { diff --git a/awx/ui/client/src/login/authenticationServices/timer.factory.js b/awx/ui/client/src/login/authenticationServices/timer.factory.js index 7e39c93502..04478309e3 100644 --- a/awx/ui/client/src/login/authenticationServices/timer.factory.js +++ b/awx/ui/client/src/login/authenticationServices/timer.factory.js @@ -23,9 +23,9 @@ */ export default ['$rootScope', '$cookieStore', 'transitionTo', 'CreateDialog', 'Authorization', - 'Store', '$interval', + 'Store', '$interval', '$location', '$q', function ($rootScope, $cookieStore, transitionTo, CreateDialog, Authorization, - Store, $interval) { + Store, $interval, $location, $q) { return { sessionTime: null, @@ -82,7 +82,6 @@ export default this.sessionTime = 0; this.clearTimers(); $cookieStore.put('sessionExpired', true); - transitionTo('signOut'); }, moveForward: function () { @@ -158,9 +157,12 @@ export default $('#idle-modal').dialog('close'); } that.expireSession('idle'); + $location.url('/login'); } if(Store('sessionTime')[$rootScope.current_user.id].loggedIn === false){ that.expireSession(); + $location.url('/login'); + } }, 1000); @@ -169,11 +171,15 @@ export default clearTimers: function(){ $interval.cancel($rootScope.expireTimer); + delete $rootScope.expireTimer; }, init: function () { + var deferred = $q.defer(); this.moveForward(); - return this; + deferred.resolve(this); + return deferred.promise; + } }; } diff --git a/awx/ui/client/src/login/loginModal/loginModal.controller.js b/awx/ui/client/src/login/loginModal/loginModal.controller.js index 48cf162f88..6b2bbb9f03 100644 --- a/awx/ui/client/src/login/loginModal/loginModal.controller.js +++ b/awx/ui/client/src/login/loginModal/loginModal.controller.js @@ -165,9 +165,12 @@ export default ['$log', '$cookieStore', '$compile', '$window', '$rootScope', '$l Authorization.getUser() .success(function (data) { Authorization.setUserInfo(data); - $rootScope.sessionTimer = Timer.init(); - $rootScope.user_is_superuser = data.results[0].is_superuser; - scope.$emit('AuthorizationGetLicense'); + Timer.init().then(function(timer){ + $rootScope.sessionTimer = timer; + $rootScope.$emit('OpenSocket'); + $rootScope.user_is_superuser = data.results[0].is_superuser; + scope.$emit('AuthorizationGetLicense'); + }); }) .error(function (data, status) { Authorization.logout(); diff --git a/awx/ui/client/src/rest/interceptors.service.js b/awx/ui/client/src/rest/interceptors.service.js index 5ef77a40f4..def62c1560 100644 --- a/awx/ui/client/src/rest/interceptors.service.js +++ b/awx/ui/client/src/rest/interceptors.service.js @@ -11,8 +11,8 @@ *************************************************/ export default - [ '$rootScope', '$q', - function ($rootScope, $q) { + [ '$rootScope', '$q', '$injector', + function ($rootScope, $q, $injector) { return { response: function(config) { if(config.headers('auth-token-timeout') !== null){ @@ -23,6 +23,8 @@ responseError: function(rejection){ if( rejection.data && !_.isEmpty(rejection.data.detail) && rejection.data.detail === "Maximum per-user sessions reached"){ $rootScope.sessionTimer.expireSession('session_limit'); + var location = $injector.get('$location'); + location.url('/login'); return $q.reject(rejection); } return $q.reject(rejection);