diff --git a/src/popup/components/set-pin.component.html b/src/popup/components/set-pin.component.html
new file mode 100644
index 0000000000..8513011282
--- /dev/null
+++ b/src/popup/components/set-pin.component.html
@@ -0,0 +1,44 @@
+
diff --git a/src/popup/components/set-pin.component.ts b/src/popup/components/set-pin.component.ts
new file mode 100644
index 0000000000..938a32873f
--- /dev/null
+++ b/src/popup/components/set-pin.component.ts
@@ -0,0 +1,8 @@
+import { Component } from '@angular/core';
+
+import { SetPinComponent as BaseSetPinComponent } from 'jslib-angular/components/set-pin.component';
+
+@Component({
+ templateUrl: 'set-pin.component.html',
+})
+export class SetPinComponent extends BaseSetPinComponent {}
diff --git a/src/popup/settings/settings.component.ts b/src/popup/settings/settings.component.ts
index 393bd839d0..83d3841aef 100644
--- a/src/popup/settings/settings.component.ts
+++ b/src/popup/settings/settings.component.ts
@@ -25,6 +25,10 @@ import { UserService } from 'jslib-common/abstractions/user.service';
import { VaultTimeoutService } from 'jslib-common/abstractions/vaultTimeout.service';
import { PopupUtilsService } from '../services/popup-utils.service';
+import { ModalService } from 'jslib-angular/services/modal.service';
+
+import { SetPinComponent } from '../components/set-pin.component';
+
const RateUrls = {
[DeviceType.ChromeExtension]:
'https://chrome.google.com/webstore/detail/bitwarden-free-password-m/nngceckbapebfimnlniiiahkandclblb/reviews',
@@ -61,7 +65,7 @@ export class SettingsComponent implements OnInit {
public messagingService: MessagingService, private router: Router,
private environmentService: EnvironmentService, private cryptoService: CryptoService,
private userService: UserService, private popupUtilsService: PopupUtilsService,
- private toasterService: ToasterService) {
+ private modalService: ModalService, private toasterService: ToasterService) {
}
async ngOnInit() {
@@ -164,58 +168,15 @@ export class SettingsComponent implements OnInit {
async updatePin() {
if (this.pin) {
- const div = document.createElement('div');
- const label = document.createElement('label');
- label.className = 'checkbox';
- const checkboxText = document.createElement('span');
- const restartText = document.createTextNode(this.i18nService.t('lockWithMasterPassOnRestart'));
- checkboxText.appendChild(restartText);
- label.innerHTML = '
';
- label.appendChild(checkboxText);
+ const ref = this.modalService.open(SetPinComponent, { allowMultipleModals: true });
- div.innerHTML =
- `
${this.i18nService.t('setYourPinCode')}
` +
- '
';
-
- (div.querySelector('#pin-val') as HTMLInputElement).placeholder = this.i18nService.t('pin');
- div.appendChild(label);
-
- const submitted = await Swal.fire({
- heightAuto: false,
- buttonsStyling: false,
- html: div,
- showCancelButton: true,
- cancelButtonText: this.i18nService.t('cancel'),
- showConfirmButton: true,
- confirmButtonText: this.i18nService.t('submit'),
- });
-
- let pin: string = null;
- let masterPassOnRestart: boolean = null;
- if (submitted.value) {
- pin = (document.getElementById('pin-val') as HTMLInputElement).value;
- masterPassOnRestart = (document.getElementById('master-pass-restart') as HTMLInputElement).checked;
- }
- if (pin != null && pin.trim() !== '') {
- const kdf = await this.userService.getKdf();
- const kdfIterations = await this.userService.getKdfIterations();
- const email = await this.userService.getEmail();
- const pinKey = await this.cryptoService.makePinKey(pin, email, kdf, kdfIterations);
- const key = await this.cryptoService.getKey();
- const pinProtectedKey = await this.cryptoService.encrypt(key.key, pinKey);
- if (masterPassOnRestart) {
- const encPin = await this.cryptoService.encrypt(pin);
- await this.storageService.save(ConstantsService.protectedPin, encPin.encryptedString);
- this.vaultTimeoutService.pinProtectedKey = pinProtectedKey;
- } else {
- await this.storageService.save(ConstantsService.pinProtectedKey, pinProtectedKey.encryptedString);
- }
- } else {
+ if (ref == null) {
this.pin = false;
+ return;
}
- }
- if (!this.pin) {
+
+ this.pin = await ref.onClosedPromise();
+ } else {
await this.cryptoService.clearPinProtectedKey();
await this.vaultTimeoutService.clear();
}