1
0
mirror of https://github.com/bitwarden/browser synced 2025-12-17 16:53:34 +00:00

Rewrite lock module to TypeScript. (#354)

This commit is contained in:
Oscar Hinton
2017-11-03 21:40:44 +01:00
committed by Kyle Spearrin
parent e250d9b658
commit 8ae178aff3
7 changed files with 71 additions and 59 deletions

View File

@@ -0,0 +1,53 @@
import CryptoService from '../../../services/crypto.service';
import UserService from '../../../services/user.service';
import * as template from './lock.component.html';
class LockController {
i18n: any;
constructor(public $scope: any, public $state: any, public i18nService: any,
public cryptoService: CryptoService, public toastr: any, public userService: UserService,
public SweetAlert: any, public $timeout: any) {
this.i18n = i18nService;
$timeout(() => {
document.getElementById('master-password').focus();
});
}
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) {
chrome.runtime.sendMessage({ command: 'logout' });
}
});
}
async submit() {
const email = await this.userService.getEmail();
const key = this.cryptoService.makeKey(this.$scope.masterPassword, email);
const keyHash = await this.cryptoService.hashPassword(this.$scope.masterPassword, key);
const storedKeyHash = await this.cryptoService.getKeyHash();
if (storedKeyHash && keyHash && storedKeyHash === keyHash) {
await this.cryptoService.setKey(key);
chrome.runtime.sendMessage({ command: 'unlocked' });
this.$state.go('tabs.current');
} else {
this.toastr.error(this.i18nService.invalidMasterPassword, this.i18nService.errorsOccurred);
}
}
}
export const LockComponent = {
bindings: {},
controller: LockController,
template,
};