init functions

This commit is contained in:
Kyle Spearrin 2019-03-06 14:31:32 -05:00
parent 965e35604c
commit 199884e6ae
3 changed files with 47 additions and 35 deletions

View File

@ -35,28 +35,7 @@ export class AttachmentsComponent implements OnInit {
protected platformUtilsService: PlatformUtilsService, protected win: Window) { } protected platformUtilsService: PlatformUtilsService, protected win: Window) { }
async ngOnInit() { async ngOnInit() {
this.cipherDomain = await this.loadCipher(); await this.init();
this.cipher = await this.cipherDomain.decrypt();
this.hasUpdatedKey = await this.cryptoService.hasEncKey();
const canAccessPremium = await this.userService.canAccessPremium();
this.canAccessAttachments = canAccessPremium || this.cipher.organizationId != null;
if (!this.canAccessAttachments) {
const confirmed = await this.platformUtilsService.showDialog(
this.i18nService.t('premiumRequiredDesc'), this.i18nService.t('premiumRequired'),
this.i18nService.t('learnMore'), this.i18nService.t('cancel'));
if (confirmed) {
this.platformUtilsService.launchUri('https://vault.bitwarden.com/#/?premium=purchase');
}
} else if (!this.hasUpdatedKey) {
const confirmed = await this.platformUtilsService.showDialog(
this.i18nService.t('updateKey'), this.i18nService.t('featureUnavailable'),
this.i18nService.t('learnMore'), this.i18nService.t('cancel'), 'warning');
if (confirmed) {
this.platformUtilsService.launchUri('https://help.bitwarden.com/article/update-encryption-key/');
}
}
} }
async submit() { async submit() {
@ -156,6 +135,31 @@ export class AttachmentsComponent implements OnInit {
a.downloading = false; a.downloading = false;
} }
protected async init() {
this.cipherDomain = await this.loadCipher();
this.cipher = await this.cipherDomain.decrypt();
this.hasUpdatedKey = await this.cryptoService.hasEncKey();
const canAccessPremium = await this.userService.canAccessPremium();
this.canAccessAttachments = canAccessPremium || this.cipher.organizationId != null;
if (!this.canAccessAttachments) {
const confirmed = await this.platformUtilsService.showDialog(
this.i18nService.t('premiumRequiredDesc'), this.i18nService.t('premiumRequired'),
this.i18nService.t('learnMore'), this.i18nService.t('cancel'));
if (confirmed) {
this.platformUtilsService.launchUri('https://vault.bitwarden.com/#/?premium=purchase');
}
} else if (!this.hasUpdatedKey) {
const confirmed = await this.platformUtilsService.showDialog(
this.i18nService.t('updateKey'), this.i18nService.t('featureUnavailable'),
this.i18nService.t('learnMore'), this.i18nService.t('cancel'), 'warning');
if (confirmed) {
this.platformUtilsService.launchUri('https://help.bitwarden.com/article/update-encryption-key/');
}
}
}
protected async reuploadCipherAttachment(attachment: AttachmentView, admin: boolean) { protected async reuploadCipherAttachment(attachment: AttachmentView, admin: boolean) {
const a = (attachment as any); const a = (attachment as any);
if (attachment.key != null || a.downloading || this.reuploadPromises[attachment.id] != null) { if (attachment.key != null || a.downloading || this.reuploadPromises[attachment.id] != null) {

View File

@ -26,16 +26,7 @@ export class FolderAddEditComponent implements OnInit {
protected platformUtilsService: PlatformUtilsService) { } protected platformUtilsService: PlatformUtilsService) { }
async ngOnInit() { async ngOnInit() {
this.editMode = this.folderId != null; await this.init();
if (this.editMode) {
this.editMode = true;
this.title = this.i18nService.t('editFolder');
const folder = await this.folderService.get(this.folderId);
this.folder = await folder.decrypt();
} else {
this.title = this.i18nService.t('addFolder');
}
} }
async submit(): Promise<boolean> { async submit(): Promise<boolean> {
@ -77,4 +68,17 @@ export class FolderAddEditComponent implements OnInit {
return true; return true;
} }
protected async init() {
this.editMode = this.folderId != null;
if (this.editMode) {
this.editMode = true;
this.title = this.i18nService.t('editFolder');
const folder = await this.folderService.get(this.folderId);
this.folder = await folder.decrypt();
} else {
this.title = this.i18nService.t('addFolder');
}
}
} }

View File

@ -14,9 +14,7 @@ export class PasswordHistoryComponent implements OnInit {
protected i18nService: I18nService, private win: Window) { } protected i18nService: I18nService, private win: Window) { }
async ngOnInit() { async ngOnInit() {
const cipher = await this.cipherService.get(this.cipherId); await this.init();
const decCipher = await cipher.decrypt();
this.history = decCipher.passwordHistory == null ? [] : decCipher.passwordHistory;
} }
copy(password: string) { copy(password: string) {
@ -26,4 +24,10 @@ export class PasswordHistoryComponent implements OnInit {
this.platformUtilsService.showToast('info', null, this.platformUtilsService.showToast('info', null,
this.i18nService.t('valueCopied', this.i18nService.t('password'))); this.i18nService.t('valueCopied', this.i18nService.t('password')));
} }
protected async init() {
const cipher = await this.cipherService.get(this.cipherId);
const decCipher = await cipher.decrypt();
this.history = decCipher.passwordHistory == null ? [] : decCipher.passwordHistory;
}
} }