2018-06-10 04:02:45 +02:00
|
|
|
import { Injectable } from '@angular/core';
|
|
|
|
import {
|
|
|
|
CanActivate,
|
|
|
|
Router,
|
|
|
|
} from '@angular/router';
|
|
|
|
|
|
|
|
import { UserService } from 'jslib/abstractions/user.service';
|
2020-03-30 16:59:47 +02:00
|
|
|
import { VaultTimeoutService } from 'jslib/abstractions/vaultTimeout.service';
|
2018-06-10 04:02:45 +02:00
|
|
|
|
|
|
|
@Injectable()
|
|
|
|
export class UnauthGuardService implements CanActivate {
|
2020-03-30 16:59:47 +02:00
|
|
|
constructor(private vaultTimeoutService: VaultTimeoutService, private userService: UserService,
|
2018-06-10 04:02:45 +02:00
|
|
|
private router: Router) { }
|
|
|
|
|
|
|
|
async canActivate() {
|
|
|
|
const isAuthed = await this.userService.isAuthenticated();
|
|
|
|
if (isAuthed) {
|
2020-03-30 16:59:47 +02:00
|
|
|
const locked = await this.vaultTimeoutService.isLocked();
|
2019-02-14 03:55:11 +01:00
|
|
|
if (locked) {
|
2018-06-10 04:02:45 +02:00
|
|
|
this.router.navigate(['lock']);
|
|
|
|
} else {
|
|
|
|
this.router.navigate(['vault']);
|
|
|
|
}
|
|
|
|
return false;
|
|
|
|
}
|
|
|
|
|
|
|
|
return true;
|
|
|
|
}
|
|
|
|
}
|