From f772cd31cb893f95b63d739b4522ffd29c605002 Mon Sep 17 00:00:00 2001 From: Chaim Lev-Ari Date: Wed, 23 Jan 2019 01:22:56 +0200 Subject: [PATCH] feat(auth): preserve url when redirected to login (#2591) * feat(auth): preserve url when redirected to login * feat(auth): add redirect also to unauthenticated flow * style(app): remove style changes from files * fix(app): remove reference to otpLogin * style(auth): remove semicolon --- app/app.js | 2 +- app/portainer/__module.js | 8 ++++---- app/portainer/views/auth/authController.js | 8 ++++---- 3 files changed, 9 insertions(+), 9 deletions(-) diff --git a/app/app.js b/app/app.js index 8d6c669b1..8a05b219b 100644 --- a/app/app.js +++ b/app/app.js @@ -45,7 +45,7 @@ function initAuthentication(authManager, Authentication, $rootScope, $state) { // to have more controls on which URL should trigger the unauthenticated state. $rootScope.$on('unauthenticated', function (event, data) { if (!_.includes(data.config.url, '/v2/')) { - $state.go('portainer.auth', {error: 'Your session has expired'}); + $state.go('portainer.auth', {error: 'Your session has expired', redirect: $state.current.name}); } }); } diff --git a/app/portainer/__module.js b/app/portainer/__module.js index 3b29b82ee..129c6b4b2 100644 --- a/app/portainer/__module.js +++ b/app/portainer/__module.js @@ -48,7 +48,7 @@ angular.module('portainer.app', []) var authentication = { name: 'portainer.auth', - url: '/auth', + url: '/auth?redirect', params: { logout: false, error: '' @@ -87,7 +87,7 @@ angular.module('portainer.app', []) } }; - var endpointCreation = { + var endpointCreation = { name: 'portainer.endpoints.new', url: '/new', views: { @@ -242,7 +242,7 @@ angular.module('portainer.app', []) } }; - var registryCreation = { + var registryCreation = { name: 'portainer.registries.new', url: '/new', views: { @@ -286,7 +286,7 @@ angular.module('portainer.app', []) } }; - var scheduleCreation = { + var scheduleCreation = { name: 'portainer.schedules.new', url: '/new', views: { diff --git a/app/portainer/views/auth/authController.js b/app/portainer/views/auth/authController.js index 055d359be..2e2b729bf 100644 --- a/app/portainer/views/auth/authController.js +++ b/app/portainer/views/auth/authController.js @@ -1,6 +1,6 @@ angular.module('portainer.app') -.controller('AuthenticationController', ['$q', '$scope', '$state', '$transition$', '$sanitize', 'Authentication', 'UserService', 'EndpointService', 'StateManager', 'Notifications', 'SettingsService', -function ($q, $scope, $state, $transition$, $sanitize, Authentication, UserService, EndpointService, StateManager, Notifications, SettingsService) { +.controller('AuthenticationController', ['$q', '$scope', '$state', '$transition$', '$sanitize', 'Authentication', 'UserService', 'EndpointService', 'StateManager', 'Notifications', 'SettingsService', '$stateParams', +function ($q, $scope, $state, $transition$, $sanitize, Authentication, UserService, EndpointService, StateManager, Notifications, SettingsService, $stateParams) { $scope.logo = StateManager.getState().application.logo; @@ -44,7 +44,7 @@ function ($q, $scope, $state, $transition$, $sanitize, Authentication, UserServi if (endpoints.length === 0) { $state.go('portainer.init.endpoint'); } else { - $state.go('portainer.home'); + $state.go($stateParams.redirect ||'portainer.home'); } }) .catch(function error(err) { @@ -73,7 +73,7 @@ function ($q, $scope, $state, $transition$, $sanitize, Authentication, UserServi if (endpoints.length === 0 && userDetails.role === 1) { $state.go('portainer.init.endpoint'); } else { - $state.go('portainer.home'); + $state.go($stateParams.redirect || 'portainer.home'); } }) .catch(function error(err) {