From 7768106d3fc0027b877fabb83f0f5d4068e09ed2 Mon Sep 17 00:00:00 2001 From: Michael Abashian Date: Thu, 8 Jun 2017 19:01:44 -0400 Subject: [PATCH] Store the url that the user comes in on before auth in preAuthUrl --- awx/ui/client/src/app.js | 3 +-- .../authentication.service.js | 2 +- .../login/loginModal/loginModal.controller.js | 23 ++++++++++++------- 3 files changed, 17 insertions(+), 11 deletions(-) diff --git a/awx/ui/client/src/app.js b/awx/ui/client/src/app.js index f01ca708ba..856f68f2e7 100644 --- a/awx/ui/client/src/app.js +++ b/awx/ui/client/src/app.js @@ -364,8 +364,7 @@ var tower = angular.module('Tower', [ if (!Authorization.getToken() || !Authorization.isUserLoggedIn()) { // User not authenticated, redirect to login page - $rootScope.lastPath = $location.path(); - $cookies.put('lastPath', $location.path()); + $cookies.put('preAuthUrl', $location.path()); $location.path('/login'); } else { var lastUser = $cookies.getObject('current_user'), diff --git a/awx/ui/client/src/login/authenticationServices/authentication.service.js b/awx/ui/client/src/login/authenticationServices/authentication.service.js index f073040e41..f7b8dd8666 100644 --- a/awx/ui/client/src/login/authenticationServices/authentication.service.js +++ b/awx/ui/client/src/login/authenticationServices/authentication.service.js @@ -103,7 +103,7 @@ export default Store('sessionTime', x); if ($cookies.getObject('current_user')) { - $cookies.put( 'lastUser', $cookies.getObject('current_user').id); + $rootScope.lastUser = $cookies.getObject('current_user').id; } ConfigService.delete(); SocketService.disconnect(); diff --git a/awx/ui/client/src/login/loginModal/loginModal.controller.js b/awx/ui/client/src/login/loginModal/loginModal.controller.js index 7003f58b10..b070798d92 100644 --- a/awx/ui/client/src/login/loginModal/loginModal.controller.js +++ b/awx/ui/client/src/login/loginModal/loginModal.controller.js @@ -62,7 +62,7 @@ export default ['$log', '$cookies', '$compile', '$rootScope', Authorization, Alert, Wait, Timer, Empty, scope, pendoService, ConfigService, CheckLicense, FeaturesService, SocketService) { - var lastPath, lastUser, sessionExpired, loginAgain; + var lastPath, lastUser, sessionExpired, loginAgain, preAuthUrl; loginAgain = function() { setTimeout(function() { @@ -80,8 +80,7 @@ export default ['$log', '$cookies', '$compile', '$rootScope', }; lastUser = function(){ - let lastUser = $cookies.get('lastUser'); - if(!Empty(lastUser) && parseInt(lastUser) === $rootScope.current_user.id){ + if(!Empty($rootScope.lastUser) && $rootScope.lastUser === $rootScope.current_user.id){ return true; } else { @@ -89,6 +88,8 @@ export default ['$log', '$cookies', '$compile', '$rootScope', } }; + preAuthUrl = $cookies.get('preAuthUrl'); + $log.debug('User session expired: ' + sessionExpired); $log.debug('Last URL: ' + lastPath()); @@ -113,11 +114,17 @@ export default ['$log', '$cookies', '$compile', '$rootScope', pendoService.issuePendoIdentity(); FeaturesService.get(); Wait("stop"); - if (lastPath() && lastUser()) { - // Go back to most recent navigation path - $location.path(lastPath()); - } else { - $location.url('/home'); + if(!Empty(preAuthUrl)){ + $location.path(preAuthUrl); + $cookies.remove('preAuthUrl'); + } + else { + if (lastPath() && lastUser()) { + // Go back to most recent navigation path + $location.path(lastPath()); + } else { + $location.url('/home'); + } } }) .catch(function () {