1
0
mirror of https://github.com/bitwarden/browser synced 2025-12-16 08:13:42 +00:00

refactor toaster to platform showToast

This commit is contained in:
Kyle Spearrin
2018-10-02 23:09:19 -04:00
parent 45341ec408
commit f793ff0aa5
21 changed files with 85 additions and 117 deletions

5
package-lock.json generated
View File

@@ -229,11 +229,6 @@
"integrity": "sha1-SlKCrBZHKek2Gbz9OtFR+BfOkfU=", "integrity": "sha1-SlKCrBZHKek2Gbz9OtFR+BfOkfU=",
"dev": true "dev": true
}, },
"angular2-toaster": {
"version": "6.1.0",
"resolved": "https://registry.npmjs.org/angular2-toaster/-/angular2-toaster-6.1.0.tgz",
"integrity": "sha512-++CtP7Xx3zNG1U+1nlop8rfA0nqkKqEhKGCtdcT2dB+CTQKkSOod5A6TMdTOZbdm/edaAzT8E0fHt9RrPRTDbA=="
},
"angulartics2": { "angulartics2": {
"version": "6.3.0", "version": "6.3.0",
"resolved": "https://registry.npmjs.org/angulartics2/-/angulartics2-6.3.0.tgz", "resolved": "https://registry.npmjs.org/angulartics2/-/angulartics2-6.3.0.tgz",

View File

@@ -69,7 +69,6 @@
"@angular/upgrade": "6.1.7", "@angular/upgrade": "6.1.7",
"@aspnet/signalr": "1.0.3", "@aspnet/signalr": "1.0.3",
"@aspnet/signalr-protocol-msgpack": "1.0.3", "@aspnet/signalr-protocol-msgpack": "1.0.3",
"angular2-toaster": "6.1.0",
"angulartics2": "6.3.0", "angulartics2": "6.3.0",
"core-js": "2.5.7", "core-js": "2.5.7",
"electron-log": "2.2.14", "electron-log": "2.2.14",

View File

@@ -21,7 +21,8 @@ export abstract class PlatformUtilsService {
getApplicationVersion: () => string; getApplicationVersion: () => string;
supportsU2f: (win: Window) => boolean; supportsU2f: (win: Window) => boolean;
supportsDuo: () => boolean; supportsDuo: () => boolean;
showToast: (type: 'error' | 'success' | 'warning' | 'info', title: string, text: string) => void; showToast: (type: 'error' | 'success' | 'warning' | 'info', title: string, text: string | string[],
options?: any) => void;
showDialog: (text: string, title?: string, confirmText?: string, cancelText?: string, showDialog: (text: string, title?: string, confirmText?: string, cancelText?: string,
type?: string) => Promise<boolean>; type?: string) => Promise<boolean>;
isDev: () => boolean; isDev: () => boolean;

View File

@@ -4,7 +4,6 @@ import {
Output, Output,
} from '@angular/core'; } from '@angular/core';
import { ToasterService } from 'angular2-toaster';
import { Angulartics2 } from 'angulartics2'; import { Angulartics2 } from 'angulartics2';
import { CipherType } from '../../enums/cipherType'; import { CipherType } from '../../enums/cipherType';
@@ -61,7 +60,7 @@ export class AddEditComponent {
constructor(protected cipherService: CipherService, protected folderService: FolderService, constructor(protected cipherService: CipherService, protected folderService: FolderService,
protected i18nService: I18nService, protected platformUtilsService: PlatformUtilsService, protected i18nService: I18nService, protected platformUtilsService: PlatformUtilsService,
protected analytics: Angulartics2, protected toasterService: ToasterService, protected analytics: Angulartics2,
protected auditService: AuditService, protected stateService: StateService) { protected auditService: AuditService, protected stateService: StateService) {
this.typeOptions = [ this.typeOptions = [
{ name: i18nService.t('typeLogin'), value: CipherType.Login }, { name: i18nService.t('typeLogin'), value: CipherType.Login },
@@ -152,7 +151,7 @@ export class AddEditComponent {
async submit(): Promise<boolean> { async submit(): Promise<boolean> {
if (this.cipher.name == null || this.cipher.name === '') { if (this.cipher.name == null || this.cipher.name === '') {
this.toasterService.popAsync('error', this.i18nService.t('errorOccurred'), this.platformUtilsService.showToast('error', this.i18nService.t('errorOccurred'),
this.i18nService.t('nameRequired')); this.i18nService.t('nameRequired'));
return false; return false;
} }
@@ -169,7 +168,7 @@ export class AddEditComponent {
await this.formPromise; await this.formPromise;
this.cipher.id = cipher.id; this.cipher.id = cipher.id;
this.analytics.eventTrack.next({ action: this.editMode ? 'Edited Cipher' : 'Added Cipher' }); this.analytics.eventTrack.next({ action: this.editMode ? 'Edited Cipher' : 'Added Cipher' });
this.toasterService.popAsync('success', null, this.platformUtilsService.showToast('success', null,
this.i18nService.t(this.editMode ? 'editedItem' : 'addedItem')); this.i18nService.t(this.editMode ? 'editedItem' : 'addedItem'));
this.onSavedCipher.emit(this.cipher); this.onSavedCipher.emit(this.cipher);
return true; return true;
@@ -238,7 +237,7 @@ export class AddEditComponent {
this.deletePromise = this.deleteCipher(); this.deletePromise = this.deleteCipher();
await this.deletePromise; await this.deletePromise;
this.analytics.eventTrack.next({ action: 'Deleted Cipher' }); this.analytics.eventTrack.next({ action: 'Deleted Cipher' });
this.toasterService.popAsync('success', null, this.i18nService.t('deletedItem')); this.platformUtilsService.showToast('success', null, this.i18nService.t('deletedItem'));
this.onDeletedCipher.emit(this.cipher); this.onDeletedCipher.emit(this.cipher);
} catch { } } catch { }
@@ -301,9 +300,10 @@ export class AddEditComponent {
this.checkPasswordPromise = null; this.checkPasswordPromise = null;
if (matches > 0) { if (matches > 0) {
this.toasterService.popAsync('warning', null, this.i18nService.t('passwordExposed', matches.toString())); this.platformUtilsService.showToast('warning', null,
this.i18nService.t('passwordExposed', matches.toString()));
} else { } else {
this.toasterService.popAsync('success', null, this.i18nService.t('passwordSafe')); this.platformUtilsService.showToast('success', null, this.i18nService.t('passwordSafe'));
} }
} }

View File

@@ -5,7 +5,6 @@ import {
Output, Output,
} from '@angular/core'; } from '@angular/core';
import { ToasterService } from 'angular2-toaster';
import { Angulartics2 } from 'angulartics2'; import { Angulartics2 } from 'angulartics2';
import { CipherService } from '../../abstractions/cipher.service'; import { CipherService } from '../../abstractions/cipher.service';
@@ -32,7 +31,7 @@ export class AttachmentsComponent implements OnInit {
deletePromises: { [id: string]: Promise<any>; } = {}; deletePromises: { [id: string]: Promise<any>; } = {};
constructor(protected cipherService: CipherService, protected analytics: Angulartics2, constructor(protected cipherService: CipherService, protected analytics: Angulartics2,
protected toasterService: ToasterService, protected i18nService: I18nService, protected i18nService: I18nService,
protected cryptoService: CryptoService, protected userService: UserService, protected cryptoService: CryptoService, protected userService: UserService,
protected platformUtilsService: PlatformUtilsService, protected win: Window) { } protected platformUtilsService: PlatformUtilsService, protected win: Window) { }
@@ -63,7 +62,7 @@ export class AttachmentsComponent implements OnInit {
async submit() { async submit() {
if (!this.hasUpdatedKey) { if (!this.hasUpdatedKey) {
this.toasterService.popAsync('error', this.i18nService.t('errorOccurred'), this.platformUtilsService.showToast('error', this.i18nService.t('errorOccurred'),
this.i18nService.t('updateKey')); this.i18nService.t('updateKey'));
return; return;
} }
@@ -71,13 +70,13 @@ export class AttachmentsComponent implements OnInit {
const fileEl = document.getElementById('file') as HTMLInputElement; const fileEl = document.getElementById('file') as HTMLInputElement;
const files = fileEl.files; const files = fileEl.files;
if (files == null || files.length === 0) { if (files == null || files.length === 0) {
this.toasterService.popAsync('error', this.i18nService.t('errorOccurred'), this.platformUtilsService.showToast('error', this.i18nService.t('errorOccurred'),
this.i18nService.t('selectFile')); this.i18nService.t('selectFile'));
return; return;
} }
if (files[0].size > 104857600) { // 100 MB if (files[0].size > 104857600) { // 100 MB
this.toasterService.popAsync('error', this.i18nService.t('errorOccurred'), this.platformUtilsService.showToast('error', this.i18nService.t('errorOccurred'),
this.i18nService.t('maxFileSize')); this.i18nService.t('maxFileSize'));
return; return;
} }
@@ -87,7 +86,7 @@ export class AttachmentsComponent implements OnInit {
this.cipherDomain = await this.formPromise; this.cipherDomain = await this.formPromise;
this.cipher = await this.cipherDomain.decrypt(); this.cipher = await this.cipherDomain.decrypt();
this.analytics.eventTrack.next({ action: 'Added Attachment' }); this.analytics.eventTrack.next({ action: 'Added Attachment' });
this.toasterService.popAsync('success', null, this.i18nService.t('attachmentSaved')); this.platformUtilsService.showToast('success', null, this.i18nService.t('attachmentSaved'));
this.onUploadedAttachment.emit(); this.onUploadedAttachment.emit();
} catch { } } catch { }
@@ -114,7 +113,7 @@ export class AttachmentsComponent implements OnInit {
this.deletePromises[attachment.id] = this.deleteCipherAttachment(attachment.id); this.deletePromises[attachment.id] = this.deleteCipherAttachment(attachment.id);
await this.deletePromises[attachment.id]; await this.deletePromises[attachment.id];
this.analytics.eventTrack.next({ action: 'Deleted Attachment' }); this.analytics.eventTrack.next({ action: 'Deleted Attachment' });
this.toasterService.popAsync('success', null, this.i18nService.t('deletedAttachment')); this.platformUtilsService.showToast('success', null, this.i18nService.t('deletedAttachment'));
const i = this.cipher.attachments.indexOf(attachment); const i = this.cipher.attachments.indexOf(attachment);
if (i > -1) { if (i > -1) {
this.cipher.attachments.splice(i, 1); this.cipher.attachments.splice(i, 1);
@@ -132,7 +131,7 @@ export class AttachmentsComponent implements OnInit {
} }
if (!this.canAccessAttachments) { if (!this.canAccessAttachments) {
this.toasterService.popAsync('error', this.i18nService.t('premiumRequired'), this.platformUtilsService.showToast('error', this.i18nService.t('premiumRequired'),
this.i18nService.t('premiumRequiredDesc')); this.i18nService.t('premiumRequiredDesc'));
return; return;
} }
@@ -140,7 +139,7 @@ export class AttachmentsComponent implements OnInit {
a.downloading = true; a.downloading = true;
const response = await fetch(new Request(attachment.url, { cache: 'no-cache' })); const response = await fetch(new Request(attachment.url, { cache: 'no-cache' }));
if (response.status !== 200) { if (response.status !== 200) {
this.toasterService.popAsync('error', null, this.i18nService.t('errorOccurred')); this.platformUtilsService.showToast('error', null, this.i18nService.t('errorOccurred'));
a.downloading = false; a.downloading = false;
return; return;
} }
@@ -151,7 +150,7 @@ export class AttachmentsComponent implements OnInit {
const decBuf = await this.cryptoService.decryptFromBytes(buf, key); const decBuf = await this.cryptoService.decryptFromBytes(buf, key);
this.platformUtilsService.saveFile(this.win, decBuf, null, attachment.fileName); this.platformUtilsService.saveFile(this.win, decBuf, null, attachment.fileName);
} catch (e) { } catch (e) {
this.toasterService.popAsync('error', null, this.i18nService.t('errorOccurred')); this.platformUtilsService.showToast('error', null, this.i18nService.t('errorOccurred'));
} }
a.downloading = false; a.downloading = false;

View File

@@ -3,11 +3,11 @@ import {
Output, Output,
} from '@angular/core'; } from '@angular/core';
import { ToasterService } from 'angular2-toaster';
import { Angulartics2 } from 'angulartics2'; import { Angulartics2 } from 'angulartics2';
import { EnvironmentService } from '../../abstractions/environment.service'; import { EnvironmentService } from '../../abstractions/environment.service';
import { I18nService } from '../../abstractions/i18n.service'; import { I18nService } from '../../abstractions/i18n.service';
import { PlatformUtilsService } from '../../abstractions/platformUtils.service';
export class EnvironmentComponent { export class EnvironmentComponent {
@Output() onSaved = new EventEmitter(); @Output() onSaved = new EventEmitter();
@@ -20,7 +20,7 @@ export class EnvironmentComponent {
baseUrl: string; baseUrl: string;
showCustom = false; showCustom = false;
constructor(protected analytics: Angulartics2, protected toasterService: ToasterService, constructor(protected analytics: Angulartics2, protected platformUtilsService: PlatformUtilsService,
protected environmentService: EnvironmentService, protected i18nService: I18nService) { protected environmentService: EnvironmentService, protected i18nService: I18nService) {
this.baseUrl = environmentService.baseUrl || ''; this.baseUrl = environmentService.baseUrl || '';
this.webVaultUrl = environmentService.webVaultUrl || ''; this.webVaultUrl = environmentService.webVaultUrl || '';
@@ -49,7 +49,7 @@ export class EnvironmentComponent {
this.notificationsUrl = resUrls.notifications; this.notificationsUrl = resUrls.notifications;
this.analytics.eventTrack.next({ action: 'Set Environment URLs' }); this.analytics.eventTrack.next({ action: 'Set Environment URLs' });
this.toasterService.popAsync('success', null, this.i18nService.t('environmentSaved')); this.platformUtilsService.showToast('success', null, this.i18nService.t('environmentSaved'));
this.saved(); this.saved();
} }

View File

@@ -1,4 +1,3 @@
import { ToasterService } from 'angular2-toaster';
import { Angulartics2 } from 'angulartics2'; import { Angulartics2 } from 'angulartics2';
import { import {
@@ -18,14 +17,14 @@ export class ExportComponent {
masterPassword: string; masterPassword: string;
showPassword = false; showPassword = false;
constructor(protected analytics: Angulartics2, protected toasterService: ToasterService, constructor(protected analytics: Angulartics2,
protected cryptoService: CryptoService, protected i18nService: I18nService, protected cryptoService: CryptoService, protected i18nService: I18nService,
protected platformUtilsService: PlatformUtilsService, protected exportService: ExportService, protected platformUtilsService: PlatformUtilsService, protected exportService: ExportService,
protected win: Window) { } protected win: Window) { }
async submit() { async submit() {
if (this.masterPassword == null || this.masterPassword === '') { if (this.masterPassword == null || this.masterPassword === '') {
this.toasterService.popAsync('error', this.i18nService.t('errorOccurred'), this.platformUtilsService.showToast('error', this.i18nService.t('errorOccurred'),
this.i18nService.t('invalidMasterPassword')); this.i18nService.t('invalidMasterPassword'));
return; return;
} }
@@ -41,7 +40,7 @@ export class ExportComponent {
this.saved(); this.saved();
} catch { } } catch { }
} else { } else {
this.toasterService.popAsync('error', this.i18nService.t('errorOccurred'), this.platformUtilsService.showToast('error', this.i18nService.t('errorOccurred'),
this.i18nService.t('invalidMasterPassword')); this.i18nService.t('invalidMasterPassword'));
} }
} }

View File

@@ -5,7 +5,6 @@ import {
Output, Output,
} from '@angular/core'; } from '@angular/core';
import { ToasterService } from 'angular2-toaster';
import { Angulartics2 } from 'angulartics2'; import { Angulartics2 } from 'angulartics2';
import { FolderService } from '../../abstractions/folder.service'; import { FolderService } from '../../abstractions/folder.service';
@@ -26,8 +25,7 @@ export class FolderAddEditComponent implements OnInit {
deletePromise: Promise<any>; deletePromise: Promise<any>;
constructor(protected folderService: FolderService, protected i18nService: I18nService, constructor(protected folderService: FolderService, protected i18nService: I18nService,
protected analytics: Angulartics2, protected toasterService: ToasterService, protected analytics: Angulartics2, protected platformUtilsService: PlatformUtilsService) { }
protected platformUtilsService: PlatformUtilsService) { }
async ngOnInit() { async ngOnInit() {
this.editMode = this.folderId != null; this.editMode = this.folderId != null;
@@ -44,7 +42,7 @@ export class FolderAddEditComponent implements OnInit {
async submit(): Promise<boolean> { async submit(): Promise<boolean> {
if (this.folder.name == null || this.folder.name === '') { if (this.folder.name == null || this.folder.name === '') {
this.toasterService.popAsync('error', this.i18nService.t('errorOccurred'), this.platformUtilsService.showToast('error', this.i18nService.t('errorOccurred'),
this.i18nService.t('nameRequired')); this.i18nService.t('nameRequired'));
return false; return false;
} }
@@ -54,7 +52,7 @@ export class FolderAddEditComponent implements OnInit {
this.formPromise = this.folderService.saveWithServer(folder); this.formPromise = this.folderService.saveWithServer(folder);
await this.formPromise; await this.formPromise;
this.analytics.eventTrack.next({ action: this.editMode ? 'Edited Folder' : 'Added Folder' }); this.analytics.eventTrack.next({ action: this.editMode ? 'Edited Folder' : 'Added Folder' });
this.toasterService.popAsync('success', null, this.platformUtilsService.showToast('success', null,
this.i18nService.t(this.editMode ? 'editedFolder' : 'addedFolder')); this.i18nService.t(this.editMode ? 'editedFolder' : 'addedFolder'));
this.onSavedFolder.emit(this.folder); this.onSavedFolder.emit(this.folder);
return true; return true;
@@ -75,7 +73,7 @@ export class FolderAddEditComponent implements OnInit {
this.deletePromise = this.folderService.deleteWithServer(this.folder.id); this.deletePromise = this.folderService.deleteWithServer(this.folder.id);
await this.deletePromise; await this.deletePromise;
this.analytics.eventTrack.next({ action: 'Deleted Folder' }); this.analytics.eventTrack.next({ action: 'Deleted Folder' });
this.toasterService.popAsync('success', null, this.i18nService.t('deletedFolder')); this.platformUtilsService.showToast('success', null, this.i18nService.t('deletedFolder'));
this.onDeletedFolder.emit(this.folder); this.onDeletedFolder.emit(this.folder);
} catch { } } catch { }

View File

@@ -1,12 +1,12 @@
import { Router } from '@angular/router'; import { Router } from '@angular/router';
import { ToasterService } from 'angular2-toaster';
import { Angulartics2 } from 'angulartics2'; import { Angulartics2 } from 'angulartics2';
import { PasswordHintRequest } from '../../models/request/passwordHintRequest'; import { PasswordHintRequest } from '../../models/request/passwordHintRequest';
import { ApiService } from '../../abstractions/api.service'; import { ApiService } from '../../abstractions/api.service';
import { I18nService } from '../../abstractions/i18n.service'; import { I18nService } from '../../abstractions/i18n.service';
import { PlatformUtilsService } from '../../abstractions/platformUtils.service';
export class HintComponent { export class HintComponent {
email: string = ''; email: string = '';
@@ -15,17 +15,17 @@ export class HintComponent {
protected successRoute = 'login'; protected successRoute = 'login';
constructor(protected router: Router, protected analytics: Angulartics2, constructor(protected router: Router, protected analytics: Angulartics2,
protected toasterService: ToasterService, protected i18nService: I18nService, protected i18nService: I18nService, protected apiService: ApiService,
protected apiService: ApiService) { } protected platformUtilsService: PlatformUtilsService) { }
async submit() { async submit() {
if (this.email == null || this.email === '') { if (this.email == null || this.email === '') {
this.toasterService.popAsync('error', this.i18nService.t('errorOccurred'), this.platformUtilsService.showToast('error', this.i18nService.t('errorOccurred'),
this.i18nService.t('emailRequired')); this.i18nService.t('emailRequired'));
return; return;
} }
if (this.email.indexOf('@') === -1) { if (this.email.indexOf('@') === -1) {
this.toasterService.popAsync('error', this.i18nService.t('errorOccurred'), this.platformUtilsService.showToast('error', this.i18nService.t('errorOccurred'),
this.i18nService.t('invalidEmail')); this.i18nService.t('invalidEmail'));
return; return;
} }
@@ -34,7 +34,7 @@ export class HintComponent {
this.formPromise = this.apiService.postPasswordHint(new PasswordHintRequest(this.email)); this.formPromise = this.apiService.postPasswordHint(new PasswordHintRequest(this.email));
await this.formPromise; await this.formPromise;
this.analytics.eventTrack.next({ action: 'Requested Hint' }); this.analytics.eventTrack.next({ action: 'Requested Hint' });
this.toasterService.popAsync('success', null, this.i18nService.t('masterPassSent')); this.platformUtilsService.showToast('success', null, this.i18nService.t('masterPassSent'));
this.router.navigate([this.successRoute]); this.router.navigate([this.successRoute]);
} catch { } } catch { }
} }

View File

@@ -1,6 +1,5 @@
import { Router } from '@angular/router'; import { Router } from '@angular/router';
import { ToasterService } from 'angular2-toaster';
import { Angulartics2 } from 'angulartics2'; import { Angulartics2 } from 'angulartics2';
import { CryptoService } from '../../abstractions/crypto.service'; import { CryptoService } from '../../abstractions/crypto.service';
@@ -16,13 +15,13 @@ export class LockComponent {
protected successRoute: string = 'vault'; protected successRoute: string = 'vault';
constructor(protected router: Router, protected analytics: Angulartics2, constructor(protected router: Router, protected analytics: Angulartics2,
protected toasterService: ToasterService, protected i18nService: I18nService, protected i18nService: I18nService,
protected platformUtilsService: PlatformUtilsService, protected messagingService: MessagingService, protected platformUtilsService: PlatformUtilsService, protected messagingService: MessagingService,
protected userService: UserService, protected cryptoService: CryptoService) { } protected userService: UserService, protected cryptoService: CryptoService) { }
async submit() { async submit() {
if (this.masterPassword == null || this.masterPassword === '') { if (this.masterPassword == null || this.masterPassword === '') {
this.toasterService.popAsync('error', this.i18nService.t('errorOccurred'), this.platformUtilsService.showToast('error', this.i18nService.t('errorOccurred'),
this.i18nService.t('masterPassRequired')); this.i18nService.t('masterPassRequired'));
return; return;
} }
@@ -39,7 +38,7 @@ export class LockComponent {
this.messagingService.send('unlocked'); this.messagingService.send('unlocked');
this.router.navigate([this.successRoute]); this.router.navigate([this.successRoute]);
} else { } else {
this.toasterService.popAsync('error', this.i18nService.t('errorOccurred'), this.platformUtilsService.showToast('error', this.i18nService.t('errorOccurred'),
this.i18nService.t('invalidMasterPassword')); this.i18nService.t('invalidMasterPassword'));
} }
} }

View File

@@ -4,13 +4,13 @@ import {
} from '@angular/core'; } from '@angular/core';
import { Router } from '@angular/router'; import { Router } from '@angular/router';
import { ToasterService } from 'angular2-toaster';
import { Angulartics2 } from 'angulartics2'; import { Angulartics2 } from 'angulartics2';
import { AuthResult } from '../../models/domain/authResult'; import { AuthResult } from '../../models/domain/authResult';
import { AuthService } from '../../abstractions/auth.service'; import { AuthService } from '../../abstractions/auth.service';
import { I18nService } from '../../abstractions/i18n.service'; import { I18nService } from '../../abstractions/i18n.service';
import { PlatformUtilsService } from '../../abstractions/platformUtils.service';
import { StorageService } from '../../abstractions/storage.service'; import { StorageService } from '../../abstractions/storage.service';
import { Utils } from '../../misc/utils'; import { Utils } from '../../misc/utils';
@@ -34,7 +34,7 @@ export class LoginComponent implements OnInit {
protected successRoute = 'vault'; protected successRoute = 'vault';
constructor(protected authService: AuthService, protected router: Router, constructor(protected authService: AuthService, protected router: Router,
protected analytics: Angulartics2, protected toasterService: ToasterService, protected analytics: Angulartics2, protected platformUtilsService: PlatformUtilsService,
protected i18nService: I18nService, private storageService: StorageService) { } protected i18nService: I18nService, private storageService: StorageService) { }
async ngOnInit() { async ngOnInit() {
@@ -55,17 +55,17 @@ export class LoginComponent implements OnInit {
async submit() { async submit() {
if (this.email == null || this.email === '') { if (this.email == null || this.email === '') {
this.toasterService.popAsync('error', this.i18nService.t('errorOccurred'), this.platformUtilsService.showToast('error', this.i18nService.t('errorOccurred'),
this.i18nService.t('emailRequired')); this.i18nService.t('emailRequired'));
return; return;
} }
if (this.email.indexOf('@') === -1) { if (this.email.indexOf('@') === -1) {
this.toasterService.popAsync('error', this.i18nService.t('errorOccurred'), this.platformUtilsService.showToast('error', this.i18nService.t('errorOccurred'),
this.i18nService.t('invalidEmail')); this.i18nService.t('invalidEmail'));
return; return;
} }
if (this.masterPassword == null || this.masterPassword === '') { if (this.masterPassword == null || this.masterPassword === '') {
this.toasterService.popAsync('error', this.i18nService.t('errorOccurred'), this.platformUtilsService.showToast('error', this.i18nService.t('errorOccurred'),
this.i18nService.t('masterPassRequired')); this.i18nService.t('masterPassRequired'));
return; return;
} }

View File

@@ -1,4 +1,3 @@
import { ToasterService } from 'angular2-toaster';
import { Angulartics2 } from 'angulartics2'; import { Angulartics2 } from 'angulartics2';
import { OnInit } from '@angular/core'; import { OnInit } from '@angular/core';
@@ -14,7 +13,7 @@ export class PasswordGeneratorHistoryComponent implements OnInit {
constructor(protected passwordGenerationService: PasswordGenerationService, protected analytics: Angulartics2, constructor(protected passwordGenerationService: PasswordGenerationService, protected analytics: Angulartics2,
protected platformUtilsService: PlatformUtilsService, protected i18nService: I18nService, protected platformUtilsService: PlatformUtilsService, protected i18nService: I18nService,
protected toasterService: ToasterService, private win: Window) { } private win: Window) { }
async ngOnInit() { async ngOnInit() {
this.history = await this.passwordGenerationService.getHistory(); this.history = await this.passwordGenerationService.getHistory();
@@ -29,6 +28,7 @@ export class PasswordGeneratorHistoryComponent implements OnInit {
this.analytics.eventTrack.next({ action: 'Copied Historical Password' }); this.analytics.eventTrack.next({ action: 'Copied Historical Password' });
const copyOptions = this.win != null ? { window: this.win } : null; const copyOptions = this.win != null ? { window: this.win } : null;
this.platformUtilsService.copyToClipboard(password, copyOptions); this.platformUtilsService.copyToClipboard(password, copyOptions);
this.toasterService.popAsync('info', null, this.i18nService.t('valueCopied', this.i18nService.t('password'))); this.platformUtilsService.showToast('info', null,
this.i18nService.t('valueCopied', this.i18nService.t('password')));
} }
} }

View File

@@ -1,4 +1,3 @@
import { ToasterService } from 'angular2-toaster';
import { Angulartics2 } from 'angulartics2'; import { Angulartics2 } from 'angulartics2';
import { import {
@@ -23,7 +22,7 @@ export class PasswordGeneratorComponent implements OnInit {
constructor(protected passwordGenerationService: PasswordGenerationService, protected analytics: Angulartics2, constructor(protected passwordGenerationService: PasswordGenerationService, protected analytics: Angulartics2,
protected platformUtilsService: PlatformUtilsService, protected i18nService: I18nService, protected platformUtilsService: PlatformUtilsService, protected i18nService: I18nService,
protected toasterService: ToasterService, private win: Window) { } private win: Window) { }
async ngOnInit() { async ngOnInit() {
this.options = await this.passwordGenerationService.getOptions(); this.options = await this.passwordGenerationService.getOptions();
@@ -63,7 +62,8 @@ export class PasswordGeneratorComponent implements OnInit {
this.analytics.eventTrack.next({ action: 'Copied Generated Password' }); this.analytics.eventTrack.next({ action: 'Copied Generated Password' });
const copyOptions = this.win != null ? { window: this.win } : null; const copyOptions = this.win != null ? { window: this.win } : null;
this.platformUtilsService.copyToClipboard(this.password, copyOptions); this.platformUtilsService.copyToClipboard(this.password, copyOptions);
this.toasterService.popAsync('info', null, this.i18nService.t('valueCopied', this.i18nService.t('password'))); this.platformUtilsService.showToast('info', null,
this.i18nService.t('valueCopied', this.i18nService.t('password')));
} }
select() { select() {

View File

@@ -1,4 +1,3 @@
import { ToasterService } from 'angular2-toaster';
import { Angulartics2 } from 'angulartics2'; import { Angulartics2 } from 'angulartics2';
import { OnInit } from '@angular/core'; import { OnInit } from '@angular/core';
@@ -15,7 +14,7 @@ export class PasswordHistoryComponent implements OnInit {
constructor(protected cipherService: CipherService, protected analytics: Angulartics2, constructor(protected cipherService: CipherService, protected analytics: Angulartics2,
protected platformUtilsService: PlatformUtilsService, protected i18nService: I18nService, protected platformUtilsService: PlatformUtilsService, protected i18nService: I18nService,
protected toasterService: ToasterService, private win: Window) { } private win: Window) { }
async ngOnInit() { async ngOnInit() {
const cipher = await this.cipherService.get(this.cipherId); const cipher = await this.cipherService.get(this.cipherId);
@@ -27,6 +26,7 @@ export class PasswordHistoryComponent implements OnInit {
this.analytics.eventTrack.next({ action: 'Copied Password History' }); this.analytics.eventTrack.next({ action: 'Copied Password History' });
const copyOptions = this.win != null ? { window: this.win } : null; const copyOptions = this.win != null ? { window: this.win } : null;
this.platformUtilsService.copyToClipboard(password, copyOptions); this.platformUtilsService.copyToClipboard(password, copyOptions);
this.toasterService.popAsync('info', null, this.i18nService.t('valueCopied', this.i18nService.t('password'))); this.platformUtilsService.showToast('info', null,
this.i18nService.t('valueCopied', this.i18nService.t('password')));
} }
} }

View File

@@ -1,6 +1,5 @@
import { OnInit } from '@angular/core'; import { OnInit } from '@angular/core';
import { ToasterService } from 'angular2-toaster';
import { Angulartics2 } from 'angulartics2'; import { Angulartics2 } from 'angulartics2';
import { ApiService } from '../../abstractions/api.service'; import { ApiService } from '../../abstractions/api.service';
@@ -13,7 +12,7 @@ export class PremiumComponent implements OnInit {
price: number = 10; price: number = 10;
refreshPromise: Promise<any>; refreshPromise: Promise<any>;
constructor(protected analytics: Angulartics2, protected toasterService: ToasterService, constructor(protected analytics: Angulartics2,
protected i18nService: I18nService, protected platformUtilsService: PlatformUtilsService, protected i18nService: I18nService, protected platformUtilsService: PlatformUtilsService,
protected tokenService: TokenService, protected apiService: ApiService) { } protected tokenService: TokenService, protected apiService: ApiService) { }
@@ -25,7 +24,7 @@ export class PremiumComponent implements OnInit {
try { try {
this.refreshPromise = this.apiService.refreshIdentityToken(); this.refreshPromise = this.apiService.refreshIdentityToken();
await this.refreshPromise; await this.refreshPromise;
this.toasterService.popAsync('success', null, this.i18nService.t('refreshComplete')); this.platformUtilsService.showToast('success', null, this.i18nService.t('refreshComplete'));
this.isPremium = this.tokenService.getPremium(); this.isPremium = this.tokenService.getPremium();
} catch { } } catch { }
} }

View File

@@ -1,6 +1,5 @@
import { Router } from '@angular/router'; import { Router } from '@angular/router';
import { ToasterService } from 'angular2-toaster';
import { Angulartics2 } from 'angulartics2'; import { Angulartics2 } from 'angulartics2';
import { KeysRequest } from '../../models/request/keysRequest'; import { KeysRequest } from '../../models/request/keysRequest';
@@ -27,34 +26,34 @@ export class RegisterComponent {
protected successRoute = 'login'; protected successRoute = 'login';
constructor(protected authService: AuthService, protected router: Router, constructor(protected authService: AuthService, protected router: Router,
protected analytics: Angulartics2, protected toasterService: ToasterService, protected analytics: Angulartics2,
protected i18nService: I18nService, protected cryptoService: CryptoService, protected i18nService: I18nService, protected cryptoService: CryptoService,
protected apiService: ApiService, protected stateService: StateService, protected apiService: ApiService, protected stateService: StateService,
protected platformUtilsService: PlatformUtilsService) { } protected platformUtilsService: PlatformUtilsService) { }
async submit() { async submit() {
if (this.email == null || this.email === '') { if (this.email == null || this.email === '') {
this.toasterService.popAsync('error', this.i18nService.t('errorOccurred'), this.platformUtilsService.showToast('error', this.i18nService.t('errorOccurred'),
this.i18nService.t('emailRequired')); this.i18nService.t('emailRequired'));
return; return;
} }
if (this.email.indexOf('@') === -1) { if (this.email.indexOf('@') === -1) {
this.toasterService.popAsync('error', this.i18nService.t('errorOccurred'), this.platformUtilsService.showToast('error', this.i18nService.t('errorOccurred'),
this.i18nService.t('invalidEmail')); this.i18nService.t('invalidEmail'));
return; return;
} }
if (this.masterPassword == null || this.masterPassword === '') { if (this.masterPassword == null || this.masterPassword === '') {
this.toasterService.popAsync('error', this.i18nService.t('errorOccurred'), this.platformUtilsService.showToast('error', this.i18nService.t('errorOccurred'),
this.i18nService.t('masterPassRequired')); this.i18nService.t('masterPassRequired'));
return; return;
} }
if (this.masterPassword.length < 8) { if (this.masterPassword.length < 8) {
this.toasterService.popAsync('error', this.i18nService.t('errorOccurred'), this.platformUtilsService.showToast('error', this.i18nService.t('errorOccurred'),
this.i18nService.t('masterPassLength')); this.i18nService.t('masterPassLength'));
return; return;
} }
if (this.masterPassword !== this.confirmMasterPassword) { if (this.masterPassword !== this.confirmMasterPassword) {
this.toasterService.popAsync('error', this.i18nService.t('errorOccurred'), this.platformUtilsService.showToast('error', this.i18nService.t('errorOccurred'),
this.i18nService.t('masterPassDoesntMatch')); this.i18nService.t('masterPassDoesntMatch'));
return; return;
} }
@@ -81,7 +80,7 @@ export class RegisterComponent {
this.formPromise = this.apiService.postRegister(request); this.formPromise = this.apiService.postRegister(request);
await this.formPromise; await this.formPromise;
this.analytics.eventTrack.next({ action: 'Registered' }); this.analytics.eventTrack.next({ action: 'Registered' });
this.toasterService.popAsync('success', null, this.i18nService.t('newAccountCreated')); this.platformUtilsService.showToast('success', null, this.i18nService.t('newAccountCreated'));
this.router.navigate([this.successRoute], { queryParams: { email: this.email } }); this.router.navigate([this.successRoute], { queryParams: { email: this.email } });
} catch { } } catch { }
} }

View File

@@ -6,7 +6,6 @@ import {
} from '@angular/core'; } from '@angular/core';
import { Router } from '@angular/router'; import { Router } from '@angular/router';
import { ToasterService } from 'angular2-toaster';
import { Angulartics2 } from 'angulartics2'; import { Angulartics2 } from 'angulartics2';
import { TwoFactorProviderType } from '../../enums/twoFactorProviderType'; import { TwoFactorProviderType } from '../../enums/twoFactorProviderType';
@@ -15,8 +14,6 @@ import { AuthService } from '../../abstractions/auth.service';
import { I18nService } from '../../abstractions/i18n.service'; import { I18nService } from '../../abstractions/i18n.service';
import { PlatformUtilsService } from '../../abstractions/platformUtils.service'; import { PlatformUtilsService } from '../../abstractions/platformUtils.service';
import { TwoFactorProviders } from '../../services/auth.service';
export class TwoFactorOptionsComponent implements OnInit { export class TwoFactorOptionsComponent implements OnInit {
@Output() onProviderSelected = new EventEmitter<TwoFactorProviderType>(); @Output() onProviderSelected = new EventEmitter<TwoFactorProviderType>();
@Output() onRecoverSelected = new EventEmitter(); @Output() onRecoverSelected = new EventEmitter();
@@ -24,7 +21,7 @@ export class TwoFactorOptionsComponent implements OnInit {
providers: any[] = []; providers: any[] = [];
constructor(protected authService: AuthService, protected router: Router, constructor(protected authService: AuthService, protected router: Router,
protected analytics: Angulartics2, protected toasterService: ToasterService, protected analytics: Angulartics2,
protected i18nService: I18nService, protected platformUtilsService: PlatformUtilsService, protected i18nService: I18nService, protected platformUtilsService: PlatformUtilsService,
protected win: Window) { } protected win: Window) { }

View File

@@ -4,7 +4,6 @@ import {
} from '@angular/core'; } from '@angular/core';
import { Router } from '@angular/router'; import { Router } from '@angular/router';
import { ToasterService } from 'angular2-toaster';
import { Angulartics2 } from 'angulartics2'; import { Angulartics2 } from 'angulartics2';
import { DeviceType } from '../../enums/deviceType'; import { DeviceType } from '../../enums/deviceType';
@@ -43,7 +42,7 @@ export class TwoFactorComponent implements OnInit, OnDestroy {
protected successRoute = 'vault'; protected successRoute = 'vault';
constructor(protected authService: AuthService, protected router: Router, constructor(protected authService: AuthService, protected router: Router,
protected analytics: Angulartics2, protected toasterService: ToasterService, protected analytics: Angulartics2,
protected i18nService: I18nService, protected apiService: ApiService, protected i18nService: I18nService, protected apiService: ApiService,
protected platformUtilsService: PlatformUtilsService, protected win: Window, protected platformUtilsService: PlatformUtilsService, protected win: Window,
protected environmentService: EnvironmentService) { protected environmentService: EnvironmentService) {
@@ -69,7 +68,7 @@ export class TwoFactorComponent implements OnInit, OnDestroy {
this.token = token; this.token = token;
this.submit(); this.submit();
}, (error: string) => { }, (error: string) => {
this.toasterService.popAsync('error', this.i18nService.t('errorOccurred'), error); this.platformUtilsService.showToast('error', this.i18nService.t('errorOccurred'), error);
}, (info: string) => { }, (info: string) => {
if (info === 'ready') { if (info === 'ready') {
this.u2fReady = true; this.u2fReady = true;
@@ -147,7 +146,7 @@ export class TwoFactorComponent implements OnInit, OnDestroy {
async submit() { async submit() {
if (this.token == null || this.token === '') { if (this.token == null || this.token === '') {
this.toasterService.popAsync('error', this.i18nService.t('errorOccurred'), this.platformUtilsService.showToast('error', this.i18nService.t('errorOccurred'),
this.i18nService.t('verificationCodeRequired')); this.i18nService.t('verificationCodeRequired'));
return; return;
} }
@@ -196,7 +195,7 @@ export class TwoFactorComponent implements OnInit, OnDestroy {
this.emailPromise = this.apiService.postTwoFactorEmail(request); this.emailPromise = this.apiService.postTwoFactorEmail(request);
await this.emailPromise; await this.emailPromise;
if (doToast) { if (doToast) {
this.toasterService.popAsync('success', null, this.platformUtilsService.showToast('success', null,
this.i18nService.t('verificationCodeEmailSent', this.twoFactorEmail)); this.i18nService.t('verificationCodeEmailSent', this.twoFactorEmail));
} }
} catch { } } catch { }

View File

@@ -8,7 +8,6 @@ import {
Output, Output,
} from '@angular/core'; } from '@angular/core';
import { ToasterService } from 'angular2-toaster';
import { Angulartics2 } from 'angulartics2'; import { Angulartics2 } from 'angulartics2';
import { CipherType } from '../../enums/cipherType'; import { CipherType } from '../../enums/cipherType';
@@ -50,7 +49,7 @@ export class ViewComponent implements OnDestroy, OnInit {
private totpInterval: any; private totpInterval: any;
constructor(protected cipherService: CipherService, protected totpService: TotpService, constructor(protected cipherService: CipherService, protected totpService: TotpService,
protected tokenService: TokenService, protected toasterService: ToasterService, protected tokenService: TokenService,
protected cryptoService: CryptoService, protected platformUtilsService: PlatformUtilsService, protected cryptoService: CryptoService, protected platformUtilsService: PlatformUtilsService,
protected i18nService: I18nService, protected analytics: Angulartics2, protected i18nService: I18nService, protected analytics: Angulartics2,
protected auditService: AuditService, protected win: Window, protected auditService: AuditService, protected win: Window,
@@ -120,9 +119,10 @@ export class ViewComponent implements OnDestroy, OnInit {
const matches = await this.checkPasswordPromise; const matches = await this.checkPasswordPromise;
if (matches > 0) { if (matches > 0) {
this.toasterService.popAsync('warning', null, this.i18nService.t('passwordExposed', matches.toString())); this.platformUtilsService.showToast('warning', null,
this.i18nService.t('passwordExposed', matches.toString()));
} else { } else {
this.toasterService.popAsync('success', null, this.i18nService.t('passwordSafe')); this.platformUtilsService.showToast('success', null, this.i18nService.t('passwordSafe'));
} }
} }
@@ -148,7 +148,7 @@ export class ViewComponent implements OnDestroy, OnInit {
this.analytics.eventTrack.next({ action: 'Copied ' + aType }); this.analytics.eventTrack.next({ action: 'Copied ' + aType });
const copyOptions = this.win != null ? { window: this.win } : null; const copyOptions = this.win != null ? { window: this.win } : null;
this.platformUtilsService.copyToClipboard(value, copyOptions); this.platformUtilsService.copyToClipboard(value, copyOptions);
this.toasterService.popAsync('info', null, this.platformUtilsService.showToast('info', null,
this.i18nService.t('valueCopied', this.i18nService.t(typeI18nKey))); this.i18nService.t('valueCopied', this.i18nService.t(typeI18nKey)));
} }
@@ -159,7 +159,7 @@ export class ViewComponent implements OnDestroy, OnInit {
} }
if (this.cipher.organizationId == null && !this.canAccessPremium) { if (this.cipher.organizationId == null && !this.canAccessPremium) {
this.toasterService.popAsync('error', this.i18nService.t('premiumRequired'), this.platformUtilsService.showToast('error', this.i18nService.t('premiumRequired'),
this.i18nService.t('premiumRequiredDesc')); this.i18nService.t('premiumRequiredDesc'));
return; return;
} }
@@ -167,7 +167,7 @@ export class ViewComponent implements OnDestroy, OnInit {
a.downloading = true; a.downloading = true;
const response = await fetch(new Request(attachment.url, { cache: 'no-cache' })); const response = await fetch(new Request(attachment.url, { cache: 'no-cache' }));
if (response.status !== 200) { if (response.status !== 200) {
this.toasterService.popAsync('error', null, this.i18nService.t('errorOccurred')); this.platformUtilsService.showToast('error', null, this.i18nService.t('errorOccurred'));
a.downloading = false; a.downloading = false;
return; return;
} }
@@ -178,7 +178,7 @@ export class ViewComponent implements OnDestroy, OnInit {
const decBuf = await this.cryptoService.decryptFromBytes(buf, key); const decBuf = await this.cryptoService.decryptFromBytes(buf, key);
this.platformUtilsService.saveFile(this.win, decBuf, null, attachment.fileName); this.platformUtilsService.saveFile(this.win, decBuf, null, attachment.fileName);
} catch (e) { } catch (e) {
this.toasterService.popAsync('error', null, this.i18nService.t('errorOccurred')); this.platformUtilsService.showToast('error', null, this.i18nService.t('errorOccurred'));
} }
a.downloading = false; a.downloading = false;

View File

@@ -1,21 +1,11 @@
import { import { Injectable } from '@angular/core';
Injectable,
SecurityContext,
} from '@angular/core';
import { DomSanitizer } from '@angular/platform-browser';
import {
BodyOutputType,
Toast,
ToasterService,
} from 'angular2-toaster';
import { I18nService } from '../../abstractions/i18n.service'; import { I18nService } from '../../abstractions/i18n.service';
import { PlatformUtilsService } from '../../abstractions/platformUtils.service';
@Injectable() @Injectable()
export class ValidationService { export class ValidationService {
constructor(private toasterService: ToasterService, private i18nService: I18nService, constructor(private i18nService: I18nService, private platformUtilsService: PlatformUtilsService) { }
private sanitizer: DomSanitizer) { }
showError(data: any): string[] { showError(data: any): string[] {
const defaultErrorMessage = this.i18nService.t('unexpectedError'); const defaultErrorMessage = this.i18nService.t('unexpectedError');
@@ -45,18 +35,11 @@ export class ValidationService {
} }
if (errors.length === 1) { if (errors.length === 1) {
this.toasterService.popAsync('error', this.i18nService.t('errorOccurred'), errors[0]); this.platformUtilsService.showToast('error', this.i18nService.t('errorOccurred'), errors[0]);
} else if (errors.length > 1) { } else if (errors.length > 1) {
let errorMessage = ''; this.platformUtilsService.showToast('error', this.i18nService.t('errorOccurred'), errors, {
errors.forEach((e) => errorMessage += ('<p>' + this.sanitizer.sanitize(SecurityContext.HTML, e) + '</p>'));
const toast: Toast = {
type: 'error',
title: this.i18nService.t('errorOccurred'),
body: errorMessage,
bodyOutputType: BodyOutputType.TrustedHtml,
timeout: 5000 * errors.length, timeout: 5000 * errors.length,
}; });
this.toasterService.popAsync(toast);
} }
return errors; return errors;

View File

@@ -140,14 +140,15 @@ export class ElectronPlatformUtilsService implements PlatformUtilsService {
return true; return true;
} }
showToast(type: 'error' | 'success' | 'warning' | 'info', title: string, text: string, global?: any): void { showToast(type: 'error' | 'success' | 'warning' | 'info', title: string, text: string | string[],
if (global == null && Utils.isBrowser) { options?: any): void {
global = window; if ((options == null || options.global == null) && Utils.isBrowser) {
options.global = window;
} }
if (global == null || global.BitwardenToasterService == null) { if (options.global == null || options.global.BitwardenToasterService == null) {
throw new Error('BitwardenToasterService not available on global.'); throw new Error('BitwardenToasterService not available on global.');
} }
global.BitwardenToasterService.popAsync(type, title, text); options.global.BitwardenToasterService.popAsync(type, title, text);
} }
showDialog(text: string, title?: string, confirmText?: string, cancelText?: string, type?: string): showDialog(text: string, title?: string, confirmText?: string, cancelText?: string, type?: string):