/**
* @file Page for Login component
*/
+import { isNullOrUndefined } from 'util';
import { HttpErrorResponse } from '@angular/common/http';
import { Component, Injector, OnInit } from '@angular/core';
import { FormBuilder, FormGroup, Validators } from '@angular/forms';
import { RestService } from 'RestService';
import { Observable } from 'rxjs';
import { SharedService } from 'SharedService';
-import { isNullOrUndefined } from 'util';
/**
* Creating component
/** Observable Hold the value of subscription @public */
public isLoggedIn$: Observable<boolean>;
+ /** Observable Hold the value of subscription @public */
+ public isChangePassword$: Observable<boolean>;
+
/** contains access token information @public */
public accessToken: string;
/** 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;
*/
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]]
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');
});