Finish refactoring route guards to use jslib
This commit is contained in:
parent
2a810a1cca
commit
6230302106
|
@ -9,8 +9,7 @@ import {
|
|||
import { AuthGuardService } from 'jslib-angular/services/auth-guard.service';
|
||||
|
||||
import { LockGuardService } from './services/lock-guard.service';
|
||||
import { NotPrivateGuardService } from './services/not-private-guard.service';
|
||||
import { UnauthGuardService } from './services/unauth-guard.service';
|
||||
import { LaunchGuardService } from './services/launch-guard.service';
|
||||
|
||||
import { EnvironmentComponent } from './accounts/environment.component';
|
||||
import { HintComponent } from './accounts/hint.component';
|
||||
|
@ -66,13 +65,13 @@ const routes: Routes = [
|
|||
{
|
||||
path: 'home',
|
||||
component: HomeComponent,
|
||||
canActivate: [NotPrivateGuardService, UnauthGuardService],
|
||||
canActivate: [LaunchGuardService],
|
||||
data: { state: 'home' },
|
||||
},
|
||||
{
|
||||
path: 'login',
|
||||
component: LoginComponent,
|
||||
canActivate: [NotPrivateGuardService, UnauthGuardService],
|
||||
canActivate: [LaunchGuardService],
|
||||
data: { state: 'login' },
|
||||
},
|
||||
{
|
||||
|
@ -84,19 +83,19 @@ const routes: Routes = [
|
|||
{
|
||||
path: '2fa',
|
||||
component: TwoFactorComponent,
|
||||
canActivate: [NotPrivateGuardService, UnauthGuardService],
|
||||
canActivate: [LaunchGuardService],
|
||||
data: { state: '2fa' },
|
||||
},
|
||||
{
|
||||
path: '2fa-options',
|
||||
component: TwoFactorOptionsComponent,
|
||||
canActivate: [NotPrivateGuardService, UnauthGuardService],
|
||||
canActivate: [LaunchGuardService],
|
||||
data: { state: '2fa-options' },
|
||||
},
|
||||
{
|
||||
path: 'sso',
|
||||
component: SsoComponent,
|
||||
canActivate: [NotPrivateGuardService, UnauthGuardService],
|
||||
canActivate: [LaunchGuardService],
|
||||
data: { state: 'sso' },
|
||||
},
|
||||
{
|
||||
|
@ -107,19 +106,19 @@ const routes: Routes = [
|
|||
{
|
||||
path: 'register',
|
||||
component: RegisterComponent,
|
||||
canActivate: [NotPrivateGuardService, UnauthGuardService],
|
||||
canActivate: [LaunchGuardService],
|
||||
data: { state: 'register' },
|
||||
},
|
||||
{
|
||||
path: 'hint',
|
||||
component: HintComponent,
|
||||
canActivate: [NotPrivateGuardService, UnauthGuardService],
|
||||
canActivate: [LaunchGuardService],
|
||||
data: { state: 'hint' },
|
||||
},
|
||||
{
|
||||
path: 'environment',
|
||||
component: EnvironmentComponent,
|
||||
canActivate: [NotPrivateGuardService, UnauthGuardService],
|
||||
canActivate: [LaunchGuardService],
|
||||
data: { state: 'environment' },
|
||||
},
|
||||
{
|
||||
|
|
|
@ -0,0 +1,22 @@
|
|||
import { BrowserApi } from '../../browser/browserApi';
|
||||
|
||||
import { Injectable } from '@angular/core';
|
||||
import {
|
||||
CanActivate,
|
||||
Router,
|
||||
} from '@angular/router';
|
||||
|
||||
import { UnauthGuardService } from './unauth-guard.service';
|
||||
|
||||
@Injectable()
|
||||
export class LaunchGuardService implements CanActivate {
|
||||
constructor(private router: Router, private unauthGuardService: UnauthGuardService) { }
|
||||
|
||||
async canActivate() {
|
||||
if (BrowserApi.getBackgroundPage() == null) {
|
||||
this.router.navigate(['private-mode']);
|
||||
return false;
|
||||
}
|
||||
return await this.unauthGuardService.canActivate();
|
||||
}
|
||||
}
|
|
@ -1,19 +1,16 @@
|
|||
import { Injectable } from '@angular/core';
|
||||
import {
|
||||
ActivatedRouteSnapshot,
|
||||
CanActivate,
|
||||
Router,
|
||||
} from '@angular/router';
|
||||
import { Router } from '@angular/router';
|
||||
|
||||
import { UserService } from 'jslib-common/abstractions/user.service';
|
||||
import { VaultTimeoutService } from 'jslib-common/abstractions/vaultTimeout.service';
|
||||
import { LockGuardService as BaseLockGuardService } from 'jslib-angular/services/lock-guard.service';
|
||||
|
||||
@Injectable()
|
||||
export class LockGuardService extends BaseLockGuardService {
|
||||
constructor(private vaultTimeoutService: VaultTimeoutService, private userService: UserService,
|
||||
private router: Router) {
|
||||
constructor(vaultTimeoutService: VaultTimeoutService, userService: UserService,
|
||||
router: Router) {
|
||||
super(vaultTimeoutService, userService, router);
|
||||
}
|
||||
|
||||
protected landingPage = '/tabs/current';
|
||||
protected homepage = '/tabs/current';
|
||||
}
|
||||
|
|
|
@ -1,24 +0,0 @@
|
|||
import { BrowserApi } from '../../browser/browserApi';
|
||||
|
||||
import { Injectable } from '@angular/core';
|
||||
import {
|
||||
CanActivate,
|
||||
Router,
|
||||
} from '@angular/router';
|
||||
|
||||
import { UserService } from 'jslib-common/abstractions/user.service';
|
||||
import { VaultTimeoutService } from 'jslib-common/abstractions/vaultTimeout.service';
|
||||
|
||||
@Injectable()
|
||||
export class NotPrivateGuardService implements CanActivate {
|
||||
constructor(private vaultTimeoutService: VaultTimeoutService, private userService: UserService,
|
||||
private router: Router) { }
|
||||
|
||||
async canActivate() {
|
||||
if (BrowserApi.getBackgroundPage() == null) {
|
||||
this.router.navigate(['private-mode']);
|
||||
return false;
|
||||
}
|
||||
return true;
|
||||
}
|
||||
}
|
|
@ -6,11 +6,12 @@ import {
|
|||
|
||||
import { ToasterModule } from 'angular2-toaster';
|
||||
|
||||
import { LockGuardService } from './lock-guard.service';
|
||||
import { LaunchGuardService } from './launch-guard.service';
|
||||
import { UnauthGuardService } from './unauth-guard.service';
|
||||
|
||||
import { AuthGuardService } from 'jslib-angular/services/auth-guard.service';
|
||||
import { BroadcasterService } from 'jslib-angular/services/broadcaster.service';
|
||||
import { LockGuardService } from 'jslib-angular/services/lock-guard.service';
|
||||
import { ValidationService } from 'jslib-angular/services/validation.service';
|
||||
|
||||
import { BrowserApi } from '../../browser/browserApi';
|
||||
|
@ -115,8 +116,9 @@ export function initFactory(platformUtilsService: PlatformUtilsService, i18nServ
|
|||
providers: [
|
||||
ValidationService,
|
||||
AuthGuardService,
|
||||
LaunchGuardService,
|
||||
LockGuardService,
|
||||
LaunchGuardService,
|
||||
UnauthGuardService,
|
||||
PopupUtilsService,
|
||||
BroadcasterService,
|
||||
{ provide: MessagingService, useValue: messagingService },
|
||||
|
|
|
@ -6,14 +6,14 @@ import {
|
|||
import { UserService } from 'jslib-common/abstractions/user.service';
|
||||
import { VaultTimeoutService } from 'jslib-common/abstractions/vaultTimeout.service';
|
||||
|
||||
import { UnauthGuardService as BaseUnauthGuardService } from 'jslib/angular/services/unauth-guard.service';
|
||||
import { UnauthGuardService as BaseUnauthGuardService } from 'jslib-angular/services/unauth-guard.service';
|
||||
|
||||
@Injectable()
|
||||
export class UnauthGuardService extends BaseUnauthGuardService {
|
||||
constructor(private vaultTimeoutService: VaultTimeoutService, private userService: UserService,
|
||||
private router: Router) {
|
||||
constructor(vaultTimeoutService: VaultTimeoutService, userService: UserService,
|
||||
router: Router) {
|
||||
super(vaultTimeoutService, userService, router);
|
||||
}
|
||||
|
||||
protected landingPage: '/tabs/current';
|
||||
protected homepage = '/tabs/current';
|
||||
}
|
||||
|
|
Loading…
Reference in New Issue