add error on incorrect password while importing
This commit is contained in:
parent
7b2f227bcc
commit
6feb2a2176
3 changed files with 49 additions and 44 deletions
|
|
@ -6,7 +6,15 @@ angular.module('copay.import').controller('ImportController',
|
|||
var reader = new FileReader();
|
||||
var _importBackup = function(encryptedObj) {
|
||||
Passphrase.getBase64Async($scope.password, function(passphrase){
|
||||
$rootScope.wallet = walletFactory.fromEncryptedObj(encryptedObj, passphrase);
|
||||
var w = walletFactory.fromEncryptedObj(encryptedObj, passphrase);
|
||||
if (!w) {
|
||||
$scope.loading = false;
|
||||
$rootScope.$flashMessage = { message: 'Wrong password', type: 'error'};
|
||||
$rootScope.$digest();
|
||||
return;
|
||||
}
|
||||
$rootScope.wallet = w;
|
||||
|
||||
controllerUtils.startNetwork($rootScope.wallet);
|
||||
});
|
||||
};
|
||||
|
|
@ -23,6 +31,7 @@ angular.module('copay.import').controller('ImportController',
|
|||
|
||||
$scope.import = function(form) {
|
||||
if (form.$invalid) {
|
||||
$scope.loading = false;
|
||||
$rootScope.$flashMessage = { message: 'There is an error in the form. Please, try again', type: 'error'};
|
||||
return;
|
||||
}
|
||||
|
|
@ -32,6 +41,7 @@ angular.module('copay.import').controller('ImportController',
|
|||
var password = form.password.$modelValue;
|
||||
|
||||
if (!backupFile && !backupText) {
|
||||
$scope.loading = false;
|
||||
$rootScope.$flashMessage = { message: 'Please, select your backup file or paste the text', type: 'error'};
|
||||
return;
|
||||
}
|
||||
|
|
|
|||
|
|
@ -39,14 +39,11 @@ WalletFactory.prototype.log = function(){
|
|||
WalletFactory.prototype._checkRead = function(walletId) {
|
||||
var s = this.storage;
|
||||
var ret =
|
||||
(
|
||||
s.get(walletId, 'publicKeyRing') &&
|
||||
s.get(walletId, 'txProposals') &&
|
||||
s.get(walletId, 'opts') &&
|
||||
s.get(walletId, 'privateKey')
|
||||
)?true:false;
|
||||
;
|
||||
return ret?true:false;
|
||||
s.get(walletId, 'privateKey');
|
||||
return ret;
|
||||
};
|
||||
|
||||
WalletFactory.prototype.fromObj = function(obj) {
|
||||
|
|
@ -60,14 +57,15 @@ WalletFactory.prototype.fromObj = function(obj) {
|
|||
WalletFactory.prototype.fromEncryptedObj = function(base64, password) {
|
||||
this.storage._setPassphrase(password);
|
||||
var walletObj = this.storage.import(base64);
|
||||
if (!walletObj) return null;
|
||||
var w = this.fromObj(walletObj);
|
||||
w.store();
|
||||
if (!w) return null;
|
||||
return w;
|
||||
};
|
||||
|
||||
WalletFactory.prototype.read = function(walletId) {
|
||||
if (! this._checkRead(walletId))
|
||||
return false;
|
||||
return null;
|
||||
|
||||
var obj = {};
|
||||
var s = this.storage;
|
||||
|
|
@ -149,7 +147,6 @@ WalletFactory.prototype.open = function(walletId, opts) {
|
|||
|
||||
var w = this.read(walletId);
|
||||
|
||||
|
||||
if (w) {
|
||||
this._checkVersion(w.version);
|
||||
w.store();
|
||||
|
|
|
|||
|
|
@ -3,6 +3,7 @@
|
|||
var imports = require('soop').imports();
|
||||
|
||||
var id = 0;
|
||||
|
||||
function Storage(opts) {
|
||||
opts = opts || {};
|
||||
|
||||
|
|
@ -34,11 +35,15 @@ Storage.prototype._encryptObj = function(obj) {
|
|||
|
||||
Storage.prototype._decrypt = function(base64) {
|
||||
var decryptedStr = null;
|
||||
try {
|
||||
var decrypted = CryptoJS.AES.decrypt(base64, this._getPassphrase());
|
||||
|
||||
if (decrypted)
|
||||
decryptedStr = decrypted.toString(CryptoJS.enc.Utf8);
|
||||
|
||||
} catch (e) {
|
||||
console.log('Error while decrypting ' + base64);
|
||||
return null;
|
||||
}
|
||||
return decryptedStr;
|
||||
};
|
||||
|
||||
|
|
@ -49,18 +54,12 @@ Storage.prototype._decryptObj = function(base64) {
|
|||
|
||||
Storage.prototype._read = function(k) {
|
||||
var ret;
|
||||
try {
|
||||
ret = localStorage.getItem(k);
|
||||
if (ret){
|
||||
if (!ret) return null;
|
||||
ret = this._decrypt(ret);
|
||||
if (!ret) return null;
|
||||
ret = ret.toString(CryptoJS.enc.Utf8);
|
||||
ret = JSON.parse(ret);
|
||||
}
|
||||
} catch (e) {
|
||||
console.log('Error while decrypting: '+e);
|
||||
return null;
|
||||
};
|
||||
|
||||
return ret;
|
||||
};
|
||||
|
||||
|
|
@ -93,7 +92,6 @@ Storage.prototype._key = function(walletId, k) {
|
|||
// get value by key
|
||||
Storage.prototype.get = function(walletId, k) {
|
||||
var ret = this._read(this._key(walletId, k));
|
||||
|
||||
return ret;
|
||||
};
|
||||
|
||||
|
|
|
|||
Loading…
Add table
Add a link
Reference in a new issue