1
0
mirror of https://github.com/bitwarden/browser synced 2026-01-07 11:03:30 +00:00

support for unlocking with PIN code

This commit is contained in:
Kyle Spearrin
2019-02-12 23:53:04 -05:00
parent 7b395ba4ff
commit d5cbae7803
7 changed files with 80 additions and 7 deletions

View File

@@ -31,6 +31,10 @@
<option *ngFor="let o of lockOptions" [ngValue]="o.value">{{o.name}}</option>
</select>
</div>
<div class="box-content-row box-content-row-checkbox" appBoxRow>
<label for="pin">{{'unlockWithPin' | i18n}}</label>
<input id="pin" type="checkbox" (change)="updatePin()" [(ngModel)]="pin">
</div>
<a class="box-content-row box-content-row-flex text-default" href="#"
appStopClick appBlurClick (click)="lock()">
<div class="row-main">{{'lockNow' | i18n}}</div>

View File

@@ -47,6 +47,7 @@ export class SettingsComponent implements OnInit {
@ViewChild('lockOptionsSelect', { read: ElementRef }) lockOptionsSelectRef: ElementRef;
lockOptions: any[];
lockOption: number = null;
pin: boolean = null;
previousLockOption: number = null;
constructor(private platformUtilsService: PlatformUtilsService, private i18nService: I18nService,
@@ -87,6 +88,8 @@ export class SettingsComponent implements OnInit {
this.lockOption = option;
}
this.previousLockOption = this.lockOption;
this.pin = await this.lockService.isPinLockSet();
}
async saveLockOption(newValue: number) {
@@ -111,6 +114,27 @@ export class SettingsComponent implements OnInit {
}
}
async updatePin() {
if (this.pin) {
const pin = await swal({
text: this.i18nService.t('setYourPinCode'),
content: { element: 'input' },
buttons: [this.i18nService.t('cancel'), this.i18nService.t('submit')],
});
if (pin != null && pin.trim() !== '') {
const pinKey = await this.cryptoService.makePinKey(pin, await this.userService.getEmail());
const key = await this.cryptoService.getKey();
const pinProtectedKey = await this.cryptoService.encrypt(key.key, pinKey);
await this.storageService.save(ConstantsService.pinProtectedKey, pinProtectedKey.encryptedString);
} else {
this.pin = false;
}
}
if (!this.pin) {
await this.storageService.remove(ConstantsService.pinProtectedKey);
}
}
async lock() {
this.analytics.eventTrack.next({ action: 'Lock Now' });
await this.lockService.lock();