1
0
mirror of https://github.com/bitwarden/desktop.git synced 2024-11-17 10:45:41 +01:00

check for errors and remove scope dependency

This commit is contained in:
Kyle Spearrin 2017-11-14 11:38:21 -05:00
parent 00b8a3e7be
commit 0c8dc0c3ec
4 changed files with 38 additions and 25 deletions

View File

@ -1,4 +1,4 @@
<form name="theForm" ng-submit="$ctrl.submit()" bit-form="submitPromise">
<form name="theForm" ng-submit="$ctrl.submit()">
<div class="header">
<div class="right">
<button type="submit" class="btn btn-link">{{$ctrl.i18n.submit}}</button>
@ -12,8 +12,8 @@
<div class="list-section-item list-section-item-icon-input">
<i class="fa fa-lock fa-lg fa-fw"></i>
<label for="master-password" class="sr-only">{{$ctrl.i18n.masterPass}}</label>
<input id="master-password" type="password" name="MasterPassword" placeholder="{{$ctrl.i18n.masterPass}}"
ng-model="masterPassword">
<input id="master-password" type="password" name="MasterPassword"
placeholder="{{$ctrl.i18n.masterPass}}" ng-model="$ctrl.masterPassword">
</div>
</div>
</div>

View File

@ -4,15 +4,16 @@ import { CryptoService } from '../../../services/abstractions/crypto.service';
class LockController {
i18n: any;
masterPassword: string;
constructor(public $scope: any, public $state: any, public i18nService: any,
public cryptoService: CryptoService, public toastr: any, public userService: any,
public SweetAlert: any, public $timeout: any) {
constructor(public $state: any, public i18nService: any,
public cryptoService: CryptoService, public toastr: any, public userService: any,
public SweetAlert: any) {
this.i18n = i18nService;
}
$timeout(() => {
document.getElementById('master-password').focus();
});
$onInit() {
document.getElementById('master-password').focus();
}
logOut() {
@ -30,12 +31,17 @@ class LockController {
}
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.$scope.masterPassword, email);
const keyHash = await this.cryptoService.hashPassword(this.$scope.masterPassword, key);
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 && keyHash && storedKeyHash === keyHash) {
if (storedKeyHash != null && keyHash != null && storedKeyHash === keyHash) {
await this.cryptoService.setKey(key);
chrome.runtime.sendMessage({ command: 'unlocked' });
this.$state.go('tabs.current');

View File

@ -1,4 +1,4 @@
<form name="theForm" ng-submit="$ctrl.submit()" bit-form="submitPromise">
<form name="theForm" ng-submit="$ctrl.submit()">
<div class="header">
<div class="left">
<a ui-sref="tabs.tools({animation: 'out-slide-down'})">{{$ctrl.i18n.close}}</a>

View File

@ -11,28 +11,35 @@ export class ExportController {
i18n: any;
masterPassword: string;
constructor(private $scope: any, private $state: any, private cryptoService: CryptoService,
constructor(private $state: any, private cryptoService: CryptoService,
private toastr: any, private utilsService: UtilsService, private $analytics: any,
private i18nService: any, private folderService: any, private cipherService: any,
private $window: any, private userService: any) {
this.i18n = i18nService;
this.$scope.submitPromise = null;
}
$onInit() {
document.getElementById('master-password').focus();
}
submit() {
const self = this;
this.$scope.submitPromise = this.checkPassword().then(() => {
return self.getCsv();
}).then((csv) => {
self.$analytics.eventTrack('Exported Data');
self.downloadFile(csv);
}, () => {
this.toastr.error(self.i18n.invalidMasterPassword, self.i18n.errorsOccurred);
});
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) {
const csv = await this.getCsv();
this.$analytics.eventTrack('Exported Data');
this.downloadFile(csv);
} else {
this.toastr.error(this.i18n.invalidMasterPassword, this.i18n.errorsOccurred);
}
}
private async checkPassword() {