2022-06-16 22:20:10 +02:00
|
|
|
import { Component, EventEmitter, Output, 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";
|
2022-06-16 22:20:10 +02:00
|
|
|
import { 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";
|
2022-06-16 22:20:10 +02:00
|
|
|
import { StateService } from "@bitwarden/common/abstractions/state.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
|
|
|
|
2022-06-16 22:20:10 +02:00
|
|
|
import { ApiKeyComponent } from "../settings/api-key.component";
|
|
|
|
|
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;
|
|
|
|
|
|
|
|
@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,
|
|
|
|
stateService: StateService
|
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,
|
|
|
|
stateService
|
2021-11-09 19:24:26 +01:00
|
|
|
);
|
2018-06-20 22:28:56 +02:00
|
|
|
}
|
|
|
|
|
2022-06-16 22:20:10 +02:00
|
|
|
async promptUserForSecret() {
|
|
|
|
const entityId = await this.stateService.getUserId();
|
|
|
|
try {
|
|
|
|
// //TODO get help from Thomas on this/ other options I have to get a Secret :
|
|
|
|
// await this.modalService.openViewRef(ApiKeyComponent, this.viewUserApiKeyModalRef, (comp) => {
|
|
|
|
// comp.keyType = "user";
|
|
|
|
// comp.entityId = entityId;
|
|
|
|
// comp.postKey = this.apiService.postUserApiKey.bind(this.apiService);
|
|
|
|
// comp.scope = "api";
|
|
|
|
// comp.grantType = "client_credentials";
|
|
|
|
// comp.apiKeyTitle = "apiKey";
|
|
|
|
// comp.apiKeyWarning = "userApiKeyWarning";
|
|
|
|
// comp.apiKeyDescription = "userApiKeyDesc";
|
|
|
|
// });
|
|
|
|
|
|
|
|
// this.platformUtilsService.showToast("error", "This line doesn't get called because of an error ", this.i18nService.t("exportFail"));
|
|
|
|
|
|
|
|
//If verification is successful:
|
|
|
|
this.submitWithSecretAlreadyVerified();
|
|
|
|
} catch {
|
|
|
|
this.platformUtilsService.showToast("error", "FAIL", this.i18nService.t("exportFail"));
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
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
|
|
|
}
|
|
|
|
}
|