mirror of
https://github.com/bitwarden/browser
synced 2025-12-15 07:43:35 +00:00
65 lines
2.3 KiB
TypeScript
65 lines
2.3 KiB
TypeScript
import * as angular from 'angular';
|
|
import * as template from './lock.component.html';
|
|
|
|
import { CryptoService } from '../../../services/abstractions/crypto.service';
|
|
|
|
import { MessagingService, PlatformUtilsService } from '@bitwarden/jslib';
|
|
|
|
export class LockController {
|
|
i18n: any;
|
|
masterPassword: string;
|
|
|
|
constructor(public $state: any, public i18nService: any, private $timeout: any,
|
|
private platformUtilsService: PlatformUtilsService, public cryptoService: CryptoService, public toastr: any,
|
|
public userService: any, public messagingService: MessagingService, public SweetAlert: any) {
|
|
this.i18n = i18nService;
|
|
}
|
|
|
|
$onInit() {
|
|
this.$timeout(() => {
|
|
this.platformUtilsService.initListSectionItemListeners(document, angular);
|
|
document.getElementById('master-password').focus();
|
|
}, 500);
|
|
}
|
|
|
|
logOut() {
|
|
this.SweetAlert.swal({
|
|
title: this.i18nService.logOut,
|
|
text: this.i18nService.logOutConfirmation,
|
|
showCancelButton: true,
|
|
confirmButtonText: this.i18nService.yes,
|
|
cancelButtonText: this.i18nService.cancel,
|
|
}, (confirmed: boolean) => {
|
|
if (confirmed) {
|
|
this.messagingService.send('logout');
|
|
}
|
|
});
|
|
}
|
|
|
|
async submit() {
|
|
if (this.masterPassword == null || this.masterPassword === '') {
|
|
this.toastr.error(this.i18nService.invalidMasterPassword, this.i18nService.errorsOccurred);
|
|
return;
|
|
}
|
|
|
|
const email = await this.userService.getEmail();
|
|
const key = this.cryptoService.makeKey(this.masterPassword, email);
|
|
const keyHash = await this.cryptoService.hashPassword(this.masterPassword, key);
|
|
const storedKeyHash = await this.cryptoService.getKeyHash();
|
|
|
|
if (storedKeyHash != null && keyHash != null && storedKeyHash === keyHash) {
|
|
await this.cryptoService.setKey(key);
|
|
this.messagingService.send('unlocked');
|
|
this.$state.go('tabs.current');
|
|
} else {
|
|
this.toastr.error(this.i18nService.invalidMasterPassword, this.i18nService.errorsOccurred);
|
|
}
|
|
}
|
|
}
|
|
|
|
export const LockComponent = {
|
|
bindings: {},
|
|
controller: LockController,
|
|
template: template,
|
|
};
|