From 1e0f8e2484e7395f029764b5f7a240346d2604c6 Mon Sep 17 00:00:00 2001 From: Vec7or <43302112+Vec7or@users.noreply.github.com> Date: Thu, 21 Jan 2021 17:44:48 +0100 Subject: [PATCH] Closes #472: redirect to previous URL after login --- docs-web/src/main/webapp/src/app/docs/app.js | 2 +- .../main/webapp/src/app/docs/controller/Login.js | 11 +++++++++-- .../webapp/src/app/docs/controller/Navigation.js | 13 +++++++++---- 3 files changed, 19 insertions(+), 7 deletions(-) diff --git a/docs-web/src/main/webapp/src/app/docs/app.js b/docs-web/src/main/webapp/src/app/docs/app.js index 06d53f5c..b0fbeb20 100644 --- a/docs-web/src/main/webapp/src/app/docs/app.js +++ b/docs-web/src/main/webapp/src/app/docs/app.js @@ -356,7 +356,7 @@ angular.module('docs', } }) .state('login', { - url: '/login', + url: '/login?redirectState&redirectParams', views: { 'page': { templateUrl: 'partial/docs/login.html', diff --git a/docs-web/src/main/webapp/src/app/docs/controller/Login.js b/docs-web/src/main/webapp/src/app/docs/controller/Login.js index 9f862cda..dc1fc09d 100644 --- a/docs-web/src/main/webapp/src/app/docs/controller/Login.js +++ b/docs-web/src/main/webapp/src/app/docs/controller/Login.js @@ -3,7 +3,7 @@ /** * Login controller. */ -angular.module('docs').controller('Login', function(Restangular, $scope, $rootScope, $state, $dialog, User, $translate, $uibModal) { +angular.module('docs').controller('Login', function(Restangular, $scope, $rootScope, $state, $stateParams, $dialog, User, $translate, $uibModal) { $scope.codeRequired = false; // Get the app configuration @@ -26,7 +26,14 @@ angular.module('docs').controller('Login', function(Restangular, $scope, $rootSc User.userInfo(true).then(function(data) { $rootScope.userInfo = data; }); - $state.go('document.default'); + + if($stateParams.redirectState !== undefined && $stateParams.redirectParams !== undefined) { + $state.go($stateParams.redirectState, JSON.parse($stateParams.redirectParams)).catch(function(){ + $state.go('document.default'); + }); + } else { + $state.go('document.default'); + } }, function(data) { if (data.data.type === 'ValidationCodeRequired') { // A TOTP validation code is required to login diff --git a/docs-web/src/main/webapp/src/app/docs/controller/Navigation.js b/docs-web/src/main/webapp/src/app/docs/controller/Navigation.js index 6fa92d64..3f1e5e9f 100644 --- a/docs-web/src/main/webapp/src/app/docs/controller/Navigation.js +++ b/docs-web/src/main/webapp/src/app/docs/controller/Navigation.js @@ -3,13 +3,18 @@ /** * Navigation controller. */ -angular.module('docs').controller('Navigation', function($scope, $state, $rootScope, User) { +angular.module('docs').controller('Navigation', function($scope, $state, $stateParams, $rootScope, User) { User.userInfo().then(function(data) { $rootScope.userInfo = data; if (data.anonymous) { - $state.go('login', {}, { - location: 'replace' - }); + if($state.current.name !== 'login') { + $state.go('login', { + redirectState: $state.current.name, + redirectParams: JSON.stringify($stateParams), + }, { + location: 'replace' + }); + } } });