diff --git a/awx/ui/client/src/app.js b/awx/ui/client/src/app.js index 066bd57269..b07df48373 100644 --- a/awx/ui/client/src/app.js +++ b/awx/ui/client/src/app.js @@ -1022,7 +1022,7 @@ var tower = angular.module('Tower', [ // If browser refresh, set the user_is_superuser value $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($location.$$url !== '/login'){ + if(!_.contains($location.$$url, '/login')){ $rootScope.sessionTimer = Timer.init(); $rootScope.$emit('OpenSocket'); pendoService.issuePendoIdentity(); diff --git a/awx/ui/client/src/login/authenticationServices/timer.factory.js b/awx/ui/client/src/login/authenticationServices/timer.factory.js index a183fc9be4..54ebf99006 100644 --- a/awx/ui/client/src/login/authenticationServices/timer.factory.js +++ b/awx/ui/client/src/login/authenticationServices/timer.factory.js @@ -23,33 +23,29 @@ */ export default ['$rootScope', '$cookieStore', 'transitionTo', 'CreateDialog', 'Authorization', - 'Store', + 'Store', '$interval', function ($rootScope, $cookieStore, transitionTo, CreateDialog, Authorization, - Store) { + Store, $interval) { return { sessionTime: null, timeout: null, getSessionTime: function () { - // var sessionTime; - // if(this.sessionTime){ - // return this.sessionTime; - // } - // else { - // sessionTime = Store('sessionTime').time; - // return sessionTime; - // } - return (this.sessionTime) ? this.sessionTime : Store('sessionTime');//$cookieStore.get('sessionTime'); + return Store('sessionTime_'+$rootScope.current_user.id); }, - isExpired: function () { + isExpired: function (increase) { var stime = this.getSessionTime(), now = new Date().getTime(); if ((stime - now) <= 0) { //expired return true; - } else { + } + else if(increase){ + return false; + } + else{ // not expired. move timer forward. this.moveForward(); return false; @@ -62,7 +58,7 @@ export default diff = stime-now; if(diff < 61){ - return true; + return diff; } else { return false; @@ -88,75 +84,72 @@ export default var tm, t; tm = ($AnsibleConfig.session_timeout) ? $AnsibleConfig.session_timeout : 1800; t = new Date().getTime() + (tm * 1000); - this.sessionTime = t; - // $cookieStore.put('sessionTime', t); - Store('sessionTime', t); + Store('sessionTime_'+$rootScope.current_user.id, t); $rootScope.sessionExpired = false; $cookieStore.put('sessionExpired', false); - this.startTimers(); }, - startTimers: function() { - var that = this, - tm = ($AnsibleConfig.session_timeout) ? $AnsibleConfig.session_timeout : 1800, - t = tm - 60; - + startTimers: function(){ + var that = this; this.clearTimers(); - - // make a timeout that will go off in 30 mins to log them out - // unless they extend their time - $rootScope.endTimer = setTimeout(function(){ - that.expireSession('idle'); - }, tm * 1000); - - // notify the user a minute before the end of their session that - // their session is about to expire - if($rootScope.idleTimer){ - clearTimeout($rootScope.idleTimer); - } - $rootScope.idleTimer = setTimeout(function() { - if(that.isIdle() === true){ - var buttons = [{ - "label": "Continue", - "onClick": function() { - // make a rest call here to force the API to - // move the session time forward - Authorization.getUser(); - that.moveForward(); - $(this).dialog('close'); - - }, - "class": "btn btn-primary", - "id": "idle-modal-button" - }]; - - if ($rootScope.removeIdleDialogReady) { - $rootScope.removeIdleDialogReady(); + $rootScope.expireTimer = $interval(function() { + var idle = that.isIdle(); + if(idle !== false){ + if($('#idle-modal').is(':visible')){ + $('#remaining_seconds').html(Math.round(idle)); } - $rootScope.removeIdleDialogReady = $rootScope.$on('IdleDialogReady', function() { - $('#idle-modal').show(); - $('#idle-modal').dialog('open'); - }); - CreateDialog({ - id: 'idle-modal' , - title: "Idle Session", - scope: $rootScope, - buttons: buttons, - width: 470, - height: 240, - minWidth: 200, - callback: 'IdleDialogReady' - }); - } - }, t * 1000); + else { + var buttons = [{ + "label": "Continue", + "onClick": function() { + // make a rest call here to force the API to + // move the session time forward + Authorization.getUser(); + that.moveForward(); + $(this).dialog('close'); + }, + "class": "btn btn-primary", + "id": "idle-modal-button" + }]; + if ($rootScope.removeIdleDialogReady) { + $rootScope.removeIdleDialogReady(); + } + $rootScope.removeIdleDialogReady = $rootScope.$on('IdleDialogReady', function() { + $('#idle-modal').show(); + $('#idle-modal').dialog('open'); + }); + CreateDialog({ + id: 'idle-modal' , + title: "Idle Session", + scope: $rootScope, + buttons: buttons, + width: 470, + height: 240, + minWidth: 200, + callback: 'IdleDialogReady' + }); + } + } + else if(!idle){ + if($('#idle-modal').is(':visible')){ + $('#idle-modal').dialog('close'); + } + } + if (that.isExpired(true)) { + if($('#idle-modal').dialog('isOpen')){ + $('#idle-modal').dialog('close'); + } + that.expireSession('idle'); + } + + }, 1000); }, clearTimers: function(){ - clearTimeout($rootScope.idleTimer); - clearTimeout($rootScope.endTimer); + $interval.cancel($rootScope.expireTimer); }, init: function () { diff --git a/awx/ui/client/src/login/loginModal/loginModal.controller.js b/awx/ui/client/src/login/loginModal/loginModal.controller.js index a3386ee3ad..ce451834b4 100644 --- a/awx/ui/client/src/login/loginModal/loginModal.controller.js +++ b/awx/ui/client/src/login/loginModal/loginModal.controller.js @@ -165,6 +165,7 @@ 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'); }) @@ -187,7 +188,6 @@ export default ['$log', '$cookieStore', '$compile', '$window', '$rootScope', '$l .then(function (data) { $('#login-modal').modal('hide'); Authorization.setToken(data.data.token, data.data.expires); - $rootScope.sessionTimer = Timer.init(); scope.$emit('AuthorizationGetUser'); }, function (data) { diff --git a/awx/ui/templates/ui/index.html b/awx/ui/templates/ui/index.html index c796f29527..82ec76318a 100644 --- a/awx/ui/templates/ui/index.html +++ b/awx/ui/templates/ui/index.html @@ -58,7 +58,7 @@
- +