X-Git-Url: https://osm.etsi.org/gitweb/?a=blobdiff_plain;f=src%2Fapp%2Flogin%2FLoginComponent.ts;fp=src%2Fapp%2Flogin%2FLoginComponent.ts;h=8c6f5a3cf0f76eb9363cd70a7d9465053638a743;hb=a9816553feb848341a8c3214861d5479c3688578;hp=2f4f67e711ad3eafca66573adff32602e91c76a3;hpb=92d376dbeb4976952e4e99d5e53194d42d37787a;p=osm%2FNG-UI.git diff --git a/src/app/login/LoginComponent.ts b/src/app/login/LoginComponent.ts index 2f4f67e..8c6f5a3 100644 --- a/src/app/login/LoginComponent.ts +++ b/src/app/login/LoginComponent.ts @@ -55,6 +55,9 @@ export class LoginComponent implements OnInit { /** Observable Hold the value of subscription @public */ public isLoggedIn$: Observable; + /** Observable Hold the value of subscription @public */ + public isChangePassword$: Observable; + /** contains access token information @public */ public accessToken: string; @@ -70,6 +73,12 @@ export class LoginComponent implements OnInit { /** Contains all methods related to shared @public */ public sharedService: SharedService; + /** contains the loggedIn observable value @public */ + public loggedIn: boolean; + + /** contains the passwordIn observable value @public */ + public changePassword: boolean; + /** Utilizes auth service for any auth operations @private */ private authService: AuthenticationService; @@ -94,11 +103,24 @@ export class LoginComponent implements OnInit { */ public ngOnInit(): void { this.isLoggedIn$ = this.authService.isLoggedIn; - if (this.isLoggedIn$) { - this.router.navigate(['/']).catch(() => { + this.isLoggedIn$.subscribe((res: boolean): void => { + this.loggedIn = res; + }); + if (this.loggedIn === true) { + this.router.navigate(['/']).catch((): void => { // Catch Navigation Error }); } + this.isChangePassword$ = this.authService.isChangePassword; + this.isChangePassword$.subscribe((res: boolean): void => { + this.changePassword = res; + }); + if (this.changePassword === true) { + this.router.navigate(['changepassword']).catch((): void => { + // Catch Navigation Error + }); + } + this.loginForm = this.formBuilder.group({ userName: ['', [Validators.required]], password: ['', [Validators.required]] @@ -117,13 +139,19 @@ export class LoginComponent implements OnInit { this.isLoadingResults = true; this.sharedService.cleanForm(this.loginForm); this.authService.login(this.loginForm.value.userName, this.loginForm.value.password).subscribe( - (data: {}) => { + (data: {}): void => { this.isLoadingResults = false; - this.router.navigate([this.returnUrl]).catch(() => { - // Catch Navigation Error - }); + if (this.changePassword === true && this.loggedIn === false) { + this.router.navigate(['/changepassword']).catch((): void => { + // Catch Navigation Error + }); + } else { + this.router.navigate([this.returnUrl]).catch((): void => { + // Catch Navigation Error + }); + } localStorage.removeItem('returnUrl'); - }, (err: HttpErrorResponse) => { + }, (err: HttpErrorResponse): void => { this.isLoadingResults = false; this.restService.handleError(err, 'post'); });