bitwarden-estensione-browser/apps/web/src/app/tools/export.component.ts

Ignoring revisions in .git-blame-ignore-revs. Click here to bypass and see the normal blame view.

129 lines
4.0 KiB
TypeScript
Raw Normal View History

2022-06-20 23:32:19 +02:00
import { Component, ViewChild, ViewContainerRef } from "@angular/core";
import { FormBuilder, FormControl } from "@angular/forms";
2018-06-20 22:28:56 +02:00
2022-06-14 17:10:53 +02:00
import { ExportComponent as BaseExportComponent } from "@bitwarden/angular/components/export.component";
import { ModalConfig, ModalService } from "@bitwarden/angular/services/modal.service";
import { ApiService } from "@bitwarden/common/abstractions/api.service";
2022-06-14 17:10:53 +02:00
import { CryptoService } from "@bitwarden/common/abstractions/crypto.service";
import { EventService } from "@bitwarden/common/abstractions/event.service";
import { ExportService } from "@bitwarden/common/abstractions/export.service";
import { I18nService } from "@bitwarden/common/abstractions/i18n.service";
import { LogService } from "@bitwarden/common/abstractions/log.service";
import { PlatformUtilsService } from "@bitwarden/common/abstractions/platformUtils.service";
import { PolicyService } from "@bitwarden/common/abstractions/policy.service";
import { StateService } from "@bitwarden/common/abstractions/state.service";
import { UserSecretPromptService } from "@bitwarden/common/abstractions/userSecretPrompt.service";
2022-06-14 17:10:53 +02:00
import { UserVerificationService } from "@bitwarden/common/abstractions/userVerification.service";
2018-06-20 22:28:56 +02:00
2018-06-10 05:33:12 +02:00
@Component({
selector: "app-export",
templateUrl: "export.component.html",
})
2018-06-20 22:28:56 +02:00
export class ExportComponent extends BaseExportComponent {
organizationId: string;
formatControl: string;
encryptionType: string;
showPassword: boolean;
showConfirmPassword: boolean;
secretValue: string;
secret: FormControl;
confirmDescription: string;
confirmButtonText: string;
modalTitle: string;
@ViewChild("viewUserApiKeyModalRef", { read: ViewContainerRef, static: true })
viewUserApiKeyModalRef: ViewContainerRef;
constructor(
cryptoService: CryptoService,
i18nService: I18nService,
2019-07-12 23:11:50 +02:00
platformUtilsService: PlatformUtilsService,
exportService: ExportService,
eventService: EventService,
policyService: PolicyService,
logService: LogService,
userVerificationService: UserVerificationService,
formBuilder: FormBuilder,
modalService: ModalService,
apiService: ApiService,
stateService: StateService,
userSecretPromptService: UserSecretPromptService,
modalConfig: ModalConfig
) {
super(
cryptoService,
i18nService,
platformUtilsService,
exportService,
eventService,
policyService,
window,
logService,
userVerificationService,
formBuilder,
modalService,
apiService,
stateService,
userSecretPromptService,
modalConfig
);
2018-06-20 22:28:56 +02:00
}
async promptUserForSecret(encryptionType: string) {
//Default text values
let confirmDescription = "encExportKeyWarningDesc";
let confirmButtonText = "exportVault";
let modalTitle = "confirmVaultExport";
//Password encrypted export
if (encryptionType == "2") {
confirmDescription = "confirmVaultExportDesc";
confirmButtonText = "exportVault";
modalTitle = "confirmVaultExport";
}
try {
if (
await this.userSecretPromptService.showPasswordPrompt(
confirmDescription,
confirmButtonText,
modalTitle
)
) {
//successful
} else {
//failed
this.platformUtilsService.showToast(
"error",
this.i18nService.t("error"),
this.i18nService.t("invalidMasterPassword")
);
return;
}
this.submitWithSecretAlreadyVerified();
} catch {
this.platformUtilsService.showToast(
"error",
this.i18nService.t("error"),
this.i18nService.t("invalidMasterPassword")
);
}
}
togglePassword() {
this.showPassword = !this.showPassword;
document.getElementById("newPassword").focus();
}
toggleConfirmPassword() {
this.showConfirmPassword = !this.showConfirmPassword;
document.getElementById("newConfirmPassword").focus();
}
2018-06-20 22:28:56 +02:00
protected saved() {
super.saved();
this.platformUtilsService.showToast("success", null, this.i18nService.t("exportSuccess"));
2018-06-20 22:28:56 +02:00
}
}