Commit 11d4ef74e8431a1398b27875a3560c5966f9ce9c
Committed by
GitHub
1 parent
8b5793f2
[3.0] Improved login by params to support nagivation to different dashboards (#2703)
* Improved login by params to support nagivation to different dashboards * Refactorting
Showing
2 changed files
with
21 additions
and
8 deletions
@@ -261,6 +261,8 @@ export class AuthService { | @@ -261,6 +261,8 @@ export class AuthService { | ||
261 | const publicId = this.utils.getQueryParam('publicId'); | 261 | const publicId = this.utils.getQueryParam('publicId'); |
262 | const accessToken = this.utils.getQueryParam('accessToken'); | 262 | const accessToken = this.utils.getQueryParam('accessToken'); |
263 | const refreshToken = this.utils.getQueryParam('refreshToken'); | 263 | const refreshToken = this.utils.getQueryParam('refreshToken'); |
264 | + const username = this.utils.getQueryParam('username'); | ||
265 | + const password = this.utils.getQueryParam('password'); | ||
264 | if (publicId) { | 266 | if (publicId) { |
265 | return this.publicLogin(publicId).pipe( | 267 | return this.publicLogin(publicId).pipe( |
266 | mergeMap((response) => { | 268 | mergeMap((response) => { |
@@ -290,6 +292,23 @@ export class AuthService { | @@ -290,6 +292,23 @@ export class AuthService { | ||
290 | return throwError(e); | 292 | return throwError(e); |
291 | } | 293 | } |
292 | return this.procceedJwtTokenValidate(); | 294 | return this.procceedJwtTokenValidate(); |
295 | + } else if (username && password) { | ||
296 | + const loginRequest: LoginRequest = { | ||
297 | + username: username, | ||
298 | + password: password | ||
299 | + }; | ||
300 | + return this.http.post<LoginResponse>('/api/auth/login', loginRequest, defaultHttpOptions()).pipe( | ||
301 | + tap((loginResponse: LoginResponse) => { | ||
302 | + try { | ||
303 | + this.updateAndValidateToken(loginResponse.token, 'jwt_token', false); | ||
304 | + this.updateAndValidateToken(loginResponse.refreshToken, 'refresh_token', false); | ||
305 | + } catch (e) { | ||
306 | + } | ||
307 | + } | ||
308 | + ), mergeMap( () => { | ||
309 | + return this.procceedJwtTokenValidate(); | ||
310 | + } | ||
311 | + )); | ||
293 | } | 312 | } |
294 | return this.procceedJwtTokenValidate(doTokenRefresh); | 313 | return this.procceedJwtTokenValidate(doTokenRefresh); |
295 | } else { | 314 | } else { |
@@ -22,7 +22,7 @@ import { PageComponent } from '@shared/components/page.component'; | @@ -22,7 +22,7 @@ import { PageComponent } from '@shared/components/page.component'; | ||
22 | import { FormBuilder } from '@angular/forms'; | 22 | import { FormBuilder } from '@angular/forms'; |
23 | import { HttpErrorResponse } from '@angular/common/http'; | 23 | import { HttpErrorResponse } from '@angular/common/http'; |
24 | import { Constants } from '@shared/models/constants'; | 24 | import { Constants } from '@shared/models/constants'; |
25 | -import { ActivatedRoute, Router } from '@angular/router'; | 25 | +import { Router } from '@angular/router'; |
26 | 26 | ||
27 | @Component({ | 27 | @Component({ |
28 | selector: 'tb-login', | 28 | selector: 'tb-login', |
@@ -39,17 +39,11 @@ export class LoginComponent extends PageComponent implements OnInit { | @@ -39,17 +39,11 @@ export class LoginComponent extends PageComponent implements OnInit { | ||
39 | constructor(protected store: Store<AppState>, | 39 | constructor(protected store: Store<AppState>, |
40 | private authService: AuthService, | 40 | private authService: AuthService, |
41 | public fb: FormBuilder, | 41 | public fb: FormBuilder, |
42 | - private router: Router, | ||
43 | - private route: ActivatedRoute) { | 42 | + private router: Router) { |
44 | super(store); | 43 | super(store); |
45 | } | 44 | } |
46 | 45 | ||
47 | ngOnInit() { | 46 | ngOnInit() { |
48 | - if (this.route.snapshot.queryParams.username && this.route.snapshot.queryParams.password) { | ||
49 | - this.loginFormGroup.setValue({username: this.route.snapshot.queryParams.username, | ||
50 | - password: this.route.snapshot.queryParams.password}); | ||
51 | - this.login(); | ||
52 | - } | ||
53 | } | 47 | } |
54 | 48 | ||
55 | login(): void { | 49 | login(): void { |