From ab9be793cb4fbaafe2431b918f1d455e4ea689c1 Mon Sep 17 00:00:00 2001 From: Gustavo Cortez Date: Tue, 6 May 2014 17:57:16 -0300 Subject: [PATCH] Fix signing when put a wrong password. Fixes #297 --- js/controllers/signin.js | 5 +++++ js/models/core/WalletFactory.js | 10 +++++++--- js/models/storage/LocalEncrypted.js | 2 +- 3 files changed, 13 insertions(+), 4 deletions(-) diff --git a/js/controllers/signin.js b/js/controllers/signin.js index 04eedc1c7..0b9bbb49b 100644 --- a/js/controllers/signin.js +++ b/js/controllers/signin.js @@ -21,6 +21,11 @@ angular.module('copay.signin').controller('SigninController', var passphrase = Passphrase.getBase64($scope.openPassword); var w = walletFactory.open($scope.selectedWalletId, { passphrase: passphrase}); + if (!w) { + $scope.loading = false; + $rootScope.flashMessage = { message: 'Bad password or connection error', type: 'error'}; + return; + } controllerUtils.startNetwork(w); } }; diff --git a/js/models/core/WalletFactory.js b/js/models/core/WalletFactory.js index ba6f33f85..24360f01c 100644 --- a/js/models/core/WalletFactory.js +++ b/js/models/core/WalletFactory.js @@ -138,8 +138,11 @@ WalletFactory.prototype.open = function(walletId, opts) { opts.verbose = this.verbose; this.storage._setPassphrase(opts.passphrase); - var w = this.read(walletId) || this.create(opts); - w.store(); + var w = this.read(walletId); + + if (w) { + w.store(); + } return w; }; @@ -186,7 +189,8 @@ WalletFactory.prototype.joinCreateSession = function(secret, nickname, passphras data.opts.privateKey = privateKey; data.opts.nickname = nickname; data.opts.passphrase = passphrase; - var w = self.open(data.walletId, data.opts); + data.opts.id = data.walletId; + var w = self.create(data.opts); w.firstCopayerId = s.pubKey; return cb(null, w); } diff --git a/js/models/storage/LocalEncrypted.js b/js/models/storage/LocalEncrypted.js index cfeb1d2c5..95520ebed 100644 --- a/js/models/storage/LocalEncrypted.js +++ b/js/models/storage/LocalEncrypted.js @@ -54,7 +54,7 @@ Storage.prototype._read = function(k) { } } catch (e) { console.log('Error while decrypting: '+e); - throw e; + return null; }; return ret;