mirror of
https://github.com/bitwarden/browser.git
synced 2024-12-21 16:18:28 +01:00
[PM-1826] [PM-2168] [Tech debt] Migrate file-password-prompt to dialog (#5666)
* Migrate file-password-prompt to Dialog * Fix issue with cancel/empty password returned * Removed unneeded click handler to cancel dialog * Added margin as requested by design * Only apply margin to top of field * Call submit when clicking on Import data * Add form and and submit trigger
This commit is contained in:
parent
3abb1c9a3b
commit
24d9ac88ba
@ -1,45 +1,32 @@
|
|||||||
<!-- Please remove this disable statement when editing this file! -->
|
<form (submit)="submit()">
|
||||||
<!-- eslint-disable tailwindcss/no-custom-classname -->
|
<bit-dialog>
|
||||||
<div
|
<span bitDialogTitle>
|
||||||
class="modal fade"
|
{{ "confirmVaultImport" | i18n }}
|
||||||
role="dialog"
|
</span>
|
||||||
aria-modal="true"
|
|
||||||
[attr.aria-labelledby]="'confirmVaultImport' | i18n"
|
<div bitDialogContent>
|
||||||
>
|
{{ "confirmVaultImportDesc" | i18n }}
|
||||||
<div class="modal-dialog modal-dialog-scrollable" role="document">
|
<bit-form-field class="tw-mt-6">
|
||||||
<form #form (ngSubmit)="submit()">
|
<bit-label>{{ "confirmFilePassword" | i18n }}</bit-label>
|
||||||
<div class="form-group modal-content">
|
<input
|
||||||
<h2 class="tw-my-6 tw-ml-3.5 tw-font-semibold" id="confirmVaultImport">
|
bitInput
|
||||||
{{ "confirmVaultImport" | i18n | uppercase }}
|
type="password"
|
||||||
</h2>
|
name="filePassword"
|
||||||
<div
|
[formControl]="filePassword"
|
||||||
class="tw-border-0 tw-border-t tw-border-solid tw-border-secondary-300 tw-px-3.5 tw-pt-3.5"
|
appAutofocus
|
||||||
>
|
appInputVerbatim
|
||||||
{{ "confirmVaultImportDesc" | i18n }}
|
/>
|
||||||
<bit-form-field class="tw-pt-3.5">
|
<button type="button" bitSuffix bitIconButton bitPasswordInputToggle></button>
|
||||||
<bit-label>{{ "confirmFilePassword" | i18n }}</bit-label>
|
</bit-form-field>
|
||||||
<input
|
</div>
|
||||||
bitInput
|
|
||||||
type="password"
|
<ng-container bitDialogFooter>
|
||||||
name="filePassword"
|
<button bitButton buttonType="primary" type="submit">
|
||||||
[formControl]="filePassword"
|
<span>{{ "importData" | i18n }}</span>
|
||||||
appAutofocus
|
</button>
|
||||||
appInputVerbatim
|
<button bitButton bitDialogClose buttonType="secondary" type="button">
|
||||||
/>
|
<span>{{ "cancel" | i18n }}</span>
|
||||||
<button type="button" bitSuffix bitIconButton bitPasswordInputToggle></button>
|
</button>
|
||||||
</bit-form-field>
|
</ng-container>
|
||||||
</div>
|
</bit-dialog>
|
||||||
<div
|
</form>
|
||||||
class="tw-flex tw-w-full tw-flex-wrap tw-items-center tw-border-0 tw-border-t tw-border-solid tw-border-secondary-300 tw-bg-background-alt tw-px-3.5 tw-pb-3.5 tw-pt-4"
|
|
||||||
>
|
|
||||||
<button bitButton buttonType="primary" class="tw-mr-2" type="submit" appBlurClick>
|
|
||||||
<span>{{ "importData" | i18n }}</span>
|
|
||||||
</button>
|
|
||||||
<button bitButton buttonType="secondary" type="button" (click)="cancel()">
|
|
||||||
<span>{{ "cancel" | i18n }}</span>
|
|
||||||
</button>
|
|
||||||
</div>
|
|
||||||
</div>
|
|
||||||
</form>
|
|
||||||
</div>
|
|
||||||
</div>
|
|
||||||
|
@ -1,26 +1,20 @@
|
|||||||
|
import { DialogRef } from "@angular/cdk/dialog";
|
||||||
import { Component } from "@angular/core";
|
import { Component } from "@angular/core";
|
||||||
import { FormControl, Validators } from "@angular/forms";
|
import { FormControl, Validators } from "@angular/forms";
|
||||||
|
|
||||||
import { ModalRef } from "@bitwarden/angular/components/modal/modal.ref";
|
|
||||||
|
|
||||||
@Component({
|
@Component({
|
||||||
templateUrl: "file-password-prompt.component.html",
|
templateUrl: "file-password-prompt.component.html",
|
||||||
})
|
})
|
||||||
export class FilePasswordPromptComponent {
|
export class FilePasswordPromptComponent {
|
||||||
filePassword = new FormControl("", Validators.required);
|
filePassword = new FormControl("", Validators.required);
|
||||||
|
|
||||||
constructor(private modalRef: ModalRef) {}
|
constructor(public dialogRef: DialogRef) {}
|
||||||
|
|
||||||
submit() {
|
submit() {
|
||||||
this.filePassword.markAsTouched();
|
this.filePassword.markAsTouched();
|
||||||
if (!this.filePassword.valid) {
|
if (!this.filePassword.valid) {
|
||||||
return;
|
return;
|
||||||
}
|
}
|
||||||
|
this.dialogRef.close(this.filePassword.value);
|
||||||
this.modalRef.close(this.filePassword.value);
|
|
||||||
}
|
|
||||||
|
|
||||||
cancel() {
|
|
||||||
this.modalRef.close(null);
|
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
@ -1,7 +1,7 @@
|
|||||||
import { Component, OnDestroy, OnInit } from "@angular/core";
|
import { Component, OnDestroy, OnInit } from "@angular/core";
|
||||||
import { Router } from "@angular/router";
|
import { Router } from "@angular/router";
|
||||||
import * as JSZip from "jszip";
|
import * as JSZip from "jszip";
|
||||||
import { Subject } from "rxjs";
|
import { Subject, lastValueFrom } from "rxjs";
|
||||||
import { takeUntil } from "rxjs/operators";
|
import { takeUntil } from "rxjs/operators";
|
||||||
import Swal, { SweetAlertIcon } from "sweetalert2";
|
import Swal, { SweetAlertIcon } from "sweetalert2";
|
||||||
|
|
||||||
@ -270,15 +270,11 @@ export class ImportComponent implements OnInit, OnDestroy {
|
|||||||
}
|
}
|
||||||
|
|
||||||
async getFilePassword(): Promise<string> {
|
async getFilePassword(): Promise<string> {
|
||||||
const ref = this.modalService.open(FilePasswordPromptComponent, {
|
const dialog = this.dialogService.open<string>(FilePasswordPromptComponent, {
|
||||||
allowMultipleModals: true,
|
ariaModal: true,
|
||||||
});
|
});
|
||||||
|
|
||||||
if (ref == null) {
|
return await lastValueFrom(dialog.closed);
|
||||||
return null;
|
|
||||||
}
|
|
||||||
|
|
||||||
return await ref.onClosedPromise();
|
|
||||||
}
|
}
|
||||||
|
|
||||||
ngOnDestroy(): void {
|
ngOnDestroy(): void {
|
||||||
|
@ -62,6 +62,10 @@ export class BitwardenPasswordProtectedImporter extends BitwardenJsonImporter im
|
|||||||
jdoc: BitwardenPasswordProtectedFileFormat,
|
jdoc: BitwardenPasswordProtectedFileFormat,
|
||||||
password: string
|
password: string
|
||||||
): Promise<boolean> {
|
): Promise<boolean> {
|
||||||
|
if (this.isNullOrWhitespace(password)) {
|
||||||
|
return false;
|
||||||
|
}
|
||||||
|
|
||||||
this.key = await this.cryptoService.makePinKey(
|
this.key = await this.cryptoService.makePinKey(
|
||||||
password,
|
password,
|
||||||
jdoc.salt,
|
jdoc.salt,
|
||||||
|
Loading…
Reference in New Issue
Block a user