[3.0] Improved login by params to support nagivation to different dashboards (#2703)

* Improved login by params to support nagivation to different dashboards

* Refactorting
This commit is contained in:
VoBa 2020-04-30 15:42:19 +03:00 committed by GitHub
parent 8b5793f203
commit 11d4ef74e8
No known key found for this signature in database
GPG Key ID: 4AEE18F83AFDEB23
2 changed files with 21 additions and 8 deletions

View File

@ -261,6 +261,8 @@ export class AuthService {
const publicId = this.utils.getQueryParam('publicId'); const publicId = this.utils.getQueryParam('publicId');
const accessToken = this.utils.getQueryParam('accessToken'); const accessToken = this.utils.getQueryParam('accessToken');
const refreshToken = this.utils.getQueryParam('refreshToken'); const refreshToken = this.utils.getQueryParam('refreshToken');
const username = this.utils.getQueryParam('username');
const password = this.utils.getQueryParam('password');
if (publicId) { if (publicId) {
return this.publicLogin(publicId).pipe( return this.publicLogin(publicId).pipe(
mergeMap((response) => { mergeMap((response) => {
@ -290,6 +292,23 @@ export class AuthService {
return throwError(e); return throwError(e);
} }
return this.procceedJwtTokenValidate(); return this.procceedJwtTokenValidate();
} else if (username && password) {
const loginRequest: LoginRequest = {
username: username,
password: password
};
return this.http.post<LoginResponse>('/api/auth/login', loginRequest, defaultHttpOptions()).pipe(
tap((loginResponse: LoginResponse) => {
try {
this.updateAndValidateToken(loginResponse.token, 'jwt_token', false);
this.updateAndValidateToken(loginResponse.refreshToken, 'refresh_token', false);
} catch (e) {
}
}
), mergeMap( () => {
return this.procceedJwtTokenValidate();
}
));
} }
return this.procceedJwtTokenValidate(doTokenRefresh); return this.procceedJwtTokenValidate(doTokenRefresh);
} else { } else {

View File

@ -22,7 +22,7 @@ import { PageComponent } from '@shared/components/page.component';
import { FormBuilder } from '@angular/forms'; import { FormBuilder } from '@angular/forms';
import { HttpErrorResponse } from '@angular/common/http'; import { HttpErrorResponse } from '@angular/common/http';
import { Constants } from '@shared/models/constants'; import { Constants } from '@shared/models/constants';
import { ActivatedRoute, Router } from '@angular/router'; import { Router } from '@angular/router';
@Component({ @Component({
selector: 'tb-login', selector: 'tb-login',
@ -39,17 +39,11 @@ export class LoginComponent extends PageComponent implements OnInit {
constructor(protected store: Store<AppState>, constructor(protected store: Store<AppState>,
private authService: AuthService, private authService: AuthService,
public fb: FormBuilder, public fb: FormBuilder,
private router: Router, private router: Router) {
private route: ActivatedRoute) {
super(store); super(store);
} }
ngOnInit() { ngOnInit() {
if (this.route.snapshot.queryParams.username && this.route.snapshot.queryParams.password) {
this.loginFormGroup.setValue({username: this.route.snapshot.queryParams.username,
password: this.route.snapshot.queryParams.password});
this.login();
}
} }
login(): void { login(): void {