From fc312398cd276b0cfc5635664add9f711da869d6 Mon Sep 17 00:00:00 2001 From: Michael Abashian Date: Thu, 8 Jun 2017 18:40:12 -0400 Subject: [PATCH 1/4] Redirect the user to the link they clicked on after authentication --- awx/ui/client/src/app.js | 2 ++ .../src/login/authenticationServices/authentication.service.js | 2 +- awx/ui/client/src/login/loginModal/loginModal.controller.js | 3 ++- 3 files changed, 5 insertions(+), 2 deletions(-) diff --git a/awx/ui/client/src/app.js b/awx/ui/client/src/app.js index ab22556233..f01ca708ba 100644 --- a/awx/ui/client/src/app.js +++ b/awx/ui/client/src/app.js @@ -364,6 +364,8 @@ 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()); $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 f7b8dd8666..f073040e41 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')) { - $rootScope.lastUser = $cookies.getObject('current_user').id; + $cookies.put( '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 470ab1fd50..7003f58b10 100644 --- a/awx/ui/client/src/login/loginModal/loginModal.controller.js +++ b/awx/ui/client/src/login/loginModal/loginModal.controller.js @@ -80,7 +80,8 @@ export default ['$log', '$cookies', '$compile', '$rootScope', }; lastUser = function(){ - if(!Empty($rootScope.lastUser) && $rootScope.lastUser === $rootScope.current_user.id){ + let lastUser = $cookies.get('lastUser'); + if(!Empty(lastUser) && parseInt(lastUser) === $rootScope.current_user.id){ return true; } else { From 7768106d3fc0027b877fabb83f0f5d4068e09ed2 Mon Sep 17 00:00:00 2001 From: Michael Abashian Date: Thu, 8 Jun 2017 19:01:44 -0400 Subject: [PATCH 2/4] 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 () { From cfc15dab379ac4590615d844b8e28931a9d2e952 Mon Sep 17 00:00:00 2001 From: Michael Abashian Date: Thu, 8 Jun 2017 19:19:33 -0400 Subject: [PATCH 3/4] Only store the preAuthUrl if the user is trying to navigate to a non-login/logout state --- awx/ui/client/src/app.js | 4 +++- 1 file changed, 3 insertions(+), 1 deletion(-) diff --git a/awx/ui/client/src/app.js b/awx/ui/client/src/app.js index 856f68f2e7..800846af35 100644 --- a/awx/ui/client/src/app.js +++ b/awx/ui/client/src/app.js @@ -364,7 +364,9 @@ var tower = angular.module('Tower', [ if (!Authorization.getToken() || !Authorization.isUserLoggedIn()) { // User not authenticated, redirect to login page - $cookies.put('preAuthUrl', $location.path()); + if (!/^\/(login|logout)/.test($location.path())) { + $cookies.put('preAuthUrl', $location.path()); + } $location.path('/login'); } else { var lastUser = $cookies.getObject('current_user'), From 555c1dcb887448c7f74442d4e4e55750b5dee9d6 Mon Sep 17 00:00:00 2001 From: Michael Abashian Date: Fri, 9 Jun 2017 09:20:49 -0400 Subject: [PATCH 4/4] Store the preAuthUrl on rootScope instead of in the cookie --- awx/ui/client/src/app.js | 2 +- awx/ui/client/src/login/loginModal/loginModal.controller.js | 4 ++-- 2 files changed, 3 insertions(+), 3 deletions(-) diff --git a/awx/ui/client/src/app.js b/awx/ui/client/src/app.js index 800846af35..02b13f0f40 100644 --- a/awx/ui/client/src/app.js +++ b/awx/ui/client/src/app.js @@ -365,7 +365,7 @@ var tower = angular.module('Tower', [ if (!Authorization.getToken() || !Authorization.isUserLoggedIn()) { // User not authenticated, redirect to login page if (!/^\/(login|logout)/.test($location.path())) { - $cookies.put('preAuthUrl', $location.path()); + $rootScope.preAuthUrl = $location.path(); } $location.path('/login'); } else { diff --git a/awx/ui/client/src/login/loginModal/loginModal.controller.js b/awx/ui/client/src/login/loginModal/loginModal.controller.js index b070798d92..e65728cb21 100644 --- a/awx/ui/client/src/login/loginModal/loginModal.controller.js +++ b/awx/ui/client/src/login/loginModal/loginModal.controller.js @@ -88,7 +88,7 @@ export default ['$log', '$cookies', '$compile', '$rootScope', } }; - preAuthUrl = $cookies.get('preAuthUrl'); + preAuthUrl = $rootScope.preAuthUrl; $log.debug('User session expired: ' + sessionExpired); $log.debug('Last URL: ' + lastPath()); @@ -116,7 +116,7 @@ export default ['$log', '$cookies', '$compile', '$rootScope', Wait("stop"); if(!Empty(preAuthUrl)){ $location.path(preAuthUrl); - $cookies.remove('preAuthUrl'); + delete $rootScope.preAuthUrl; } else { if (lastPath() && lastUser()) {