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="header">
<div class="right"> <div class="right">
<button type="submit" class="btn btn-link">{{$ctrl.i18n.submit}}</button> <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"> <div class="list-section-item list-section-item-icon-input">
<i class="fa fa-lock fa-lg fa-fw"></i> <i class="fa fa-lock fa-lg fa-fw"></i>
<label for="master-password" class="sr-only">{{$ctrl.i18n.masterPass}}</label> <label for="master-password" class="sr-only">{{$ctrl.i18n.masterPass}}</label>
<input id="master-password" type="password" name="MasterPassword" placeholder="{{$ctrl.i18n.masterPass}}" <input id="master-password" type="password" name="MasterPassword"
ng-model="masterPassword"> placeholder="{{$ctrl.i18n.masterPass}}" ng-model="$ctrl.masterPassword">
</div> </div>
</div> </div>
</div> </div>

View File

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

View File

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