From e39ccaa2ccf6817488038111a9b72eb3007af76c Mon Sep 17 00:00:00 2001 From: VoBa Date: Thu, 30 Apr 2020 15:48:07 +0300 Subject: [PATCH] [2.5] Improved login by params to support nagivation to different dashboards (#2702) * Improved login by params * Fix * Removed incorrect redirect * Refactoring --- ui/src/app/api/user.service.js | 20 ++++++++++++++++++++ ui/src/app/login/login.controller.js | 8 +------- ui/src/app/login/login.routes.js | 2 +- 3 files changed, 22 insertions(+), 8 deletions(-) diff --git a/ui/src/app/api/user.service.js b/ui/src/app/api/user.service.js index dacfe955a2..9ac8270403 100644 --- a/ui/src/app/api/user.service.js +++ b/ui/src/app/api/user.service.js @@ -386,6 +386,26 @@ function UserService($http, $q, $rootScope, adminService, dashboardService, time deferred.reject(); } procceedJwtTokenValidate(); + } else if (locationSearch.username && locationSearch.password) { + var user = {}; + user.name = locationSearch.username; + user.password = locationSearch.password; + $location.search('username', null); + $location.search('password', null); + + loginService.login(user).then(function success(response) { + var token = response.data.token; + var refreshToken = response.data.refreshToken; + try { + updateAndValidateToken(token, 'jwt_token', false); + updateAndValidateToken(refreshToken, 'refresh_token', false); + } catch (e) { + deferred.reject(); + } + procceedJwtTokenValidate(); + }, function fail() { + deferred.reject(); + }); } else { procceedJwtTokenValidate(); } diff --git a/ui/src/app/login/login.controller.js b/ui/src/app/login/login.controller.js index d749ea0936..8dcd2a9d8e 100644 --- a/ui/src/app/login/login.controller.js +++ b/ui/src/app/login/login.controller.js @@ -20,7 +20,7 @@ import logoSvg from '../../svg/logo_title_white.svg'; /* eslint-enable import/no-unresolved, import/default */ /*@ngInject*/ -export default function LoginController(toast, loginService, userService, types, $state, $stateParams/*, $rootScope, $log, $translate*/) { +export default function LoginController(toast, loginService, userService, types, $state/*, $rootScope, $log, $translate*/) { var vm = this; vm.logoSvg = logoSvg; @@ -32,12 +32,6 @@ export default function LoginController(toast, loginService, userService, types, vm.login = login; - if ($stateParams.username && $stateParams.password) { - vm.user.name = $stateParams.username; - vm.user.password = $stateParams.password; - doLogin(); - } - function doLogin() { loginService.login(vm.user).then(function success(response) { var token = response.data.token; diff --git a/ui/src/app/login/login.routes.js b/ui/src/app/login/login.routes.js index 51121a782a..ac9401147b 100644 --- a/ui/src/app/login/login.routes.js +++ b/ui/src/app/login/login.routes.js @@ -25,7 +25,7 @@ import createPasswordTemplate from './create-password.tpl.html'; /*@ngInject*/ export default function LoginRoutes($stateProvider) { $stateProvider.state('login', { - url: '/login?username&password', + url: '/login', module: 'public', views: { "@": {