2021-07-02 16:05:21 +01:00
|
|
|
import { Injectable } from '@angular/core';
|
|
|
|
|
import { CanActivate, ActivatedRouteSnapshot, RouterStateSnapshot, UrlTree, Router } from '@angular/router';
|
|
|
|
|
import { Observable } from 'rxjs';
|
2021-08-27 13:39:52 +01:00
|
|
|
import { SessionStore } from '../store/session.service';
|
2021-09-02 14:23:17 +01:00
|
|
|
import { Platform } from '@ionic/angular';
|
2022-04-08 13:52:00 +01:00
|
|
|
import { RouteService } from 'src/app/services/route.service'
|
2023-01-24 15:56:47 +01:00
|
|
|
import { FirstEnterService } from 'src/app/services/first-enter.service'
|
2021-07-02 16:05:21 +01:00
|
|
|
|
|
|
|
|
@Injectable({
|
|
|
|
|
providedIn: 'root'
|
|
|
|
|
})
|
|
|
|
|
export class LoginGuard implements CanActivate {
|
2023-09-28 09:02:15 +01:00
|
|
|
constructor(
|
|
|
|
|
private router:Router,
|
2022-04-08 13:52:00 +01:00
|
|
|
private platform: Platform,
|
2023-01-24 15:56:47 +01:00
|
|
|
private FirstEnterService: FirstEnterService ) {
|
2021-07-02 16:05:21 +01:00
|
|
|
|
|
|
|
|
}
|
|
|
|
|
canActivate(
|
|
|
|
|
route: ActivatedRouteSnapshot,
|
|
|
|
|
state: RouterStateSnapshot): Observable<boolean | UrlTree> | Promise<boolean | UrlTree> | boolean | UrlTree {
|
2023-09-28 09:02:15 +01:00
|
|
|
|
2021-09-02 12:17:14 +01:00
|
|
|
if(SessionStore.exist && SessionStore.user.Inactivity && SessionStore.user.LoginPreference != 'Pin' ) {
|
2022-12-21 14:53:01 +01:00
|
|
|
// enter app
|
2023-01-24 15:56:47 +01:00
|
|
|
this.FirstEnterService.enter()
|
2021-07-02 16:05:21 +01:00
|
|
|
return false
|
2022-12-21 16:19:06 +01:00
|
|
|
} else if(SessionStore.exist && !SessionStore.user.Inactivity && SessionStore.user.LoginPreference == 'Pin' && SessionStore.forceToLoginWithForceToLogInWithPassword && this.platform.is('mobile')) {
|
2022-12-21 14:53:01 +01:00
|
|
|
// login with password while has pin
|
2022-12-19 15:48:40 +01:00
|
|
|
SessionStore.forceToLoginWithForceToLogInWithPassword = false
|
|
|
|
|
return true
|
2022-12-21 15:08:55 +01:00
|
|
|
} else if(SessionStore.exist && this.platform.is('mobile') && SessionStore.user.LoginPreference == 'Pin' ) {
|
2022-12-21 14:53:01 +01:00
|
|
|
// go to pin page
|
2021-09-02 12:17:14 +01:00
|
|
|
this.router.navigate(['/pin']);
|
|
|
|
|
return false
|
2022-12-21 16:19:06 +01:00
|
|
|
} else if(SessionStore.exist && !SessionStore.user.Inactivity && SessionStore.user.LoginPreference == 'Pin' && this.platform.is('mobile')) {
|
2021-09-02 12:17:14 +01:00
|
|
|
this.router.navigate(['/inactivity']);
|
|
|
|
|
return false
|
2021-07-02 16:05:21 +01:00
|
|
|
} else {
|
|
|
|
|
return true
|
|
|
|
|
}
|
|
|
|
|
}
|
2021-09-01 12:17:40 +01:00
|
|
|
|
2021-07-02 16:05:21 +01:00
|
|
|
}
|