Closes #472: redirect to previous URL after login

This commit is contained in:
Vec7or 2021-01-21 17:44:48 +01:00 committed by GitHub
parent bcb4c6d7b0
commit 1e0f8e2484
No known key found for this signature in database
GPG Key ID: 4AEE18F83AFDEB23
3 changed files with 19 additions and 7 deletions

View File

@ -356,7 +356,7 @@ angular.module('docs',
}
})
.state('login', {
url: '/login',
url: '/login?redirectState&redirectParams',
views: {
'page': {
templateUrl: 'partial/docs/login.html',

View File

@ -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;
});
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

View File

@ -3,14 +3,19 @@
/**
* 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', {}, {
if($state.current.name !== 'login') {
$state.go('login', {
redirectState: $state.current.name,
redirectParams: JSON.stringify($stateParams),
}, {
location: 'replace'
});
}
}
});
/**