Commit 74bf131930df891132fcc3ef72a17bb2994667ae
1 parent
5f16cbe2
Redirect to a previous page after login
Showing
3 changed files
with
15 additions
and
24 deletions
@@ -27,6 +27,7 @@ function UserService($http, $q, $rootScope, adminService, dashboardService, time | @@ -27,6 +27,7 @@ function UserService($http, $q, $rootScope, adminService, dashboardService, time | ||
27 | currentUserDetails = null, | 27 | currentUserDetails = null, |
28 | lastPublicDashboardId = null, | 28 | lastPublicDashboardId = null, |
29 | allowedDashboardIds = [], | 29 | allowedDashboardIds = [], |
30 | + redirectParams = null, | ||
30 | userTokenAccessEnabled = false, | 31 | userTokenAccessEnabled = false, |
31 | userLoaded = false; | 32 | userLoaded = false; |
32 | 33 | ||
@@ -56,6 +57,7 @@ function UserService($http, $q, $rootScope, adminService, dashboardService, time | @@ -56,6 +57,7 @@ function UserService($http, $q, $rootScope, adminService, dashboardService, time | ||
56 | refreshTokenPending: refreshTokenPending, | 57 | refreshTokenPending: refreshTokenPending, |
57 | updateAuthorizationHeader: updateAuthorizationHeader, | 58 | updateAuthorizationHeader: updateAuthorizationHeader, |
58 | setAuthorizationRequestHeader: setAuthorizationRequestHeader, | 59 | setAuthorizationRequestHeader: setAuthorizationRequestHeader, |
60 | + setRedirectParams: setRedirectParams, | ||
59 | gotoDefaultPlace: gotoDefaultPlace, | 61 | gotoDefaultPlace: gotoDefaultPlace, |
60 | forceDefaultPlace: forceDefaultPlace, | 62 | forceDefaultPlace: forceDefaultPlace, |
61 | updateLastPublicDashboardId: updateLastPublicDashboardId, | 63 | updateLastPublicDashboardId: updateLastPublicDashboardId, |
@@ -110,34 +112,24 @@ function UserService($http, $q, $rootScope, adminService, dashboardService, time | @@ -110,34 +112,24 @@ function UserService($http, $q, $rootScope, adminService, dashboardService, time | ||
110 | lastPublicDashboardId = null; | 112 | lastPublicDashboardId = null; |
111 | userTokenAccessEnabled = false; | 113 | userTokenAccessEnabled = false; |
112 | allowedDashboardIds = []; | 114 | allowedDashboardIds = []; |
113 | - var deferred = $q.defer(); | ||
114 | if (!jwtToken) { | 115 | if (!jwtToken) { |
115 | clearTokenData(); | 116 | clearTokenData(); |
116 | if (notify) { | 117 | if (notify) { |
117 | $rootScope.$broadcast('unauthenticated', doLogout); | 118 | $rootScope.$broadcast('unauthenticated', doLogout); |
118 | - deferred.reject(); | ||
119 | } | 119 | } |
120 | - deferred.resolve(); | ||
121 | } else { | 120 | } else { |
122 | updateAndValidateToken(jwtToken, 'jwt_token', true); | 121 | updateAndValidateToken(jwtToken, 'jwt_token', true); |
123 | updateAndValidateToken(refreshToken, 'refresh_token', true); | 122 | updateAndValidateToken(refreshToken, 'refresh_token', true); |
124 | if (notify) { | 123 | if (notify) { |
125 | loadUser(false).then(function success() { | 124 | loadUser(false).then(function success() { |
126 | $rootScope.$broadcast('authenticated'); | 125 | $rootScope.$broadcast('authenticated'); |
127 | - deferred.resolve(); | ||
128 | }, function fail() { | 126 | }, function fail() { |
129 | $rootScope.$broadcast('unauthenticated'); | 127 | $rootScope.$broadcast('unauthenticated'); |
130 | - deferred.reject(); | ||
131 | }); | 128 | }); |
132 | } else { | 129 | } else { |
133 | - loadUser(false).then(function success() { | ||
134 | - deferred.resolve(); | ||
135 | - }, function fail() { | ||
136 | - deferred.reject(); | ||
137 | - }); | 130 | + loadUser(false); |
138 | } | 131 | } |
139 | } | 132 | } |
140 | - return deferred.promise; | ||
141 | } | 133 | } |
142 | 134 | ||
143 | function isAuthenticated() { | 135 | function isAuthenticated() { |
@@ -551,9 +543,15 @@ function UserService($http, $q, $rootScope, adminService, dashboardService, time | @@ -551,9 +543,15 @@ function UserService($http, $q, $rootScope, adminService, dashboardService, time | ||
551 | return false; | 543 | return false; |
552 | } | 544 | } |
553 | 545 | ||
546 | + function setRedirectParams(params) { | ||
547 | + redirectParams = params; | ||
548 | + } | ||
549 | + | ||
554 | function gotoDefaultPlace(params) { | 550 | function gotoDefaultPlace(params) { |
555 | if (currentUser && isAuthenticated()) { | 551 | if (currentUser && isAuthenticated()) { |
556 | - var place = 'home.links'; | 552 | + var place = redirectParams ? redirectParams.toName : 'home.links'; |
553 | + params = redirectParams ? redirectParams.params : params; | ||
554 | + redirectParams = null; | ||
557 | if (currentUser.authority === 'TENANT_ADMIN' || currentUser.authority === 'CUSTOMER_USER') { | 555 | if (currentUser.authority === 'TENANT_ADMIN' || currentUser.authority === 'CUSTOMER_USER') { |
558 | if (userHasDefaultDashboard()) { | 556 | if (userHasDefaultDashboard()) { |
559 | place = $rootScope.forceFullscreen ? 'dashboard' : 'home.dashboards.dashboard'; | 557 | place = $rootScope.forceFullscreen ? 'dashboard' : 'home.dashboards.dashboard'; |
@@ -127,7 +127,8 @@ export default function AppRun($rootScope, $window, $injector, $location, $log, | @@ -127,7 +127,8 @@ export default function AppRun($rootScope, $window, $injector, $location, $log, | ||
127 | var redirectParams = {}; | 127 | var redirectParams = {}; |
128 | redirectParams.toName = to.name; | 128 | redirectParams.toName = to.name; |
129 | redirectParams.params = params; | 129 | redirectParams.params = params; |
130 | - $state.go('login', redirectParams); | 130 | + userService.setRedirectParams(redirectParams); |
131 | + $state.go('login', params); | ||
131 | } | 132 | } |
132 | } | 133 | } |
133 | } else { | 134 | } else { |
@@ -20,7 +20,7 @@ import logoSvg from '../../svg/logo_title_white.svg'; | @@ -20,7 +20,7 @@ import logoSvg from '../../svg/logo_title_white.svg'; | ||
20 | /* eslint-enable import/no-unresolved, import/default */ | 20 | /* eslint-enable import/no-unresolved, import/default */ |
21 | 21 | ||
22 | /*@ngInject*/ | 22 | /*@ngInject*/ |
23 | -export default function LoginController(toast, loginService, userService, $state, $stateParams, $rootScope) { | 23 | +export default function LoginController(toast, loginService, userService) { |
24 | var vm = this; | 24 | var vm = this; |
25 | 25 | ||
26 | vm.logoSvg = logoSvg; | 26 | vm.logoSvg = logoSvg; |
@@ -30,22 +30,14 @@ export default function LoginController(toast, loginService, userService, $state | @@ -30,22 +30,14 @@ export default function LoginController(toast, loginService, userService, $state | ||
30 | password: '' | 30 | password: '' |
31 | }; | 31 | }; |
32 | 32 | ||
33 | - vm.params = $stateParams; | 33 | + // vm.params = $stateParams; |
34 | vm.login = login; | 34 | vm.login = login; |
35 | 35 | ||
36 | function doLogin() { | 36 | function doLogin() { |
37 | loginService.login(vm.user).then(function success(response) { | 37 | loginService.login(vm.user).then(function success(response) { |
38 | var token = response.data.token; | 38 | var token = response.data.token; |
39 | var refreshToken = response.data.refreshToken; | 39 | var refreshToken = response.data.refreshToken; |
40 | - userService.setUserFromJwtToken(token, refreshToken, true).then(function() { | ||
41 | - if (vm.params.toName && vm.params.toName !== 'login') { | ||
42 | - if (vm.params.toName == 'home.dashboards.dashboard' && $rootScope.forceFullscreen) { | ||
43 | - $state.go('dashboard', vm.params.params) | ||
44 | - } else { | ||
45 | - $state.go(vm.params.toName, vm.params.params) | ||
46 | - } | ||
47 | - } | ||
48 | - }); | 40 | + userService.setUserFromJwtToken(token, refreshToken, true); |
49 | }, function fail(/*response*/) { | 41 | }, function fail(/*response*/) { |
50 | /*if (response && response.data && response.data.message) { | 42 | /*if (response && response.data && response.data.message) { |
51 | toast.showError(response.data.message); | 43 | toast.showError(response.data.message); |