1
0
mirror of https://github.com/bitwarden/browser synced 2025-12-17 16:53:34 +00:00

Split jslib into multiple modules (#363)

* Split jslib into multiple modules
This commit is contained in:
Oscar Hinton
2021-06-03 18:58:57 +02:00
committed by GitHub
parent b1d9b84eae
commit 1016bbfb9e
509 changed files with 8838 additions and 1887 deletions

View File

@@ -0,0 +1,36 @@
import { Injectable } from '@angular/core';
import {
ActivatedRouteSnapshot,
CanActivate,
Router,
RouterStateSnapshot,
} from '@angular/router';
import { MessagingService } from 'jslib-common/abstractions/messaging.service';
import { UserService } from 'jslib-common/abstractions/user.service';
import { VaultTimeoutService } from 'jslib-common/abstractions/vaultTimeout.service';
@Injectable()
export class AuthGuardService implements CanActivate {
constructor(private vaultTimeoutService: VaultTimeoutService, private userService: UserService,
private router: Router, private messagingService: MessagingService) { }
async canActivate(route: ActivatedRouteSnapshot, routerState: RouterStateSnapshot) {
const isAuthed = await this.userService.isAuthenticated();
if (!isAuthed) {
this.messagingService.send('authBlocked');
return false;
}
const locked = await this.vaultTimeoutService.isLocked();
if (locked) {
if (routerState != null) {
this.messagingService.send('lockedUrl', { url: routerState.url });
}
this.router.navigate(['lock'], { queryParams: { promptBiometric: true }});
return false;
}
return true;
}
}

View File

@@ -0,0 +1,7 @@
import { Injectable } from '@angular/core';
import { BroadcasterService as BaseBroadcasterService } from 'jslib-common/services/broadcaster.service';
@Injectable()
export class BroadcasterService extends BaseBroadcasterService {
}

View File

@@ -0,0 +1,30 @@
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 LockGuardService implements CanActivate {
constructor(private vaultTimeoutService: VaultTimeoutService, private userService: UserService,
private router: Router) { }
async canActivate() {
const isAuthed = await this.userService.isAuthenticated();
if (isAuthed) {
const locked = await this.vaultTimeoutService.isLocked();
if (locked) {
return true;
} else {
this.router.navigate(['vault']);
return false;
}
}
this.router.navigate(['']);
return false;
}
}

View File

@@ -0,0 +1,29 @@
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 UnauthGuardService implements CanActivate {
constructor(private vaultTimeoutService: VaultTimeoutService, private userService: UserService,
private router: Router) { }
async canActivate() {
const isAuthed = await this.userService.isAuthenticated();
if (isAuthed) {
const locked = await this.vaultTimeoutService.isLocked();
if (locked) {
this.router.navigate(['lock']);
} else {
this.router.navigate(['vault']);
}
return false;
}
return true;
}
}

View File

@@ -0,0 +1,36 @@
import { Injectable } from '@angular/core';
import { I18nService } from 'jslib-common/abstractions/i18n.service';
import { PlatformUtilsService } from 'jslib-common/abstractions/platformUtils.service';
import { ErrorResponse } from 'jslib-common/models/response/errorResponse';
@Injectable()
export class ValidationService {
constructor(private i18nService: I18nService, private platformUtilsService: PlatformUtilsService) { }
showError(data: any): string[] {
const defaultErrorMessage = this.i18nService.t('unexpectedError');
let errors: string[] = [];
if (data != null && typeof data === 'string') {
errors.push(data);
} else if (data == null || typeof data !== 'object') {
errors.push(defaultErrorMessage);
} else if (data.validationErrors != null) {
errors = errors.concat((data as ErrorResponse).getAllMessages());
} else {
errors.push(data.message ? data.message : defaultErrorMessage);
}
if (errors.length === 1) {
this.platformUtilsService.showToast('error', this.i18nService.t('errorOccurred'), errors[0]);
} else if (errors.length > 1) {
this.platformUtilsService.showToast('error', this.i18nService.t('errorOccurred'), errors, {
timeout: 5000 * errors.length,
});
}
return errors;
}
}