2022-06-20 23:32:19 +02:00
|
|
|
import { Component, ViewChild, ViewContainerRef } from "@angular/core";
|
2022-06-16 22:20:10 +02:00
|
|
|
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";
|
2022-06-20 18:50:56 +02:00
|
|
|
import { ModalConfig, ModalService } from "@bitwarden/angular/services/modal.service";
|
2022-06-16 22:20:10 +02:00
|
|
|
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";
|
2022-06-16 22:20:10 +02:00
|
|
|
import { StateService } from "@bitwarden/common/abstractions/state.service";
|
2022-06-20 23:24:48 +02:00
|
|
|
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 {
|
2020-12-04 15:58:26 +01:00
|
|
|
organizationId: string;
|
2022-06-16 22:20:10 +02:00
|
|
|
formatControl: string;
|
|
|
|
encryptionType: string;
|
|
|
|
showPassword: boolean;
|
|
|
|
showConfirmPassword: boolean;
|
|
|
|
secretValue: string;
|
|
|
|
secret: FormControl;
|
2022-06-20 18:50:56 +02:00
|
|
|
confirmDescription: string;
|
|
|
|
confirmButtonText: string;
|
|
|
|
modalTitle: string;
|
2022-06-16 22:20:10 +02:00
|
|
|
|
|
|
|
@ViewChild("viewUserApiKeyModalRef", { read: ViewContainerRef, static: true })
|
|
|
|
viewUserApiKeyModalRef: ViewContainerRef;
|
2020-12-04 15:58:26 +01:00
|
|
|
|
2018-10-03 16:33:04 +02:00
|
|
|
constructor(
|
|
|
|
cryptoService: CryptoService,
|
|
|
|
i18nService: I18nService,
|
2019-07-12 23:11:50 +02:00
|
|
|
platformUtilsService: PlatformUtilsService,
|
|
|
|
exportService: ExportService,
|
2021-11-09 19:24:26 +01:00
|
|
|
eventService: EventService,
|
|
|
|
policyService: PolicyService,
|
|
|
|
logService: LogService,
|
|
|
|
userVerificationService: UserVerificationService,
|
2022-06-16 22:20:10 +02:00
|
|
|
formBuilder: FormBuilder,
|
|
|
|
modalService: ModalService,
|
|
|
|
apiService: ApiService,
|
2022-06-20 18:50:56 +02:00
|
|
|
stateService: StateService,
|
2022-06-20 23:24:48 +02:00
|
|
|
userSecretPromptService: UserSecretPromptService,
|
2022-06-20 18:50:56 +02:00
|
|
|
modalConfig: ModalConfig
|
2021-11-09 19:24:26 +01:00
|
|
|
) {
|
2021-10-20 18:30:04 +02:00
|
|
|
super(
|
|
|
|
cryptoService,
|
|
|
|
i18nService,
|
|
|
|
platformUtilsService,
|
|
|
|
exportService,
|
|
|
|
eventService,
|
2021-11-09 19:24:26 +01:00
|
|
|
policyService,
|
|
|
|
window,
|
|
|
|
logService,
|
|
|
|
userVerificationService,
|
2022-06-16 22:20:10 +02:00
|
|
|
formBuilder,
|
|
|
|
modalService,
|
|
|
|
apiService,
|
2022-06-20 18:50:56 +02:00
|
|
|
stateService,
|
2022-06-20 23:24:48 +02:00
|
|
|
userSecretPromptService,
|
2022-06-20 18:50:56 +02:00
|
|
|
modalConfig
|
2021-11-09 19:24:26 +01:00
|
|
|
);
|
2018-06-20 22:28:56 +02:00
|
|
|
}
|
|
|
|
|
2022-06-20 18:50: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";
|
|
|
|
}
|
|
|
|
|
2022-06-16 22:20:10 +02:00
|
|
|
try {
|
2022-06-20 18:50:56 +02:00
|
|
|
if (
|
2022-06-20 23:24:48 +02:00
|
|
|
await this.userSecretPromptService.showPasswordPrompt(
|
2022-06-20 18:50:56 +02:00
|
|
|
confirmDescription,
|
|
|
|
confirmButtonText,
|
|
|
|
modalTitle
|
|
|
|
)
|
|
|
|
) {
|
|
|
|
//successful
|
|
|
|
} else {
|
|
|
|
//failed
|
|
|
|
this.platformUtilsService.showToast(
|
|
|
|
"error",
|
|
|
|
this.i18nService.t("error"),
|
|
|
|
this.i18nService.t("invalidMasterPassword")
|
|
|
|
);
|
|
|
|
return;
|
|
|
|
}
|
2022-06-16 22:20:10 +02:00
|
|
|
|
|
|
|
this.submitWithSecretAlreadyVerified();
|
|
|
|
} catch {
|
2022-06-20 18:50:56 +02:00
|
|
|
this.platformUtilsService.showToast(
|
|
|
|
"error",
|
|
|
|
this.i18nService.t("error"),
|
|
|
|
this.i18nService.t("invalidMasterPassword")
|
|
|
|
);
|
2022-06-16 22:20:10 +02:00
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
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();
|
2018-10-03 16:33:04 +02:00
|
|
|
this.platformUtilsService.showToast("success", null, this.i18nService.t("exportSuccess"));
|
2018-06-20 22:28:56 +02:00
|
|
|
}
|
|
|
|
}
|