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 { AuthGuardService } from 'jslib-angular/services/auth-guard.service';
|
||||||
|
|
||||||
import { LockGuardService } from './services/lock-guard.service';
|
import { LockGuardService } from './services/lock-guard.service';
|
||||||
import { NotPrivateGuardService } from './services/not-private-guard.service';
|
import { LaunchGuardService } from './services/launch-guard.service';
|
||||||
import { UnauthGuardService } from './services/unauth-guard.service';
|
|
||||||
|
|
||||||
import { EnvironmentComponent } from './accounts/environment.component';
|
import { EnvironmentComponent } from './accounts/environment.component';
|
||||||
import { HintComponent } from './accounts/hint.component';
|
import { HintComponent } from './accounts/hint.component';
|
||||||
|
@ -66,13 +65,13 @@ const routes: Routes = [
|
||||||
{
|
{
|
||||||
path: 'home',
|
path: 'home',
|
||||||
component: HomeComponent,
|
component: HomeComponent,
|
||||||
canActivate: [NotPrivateGuardService, UnauthGuardService],
|
canActivate: [LaunchGuardService],
|
||||||
data: { state: 'home' },
|
data: { state: 'home' },
|
||||||
},
|
},
|
||||||
{
|
{
|
||||||
path: 'login',
|
path: 'login',
|
||||||
component: LoginComponent,
|
component: LoginComponent,
|
||||||
canActivate: [NotPrivateGuardService, UnauthGuardService],
|
canActivate: [LaunchGuardService],
|
||||||
data: { state: 'login' },
|
data: { state: 'login' },
|
||||||
},
|
},
|
||||||
{
|
{
|
||||||
|
@ -84,19 +83,19 @@ const routes: Routes = [
|
||||||
{
|
{
|
||||||
path: '2fa',
|
path: '2fa',
|
||||||
component: TwoFactorComponent,
|
component: TwoFactorComponent,
|
||||||
canActivate: [NotPrivateGuardService, UnauthGuardService],
|
canActivate: [LaunchGuardService],
|
||||||
data: { state: '2fa' },
|
data: { state: '2fa' },
|
||||||
},
|
},
|
||||||
{
|
{
|
||||||
path: '2fa-options',
|
path: '2fa-options',
|
||||||
component: TwoFactorOptionsComponent,
|
component: TwoFactorOptionsComponent,
|
||||||
canActivate: [NotPrivateGuardService, UnauthGuardService],
|
canActivate: [LaunchGuardService],
|
||||||
data: { state: '2fa-options' },
|
data: { state: '2fa-options' },
|
||||||
},
|
},
|
||||||
{
|
{
|
||||||
path: 'sso',
|
path: 'sso',
|
||||||
component: SsoComponent,
|
component: SsoComponent,
|
||||||
canActivate: [NotPrivateGuardService, UnauthGuardService],
|
canActivate: [LaunchGuardService],
|
||||||
data: { state: 'sso' },
|
data: { state: 'sso' },
|
||||||
},
|
},
|
||||||
{
|
{
|
||||||
|
@ -107,19 +106,19 @@ const routes: Routes = [
|
||||||
{
|
{
|
||||||
path: 'register',
|
path: 'register',
|
||||||
component: RegisterComponent,
|
component: RegisterComponent,
|
||||||
canActivate: [NotPrivateGuardService, UnauthGuardService],
|
canActivate: [LaunchGuardService],
|
||||||
data: { state: 'register' },
|
data: { state: 'register' },
|
||||||
},
|
},
|
||||||
{
|
{
|
||||||
path: 'hint',
|
path: 'hint',
|
||||||
component: HintComponent,
|
component: HintComponent,
|
||||||
canActivate: [NotPrivateGuardService, UnauthGuardService],
|
canActivate: [LaunchGuardService],
|
||||||
data: { state: 'hint' },
|
data: { state: 'hint' },
|
||||||
},
|
},
|
||||||
{
|
{
|
||||||
path: 'environment',
|
path: 'environment',
|
||||||
component: EnvironmentComponent,
|
component: EnvironmentComponent,
|
||||||
canActivate: [NotPrivateGuardService, UnauthGuardService],
|
canActivate: [LaunchGuardService],
|
||||||
data: { state: 'environment' },
|
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 { Injectable } from '@angular/core';
|
||||||
import {
|
import { Router } from '@angular/router';
|
||||||
ActivatedRouteSnapshot,
|
|
||||||
CanActivate,
|
|
||||||
Router,
|
|
||||||
} from '@angular/router';
|
|
||||||
|
|
||||||
import { UserService } from 'jslib-common/abstractions/user.service';
|
import { UserService } from 'jslib-common/abstractions/user.service';
|
||||||
import { VaultTimeoutService } from 'jslib-common/abstractions/vaultTimeout.service';
|
import { VaultTimeoutService } from 'jslib-common/abstractions/vaultTimeout.service';
|
||||||
|
import { LockGuardService as BaseLockGuardService } from 'jslib-angular/services/lock-guard.service';
|
||||||
|
|
||||||
@Injectable()
|
@Injectable()
|
||||||
export class LockGuardService extends BaseLockGuardService {
|
export class LockGuardService extends BaseLockGuardService {
|
||||||
constructor(private vaultTimeoutService: VaultTimeoutService, private userService: UserService,
|
constructor(vaultTimeoutService: VaultTimeoutService, userService: UserService,
|
||||||
private router: Router) {
|
router: Router) {
|
||||||
super(vaultTimeoutService, userService, 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 { ToasterModule } from 'angular2-toaster';
|
||||||
|
|
||||||
|
import { LockGuardService } from './lock-guard.service';
|
||||||
import { LaunchGuardService } from './launch-guard.service';
|
import { LaunchGuardService } from './launch-guard.service';
|
||||||
|
import { UnauthGuardService } from './unauth-guard.service';
|
||||||
|
|
||||||
import { AuthGuardService } from 'jslib-angular/services/auth-guard.service';
|
import { AuthGuardService } from 'jslib-angular/services/auth-guard.service';
|
||||||
import { BroadcasterService } from 'jslib-angular/services/broadcaster.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 { ValidationService } from 'jslib-angular/services/validation.service';
|
||||||
|
|
||||||
import { BrowserApi } from '../../browser/browserApi';
|
import { BrowserApi } from '../../browser/browserApi';
|
||||||
|
@ -115,8 +116,9 @@ export function initFactory(platformUtilsService: PlatformUtilsService, i18nServ
|
||||||
providers: [
|
providers: [
|
||||||
ValidationService,
|
ValidationService,
|
||||||
AuthGuardService,
|
AuthGuardService,
|
||||||
LaunchGuardService,
|
|
||||||
LockGuardService,
|
LockGuardService,
|
||||||
|
LaunchGuardService,
|
||||||
|
UnauthGuardService,
|
||||||
PopupUtilsService,
|
PopupUtilsService,
|
||||||
BroadcasterService,
|
BroadcasterService,
|
||||||
{ provide: MessagingService, useValue: messagingService },
|
{ provide: MessagingService, useValue: messagingService },
|
||||||
|
|
|
@ -6,14 +6,14 @@ import {
|
||||||
import { UserService } from 'jslib-common/abstractions/user.service';
|
import { UserService } from 'jslib-common/abstractions/user.service';
|
||||||
import { VaultTimeoutService } from 'jslib-common/abstractions/vaultTimeout.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()
|
@Injectable()
|
||||||
export class UnauthGuardService extends BaseUnauthGuardService {
|
export class UnauthGuardService extends BaseUnauthGuardService {
|
||||||
constructor(private vaultTimeoutService: VaultTimeoutService, private userService: UserService,
|
constructor(vaultTimeoutService: VaultTimeoutService, userService: UserService,
|
||||||
private router: Router) {
|
router: Router) {
|
||||||
super(vaultTimeoutService, userService, router);
|
super(vaultTimeoutService, userService, router);
|
||||||
}
|
}
|
||||||
|
|
||||||
protected landingPage: '/tabs/current';
|
protected homepage = '/tabs/current';
|
||||||
}
|
}
|
||||||
|
|
Loading…
Reference in New Issue