launch guard + auth guard
This commit is contained in:
parent
985b4b5b8d
commit
efee88f922
|
@ -2,7 +2,7 @@
|
||||||
<a routerLink="/environment" class="settings-icon">
|
<a routerLink="/environment" class="settings-icon">
|
||||||
<i class="fa fa-cog fa-lg"></i><span> {{'settings' | i18n}}</span>
|
<i class="fa fa-cog fa-lg"></i><span> {{'settings' | i18n}}</span>
|
||||||
</a>
|
</a>
|
||||||
<img src="../images/logo@2x.png" alt="bitwarden" />
|
<img src="../images/logo@2x.png" alt="bitwarden" class="img-responsive" />
|
||||||
<p>{{'loginOrCreateNewAccount' | i18n}}</p>
|
<p>{{'loginOrCreateNewAccount' | i18n}}</p>
|
||||||
<div class="bottom-buttons">
|
<div class="bottom-buttons">
|
||||||
<a class="btn btn-lg btn-primary btn-block" routerLink="/register">
|
<a class="btn btn-lg btn-primary btn-block" routerLink="/register">
|
||||||
|
|
|
@ -86,7 +86,11 @@ const outSlideUp = [
|
||||||
];
|
];
|
||||||
|
|
||||||
export const routerTransition = trigger('routerTransition', [
|
export const routerTransition = trigger('routerTransition', [
|
||||||
|
transition('void => home', inSlideLeft),
|
||||||
|
transition('void => tabs', inSlideLeft),
|
||||||
|
|
||||||
transition('home => login', inSlideLeft),
|
transition('home => login', inSlideLeft),
|
||||||
|
transition('home => environment', inSlideUp),
|
||||||
|
|
||||||
transition('login => home', outSlideRight),
|
transition('login => home', outSlideRight),
|
||||||
transition('login => hint', inSlideUp),
|
transition('login => hint', inSlideUp),
|
||||||
|
@ -94,6 +98,8 @@ export const routerTransition = trigger('routerTransition', [
|
||||||
|
|
||||||
transition('hint => login', outSlideDown),
|
transition('hint => login', outSlideDown),
|
||||||
|
|
||||||
|
transition('environment => home', outSlideDown),
|
||||||
|
|
||||||
transition('2fa => login', outSlideRight),
|
transition('2fa => login', outSlideRight),
|
||||||
transition('2fa => 2fa-options', inSlideUp),
|
transition('2fa => 2fa-options', inSlideUp),
|
||||||
transition('2fa-options => 2fa', outSlideDown),
|
transition('2fa-options => 2fa', outSlideDown),
|
||||||
|
|
|
@ -6,6 +6,8 @@ import {
|
||||||
|
|
||||||
import { AuthGuardService } from 'jslib/angular/services/auth-guard.service';
|
import { AuthGuardService } from 'jslib/angular/services/auth-guard.service';
|
||||||
|
|
||||||
|
import { LaunchGuardService } from './services/launch-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';
|
||||||
import { HomeComponent } from './accounts/home.component';
|
import { HomeComponent } from './accounts/home.component';
|
||||||
|
@ -27,28 +29,115 @@ import { GroupingsComponent } from './vault/groupings.component';
|
||||||
import { ViewComponent } from './vault/view.component';
|
import { ViewComponent } from './vault/view.component';
|
||||||
|
|
||||||
const routes: Routes = [
|
const routes: Routes = [
|
||||||
{ path: '', redirectTo: '/tabs/current', pathMatch: 'full' },
|
|
||||||
{ path: 'vault', redirectTo: '/tabs/vault', pathMatch: 'full' },
|
|
||||||
{ path: 'home', component: HomeComponent, data: { state: 'home' } },
|
|
||||||
{ path: 'login', component: LoginComponent, data: { state: 'login' } },
|
|
||||||
{ path: 'lock', component: LockComponent, data: { state: 'lock' } },
|
|
||||||
{ path: '2fa', component: TwoFactorComponent, data: { state: '2fa' } },
|
|
||||||
{ path: '2fa-options', component: TwoFactorOptionsComponent, data: { state: '2fa-options' } },
|
|
||||||
{ path: 'register', component: RegisterComponent, data: { state: 'register' } },
|
|
||||||
{ path: 'hint', component: HintComponent, data: { state: 'hint' } },
|
|
||||||
{ path: 'environment', component: EnvironmentComponent, data: { state: 'environment' } },
|
|
||||||
{ path: 'ciphers', component: CiphersComponent, data: { state: 'ciphers' } },
|
|
||||||
{ path: 'view-cipher', component: ViewComponent, data: { state: 'view-cipher' } },
|
|
||||||
{ path: 'add-cipher', component: AddEditComponent, data: { state: 'add-cipher' } },
|
|
||||||
{ path: 'edit-cipher', component: AddEditComponent, data: { state: 'edit-cipher' } },
|
|
||||||
{ path: 'generator', component: PasswordGeneratorComponent, data: { state: 'generator' } },
|
|
||||||
{ path: 'generator-history', component: PasswordGeneratorHistoryComponent, data: { state: 'generator-history' } },
|
|
||||||
{ path: 'export', component: ExportComponent, data: { state: 'export' } },
|
|
||||||
{
|
{
|
||||||
path: 'tabs', component: TabsComponent,
|
path: '',
|
||||||
|
redirectTo: 'home',
|
||||||
|
pathMatch: 'full',
|
||||||
|
},
|
||||||
|
{
|
||||||
|
path: 'vault',
|
||||||
|
redirectTo: '/tabs/vault',
|
||||||
|
pathMatch: 'full',
|
||||||
|
},
|
||||||
|
{
|
||||||
|
path: 'home',
|
||||||
|
component: HomeComponent,
|
||||||
|
canActivate: [LaunchGuardService],
|
||||||
|
data: { state: 'home' },
|
||||||
|
},
|
||||||
|
{
|
||||||
|
path: 'login',
|
||||||
|
component: LoginComponent,
|
||||||
|
canActivate: [LaunchGuardService],
|
||||||
|
data: { state: 'login' },
|
||||||
|
},
|
||||||
|
{
|
||||||
|
path: 'lock',
|
||||||
|
component: LockComponent,
|
||||||
|
data: { state: 'lock' },
|
||||||
|
},
|
||||||
|
{
|
||||||
|
path: '2fa',
|
||||||
|
component: TwoFactorComponent,
|
||||||
|
canActivate: [LaunchGuardService],
|
||||||
|
data: { state: '2fa' },
|
||||||
|
},
|
||||||
|
{
|
||||||
|
path: '2fa-options',
|
||||||
|
component: TwoFactorOptionsComponent,
|
||||||
|
canActivate: [LaunchGuardService],
|
||||||
|
data: { state: '2fa-options' },
|
||||||
|
},
|
||||||
|
{
|
||||||
|
path: 'register',
|
||||||
|
component: RegisterComponent,
|
||||||
|
canActivate: [LaunchGuardService],
|
||||||
|
data: { state: 'register' },
|
||||||
|
},
|
||||||
|
{
|
||||||
|
path: 'hint',
|
||||||
|
component: HintComponent,
|
||||||
|
canActivate: [LaunchGuardService],
|
||||||
|
data: { state: 'hint' },
|
||||||
|
},
|
||||||
|
{
|
||||||
|
path: 'environment',
|
||||||
|
component: EnvironmentComponent,
|
||||||
|
canActivate: [LaunchGuardService],
|
||||||
|
data: { state: 'environment' },
|
||||||
|
},
|
||||||
|
{
|
||||||
|
path: 'ciphers',
|
||||||
|
component: CiphersComponent,
|
||||||
|
canActivate: [AuthGuardService],
|
||||||
|
data: { state: 'ciphers' },
|
||||||
|
},
|
||||||
|
{
|
||||||
|
path: 'view-cipher',
|
||||||
|
component: ViewComponent,
|
||||||
|
canActivate: [AuthGuardService],
|
||||||
|
data: { state: 'view-cipher' },
|
||||||
|
},
|
||||||
|
{
|
||||||
|
path: 'add-cipher',
|
||||||
|
component: AddEditComponent,
|
||||||
|
canActivate: [AuthGuardService],
|
||||||
|
data: { state: 'add-cipher' },
|
||||||
|
},
|
||||||
|
{
|
||||||
|
path: 'edit-cipher',
|
||||||
|
component: AddEditComponent,
|
||||||
|
canActivate: [AuthGuardService],
|
||||||
|
data: { state: 'edit-cipher' },
|
||||||
|
},
|
||||||
|
{
|
||||||
|
path: 'generator',
|
||||||
|
component: PasswordGeneratorComponent,
|
||||||
|
canActivate: [AuthGuardService],
|
||||||
|
data: { state: 'generator' },
|
||||||
|
},
|
||||||
|
{
|
||||||
|
path: 'generator-history',
|
||||||
|
component: PasswordGeneratorHistoryComponent,
|
||||||
|
canActivate: [AuthGuardService],
|
||||||
|
data: { state: 'generator-history' },
|
||||||
|
},
|
||||||
|
{
|
||||||
|
path: 'export',
|
||||||
|
component: ExportComponent,
|
||||||
|
canActivate: [AuthGuardService],
|
||||||
|
data: { state: 'export' },
|
||||||
|
},
|
||||||
|
{
|
||||||
|
path: 'tabs',
|
||||||
|
component: TabsComponent,
|
||||||
data: { state: 'tabs' },
|
data: { state: 'tabs' },
|
||||||
children: [
|
children: [
|
||||||
{ path: '', redirectTo: '/tabs/vault', pathMatch: 'full' },
|
{
|
||||||
|
path: '',
|
||||||
|
redirectTo: '/tabs/vault',
|
||||||
|
pathMatch: 'full',
|
||||||
|
},
|
||||||
{
|
{
|
||||||
path: 'current',
|
path: 'current',
|
||||||
component: CurrentTabComponent,
|
component: CurrentTabComponent,
|
||||||
|
|
|
@ -6,7 +6,9 @@ import { Angulartics2GoogleAnalytics } from 'angulartics2/ga';
|
||||||
import swal from 'sweetalert';
|
import swal from 'sweetalert';
|
||||||
|
|
||||||
import {
|
import {
|
||||||
|
ChangeDetectorRef,
|
||||||
Component,
|
Component,
|
||||||
|
NgZone,
|
||||||
OnInit,
|
OnInit,
|
||||||
} from '@angular/core';
|
} from '@angular/core';
|
||||||
import {
|
import {
|
||||||
|
@ -59,7 +61,8 @@ export class AppComponent implements OnInit {
|
||||||
private toasterService: ToasterService, private storageService: StorageService,
|
private toasterService: ToasterService, private storageService: StorageService,
|
||||||
private broadcasterService: BroadcasterService, private authService: AuthService,
|
private broadcasterService: BroadcasterService, private authService: AuthService,
|
||||||
private i18nService: I18nService, private router: Router,
|
private i18nService: I18nService, private router: Router,
|
||||||
private stateService: StateService, private messagingService: MessagingService) { }
|
private stateService: StateService, private messagingService: MessagingService,
|
||||||
|
private changeDetectorRef: ChangeDetectorRef, private ngZone: NgZone) { }
|
||||||
|
|
||||||
ngOnInit() {
|
ngOnInit() {
|
||||||
window.onmousemove = () => this.recordActivity();
|
window.onmousemove = () => this.recordActivity();
|
||||||
|
@ -71,6 +74,7 @@ export class AppComponent implements OnInit {
|
||||||
|
|
||||||
(window as any).bitwardenPopupMainMessageListener = async (msg: any, sender: any, sendResponse: any) => {
|
(window as any).bitwardenPopupMainMessageListener = async (msg: any, sender: any, sendResponse: any) => {
|
||||||
if (msg.command === 'doneLoggingOut') {
|
if (msg.command === 'doneLoggingOut') {
|
||||||
|
this.ngZone.run(async () => {
|
||||||
this.authService.logOut(() => {
|
this.authService.logOut(() => {
|
||||||
this.analytics.eventTrack.next({ action: 'Logged Out' });
|
this.analytics.eventTrack.next({ action: 'Logged Out' });
|
||||||
if (msg.expired) {
|
if (msg.expired) {
|
||||||
|
@ -79,6 +83,8 @@ export class AppComponent implements OnInit {
|
||||||
}
|
}
|
||||||
this.router.navigate(['home']);
|
this.router.navigate(['home']);
|
||||||
});
|
});
|
||||||
|
this.changeDetectorRef.detectChanges();
|
||||||
|
});
|
||||||
} else if (msg.command === 'showDialog') {
|
} else if (msg.command === 'showDialog') {
|
||||||
const buttons = [msg.confirmText == null ? this.i18nService.t('ok') : msg.confirmText];
|
const buttons = [msg.confirmText == null ? this.i18nService.t('ok') : msg.confirmText];
|
||||||
if (msg.cancelText != null) {
|
if (msg.cancelText != null) {
|
||||||
|
|
|
@ -0,0 +1,29 @@
|
||||||
|
import { Injectable } from '@angular/core';
|
||||||
|
import {
|
||||||
|
CanActivate,
|
||||||
|
Router,
|
||||||
|
} from '@angular/router';
|
||||||
|
|
||||||
|
import { CryptoService } from 'jslib/abstractions/crypto.service';
|
||||||
|
import { UserService } from 'jslib/abstractions/user.service';
|
||||||
|
|
||||||
|
@Injectable()
|
||||||
|
export class LaunchGuardService implements CanActivate {
|
||||||
|
constructor(private cryptoService: CryptoService, private userService: UserService, private router: Router) { }
|
||||||
|
|
||||||
|
async canActivate() {
|
||||||
|
const isAuthed = await this.userService.isAuthenticated();
|
||||||
|
if (!isAuthed) {
|
||||||
|
return true;
|
||||||
|
}
|
||||||
|
|
||||||
|
const key = await this.cryptoService.getKey();
|
||||||
|
if (key == null) {
|
||||||
|
this.router.navigate(['lock']);
|
||||||
|
} else {
|
||||||
|
this.router.navigate(['tabs/current']);
|
||||||
|
}
|
||||||
|
|
||||||
|
return false;
|
||||||
|
}
|
||||||
|
}
|
|
@ -5,6 +5,8 @@ import {
|
||||||
|
|
||||||
import { ToasterModule } from 'angular2-toaster';
|
import { ToasterModule } from 'angular2-toaster';
|
||||||
|
|
||||||
|
import { LaunchGuardService } from './launch-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 { ValidationService } from 'jslib/angular/services/validation.service';
|
import { ValidationService } from 'jslib/angular/services/validation.service';
|
||||||
|
@ -87,6 +89,7 @@ export function initFactory(i18nService: I18nService, storageService: StorageSer
|
||||||
providers: [
|
providers: [
|
||||||
ValidationService,
|
ValidationService,
|
||||||
AuthGuardService,
|
AuthGuardService,
|
||||||
|
LaunchGuardService,
|
||||||
PopupUtilsService,
|
PopupUtilsService,
|
||||||
BroadcasterService,
|
BroadcasterService,
|
||||||
{ provide: MessagingService, useValue: messagingService },
|
{ provide: MessagingService, useValue: messagingService },
|
||||||
|
|
Loading…
Reference in New Issue