Commit 11d4ef74e8431a1398b27875a3560c5966f9ce9c

Authored by VoBa
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
... ... @@ -261,6 +261,8 @@ export class AuthService {
261 261 const publicId = this.utils.getQueryParam('publicId');
262 262 const accessToken = this.utils.getQueryParam('accessToken');
263 263 const refreshToken = this.utils.getQueryParam('refreshToken');
  264 + const username = this.utils.getQueryParam('username');
  265 + const password = this.utils.getQueryParam('password');
264 266 if (publicId) {
265 267 return this.publicLogin(publicId).pipe(
266 268 mergeMap((response) => {
... ... @@ -290,6 +292,23 @@ export class AuthService {
290 292 return throwError(e);
291 293 }
292 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 313 return this.procceedJwtTokenValidate(doTokenRefresh);
295 314 } else {
... ...
... ... @@ -22,7 +22,7 @@ import { PageComponent } from '@shared/components/page.component';
22 22 import { FormBuilder } from '@angular/forms';
23 23 import { HttpErrorResponse } from '@angular/common/http';
24 24 import { Constants } from '@shared/models/constants';
25   -import { ActivatedRoute, Router } from '@angular/router';
  25 +import { Router } from '@angular/router';
26 26
27 27 @Component({
28 28 selector: 'tb-login',
... ... @@ -39,17 +39,11 @@ export class LoginComponent extends PageComponent implements OnInit {
39 39 constructor(protected store: Store<AppState>,
40 40 private authService: AuthService,
41 41 public fb: FormBuilder,
42   - private router: Router,
43   - private route: ActivatedRoute) {
  42 + private router: Router) {
44 43 super(store);
45 44 }
46 45
47 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 49 login(): void {
... ...