mirror of
https://github.com/bitwarden/browser
synced 2026-02-12 22:44:11 +00:00
Changes suggested by Thomas R
This commit is contained in:
@@ -1,8 +1,6 @@
|
||||
import { Directive, EventEmitter, OnInit, Output } from "@angular/core";
|
||||
import { FormBuilder } from "@angular/forms";
|
||||
|
||||
import { ModalConfig, ModalService } from "@bitwarden/angular/services/modal.service";
|
||||
import { ApiService } from "@bitwarden/common/abstractions/api.service";
|
||||
import { CryptoService } from "@bitwarden/common/abstractions/crypto.service";
|
||||
import { EventService } from "@bitwarden/common/abstractions/event.service";
|
||||
import { ExportService } from "@bitwarden/common/abstractions/export.service";
|
||||
@@ -11,24 +9,24 @@ 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 { UserVerificationService } from "@bitwarden/common/abstractions/userVerification.service";
|
||||
import { EventType } from "@bitwarden/common/enums/eventType";
|
||||
import { PolicyType } from "@bitwarden/common/enums/policyType";
|
||||
|
||||
import { ModalService } from "../services/modal.service";
|
||||
|
||||
@Directive()
|
||||
export class ExportComponent implements OnInit {
|
||||
@Output() onSaved = new EventEmitter();
|
||||
|
||||
formPromise: Promise<string>;
|
||||
disabledByPolicy = false;
|
||||
encryptionPassword: string;
|
||||
|
||||
exportForm = this.formBuilder.group({
|
||||
format: ["json"],
|
||||
secret: [""],
|
||||
password: [""],
|
||||
confirmPassword: [""],
|
||||
filePassword: [""],
|
||||
confirmFilePassword: [""],
|
||||
fileEncryptionType: [""],
|
||||
});
|
||||
|
||||
@@ -48,12 +46,9 @@ export class ExportComponent implements OnInit {
|
||||
protected win: Window,
|
||||
private logService: LogService,
|
||||
private userVerificationService: UserVerificationService,
|
||||
protected modalService: ModalService,
|
||||
protected apiService: ApiService,
|
||||
protected stateService: StateService,
|
||||
protected modalConfig: ModalConfig,
|
||||
private formBuilder: FormBuilder,
|
||||
protected fileDownloadService: FileDownloadService
|
||||
protected fileDownloadService: FileDownloadService,
|
||||
protected modalService: ModalService
|
||||
) {}
|
||||
|
||||
async ngOnInit() {
|
||||
@@ -91,8 +86,8 @@ export class ExportComponent implements OnInit {
|
||||
this.saved();
|
||||
await this.collectEvent();
|
||||
this.exportForm.get("secret").setValue("");
|
||||
this.exportForm.get("password").setValue("");
|
||||
this.exportForm.get("confirmPassword").setValue("");
|
||||
this.exportForm.get("filePassword").setValue("");
|
||||
this.exportForm.get("confirmFilePassword").setValue("");
|
||||
} catch (e) {
|
||||
this.logService.error(e);
|
||||
}
|
||||
@@ -165,9 +160,10 @@ export class ExportComponent implements OnInit {
|
||||
}
|
||||
|
||||
protected getExportData() {
|
||||
return (this.fileEncryptionType != 1 && this.password == undefined) || this.password == ""
|
||||
return (this.fileEncryptionType != 1 && this.filePassword == undefined) ||
|
||||
this.filePassword == ""
|
||||
? this.exportService.getExport(this.format, null)
|
||||
: this.exportService.getPasswordProtectedExport(this.password);
|
||||
: this.exportService.getPasswordProtectedExport(this.filePassword);
|
||||
}
|
||||
|
||||
protected getFileName(prefix?: string) {
|
||||
@@ -187,20 +183,16 @@ export class ExportComponent implements OnInit {
|
||||
await this.eventService.collect(EventType.User_ClientExportedVault);
|
||||
}
|
||||
|
||||
protected clearPasswordField() {
|
||||
this.encryptionPassword = "";
|
||||
}
|
||||
|
||||
get format() {
|
||||
return this.exportForm.get("format").value;
|
||||
}
|
||||
|
||||
get password() {
|
||||
return this.exportForm.get("password").value;
|
||||
get filePassword() {
|
||||
return this.exportForm.get("filePassword").value;
|
||||
}
|
||||
|
||||
get confirmPassword() {
|
||||
return this.exportForm.get("confirmPassword").value;
|
||||
get confirmFilePassword() {
|
||||
return this.exportForm.get("confirmFilePassword").value;
|
||||
}
|
||||
|
||||
get fileEncryptionType() {
|
||||
|
||||
@@ -1,5 +1,5 @@
|
||||
import { Directive } from "@angular/core";
|
||||
import { FormBuilder } from "@angular/forms";
|
||||
import { FormBuilder, FormControl } from "@angular/forms";
|
||||
|
||||
import { I18nService } from "@bitwarden/common/abstractions/i18n.service";
|
||||
import { ImportService } from "@bitwarden/common/abstractions/import.service";
|
||||
@@ -15,12 +15,9 @@ import { ModalRef } from "./modal/modal.ref";
|
||||
@Directive()
|
||||
export class FilePasswordPromptComponent {
|
||||
showPassword: boolean;
|
||||
|
||||
importForm = this.formBuilder.group({
|
||||
filePassword: [""],
|
||||
organizationId: [""],
|
||||
fileContents: [""],
|
||||
});
|
||||
filePassword = new FormControl("");
|
||||
organizationId: string;
|
||||
fileContents: string;
|
||||
|
||||
constructor(
|
||||
private modalRef: ModalRef,
|
||||
@@ -30,8 +27,8 @@ export class FilePasswordPromptComponent {
|
||||
config: ModalConfig,
|
||||
protected formBuilder: FormBuilder
|
||||
) {
|
||||
this.importForm.get("fileContents").setValue(config.data.fileContents);
|
||||
this.importForm.get("organizationId").setValue(config.data.organizationId);
|
||||
this.fileContents = config.data.fileContents;
|
||||
this.organizationId = config.data.organizationId;
|
||||
}
|
||||
|
||||
togglePassword() {
|
||||
@@ -41,16 +38,15 @@ export class FilePasswordPromptComponent {
|
||||
async submit() {
|
||||
const importerPassword = this.importService.getImporter(
|
||||
"bitwardenpasswordprotected",
|
||||
this.importForm.get("organizationId").value,
|
||||
this.importForm.get("filePassword").value
|
||||
this.organizationId,
|
||||
this.filePassword.value
|
||||
);
|
||||
|
||||
const formPromise = this.importService.import(
|
||||
const passwordError = this.importService.import(
|
||||
importerPassword,
|
||||
this.importForm.get("fileContents").value,
|
||||
this.importForm.get("organizationId").value
|
||||
this.fileContents,
|
||||
this.organizationId
|
||||
);
|
||||
const passwordError = await formPromise;
|
||||
|
||||
if (passwordError != null) {
|
||||
this.platformUtilsService.showToast(
|
||||
|
||||
@@ -14,14 +14,10 @@ import { ModalRef } from "./modal/modal.ref";
|
||||
*/
|
||||
@Directive()
|
||||
export class UserVerificationPromptComponent {
|
||||
showPassword = false;
|
||||
organizationId = "";
|
||||
confirmDescription = this.config.data.confirmDescription;
|
||||
confirmButtonText = this.config.data.confirmButtonText;
|
||||
modalTitle = this.config.data.modalTitle;
|
||||
myGroup = this.formBuilder.group({
|
||||
secret: new FormControl(),
|
||||
});
|
||||
secret = new FormControl();
|
||||
|
||||
constructor(
|
||||
private modalRef: ModalRef,
|
||||
@@ -32,16 +28,10 @@ export class UserVerificationPromptComponent {
|
||||
private i18nService: I18nService
|
||||
) {}
|
||||
|
||||
togglePassword() {
|
||||
this.showPassword = !this.showPassword;
|
||||
}
|
||||
|
||||
async submit() {
|
||||
const secret = this.myGroup.get("secret").value;
|
||||
|
||||
try {
|
||||
//Incorrect secret will throw an invalid password error.
|
||||
await this.userVerificationService.verifyUser(secret);
|
||||
await this.userVerificationService.verifyUser(this.secret.value);
|
||||
} catch (e) {
|
||||
this.platformUtilsService.showToast(
|
||||
"error",
|
||||
|
||||
Reference in New Issue
Block a user