Merge pull request #370 from yemel/fix/bad-secret-handling

add validation to wallet secret
This commit is contained in:
Matias Alejo Garcia 2014-05-14 19:09:10 -03:00
commit 2c24591ee3
4 changed files with 29 additions and 7 deletions

View file

@ -496,3 +496,6 @@ a.loading {
vertical-align:middle vertical-align:middle
} }
input.ng-invalid-wallet-secret {
background: #FFB6C1;
}

View file

@ -190,7 +190,7 @@
<div class="box-signin radius"> <div class="box-signin radius">
<h3>Join a Wallet in Creation</h3> <h3>Join a Wallet in Creation</h3>
<form name="joinForm" ng-submit="join(joinForm)" novalidate> <form name="joinForm" ng-submit="join(joinForm)" novalidate>
<input type="text" class="form-control" placeholder="Paste wallet secret here" name="connectionId" ng-model="connectionId" required> <input type="text" class="form-control" placeholder="Paste wallet secret here" name="connectionId" ng-model="connectionId" wallet-secret required>
<input type="password" class="form-control" placeholder="Choose your password" name="joinPassword" ng-model="joinPassword" required> <input type="password" class="form-control" placeholder="Choose your password" name="joinPassword" ng-model="joinPassword" required>
<input type="text" class="form-control" placeholder="Your name (optional)" name="nickname" ng-model="nickname"> <input type="text" class="form-control" placeholder="Your name (optional)" name="nickname" ng-model="nickname">
<button type="submit" class="button primary radius" ng-disabled="joinForm.$invalid || loading" loading="Joining">Join</button> <button type="submit" class="button primary radius" ng-disabled="joinForm.$invalid || loading" loading="Joining">Join</button>

View file

@ -64,6 +64,21 @@ angular.module('copay.directives')
}; };
} }
]) ])
.directive('walletSecret', ['walletFactory',
function(walletFactory) {
return {
require: 'ngModel',
link: function(scope, elem, attrs, ctrl) {
var validator = function(value) {
ctrl.$setValidity('walletSecret', Boolean(walletFactory.decodeSecret(value)));
return value;
};
ctrl.$parsers.unshift(validator);
}
};
}
])
.directive('loading', function() { .directive('loading', function() {
return { return {
restrict: 'A', restrict: 'A',

View file

@ -162,16 +162,20 @@ WalletFactory.prototype.remove = function(walletId) {
this.log('TODO: remove wallet contents'); this.log('TODO: remove wallet contents');
}; };
WalletFactory.prototype.decodeSecret = function(secret) {
try {
return Wallet.decodeSecret(secret);
} catch (e) {
return false;
}
}
WalletFactory.prototype.joinCreateSession = function(secret, nickname, passphrase, cb) { WalletFactory.prototype.joinCreateSession = function(secret, nickname, passphrase, cb) {
var self = this; var self = this;
var s; var s = self.decodeSecret(secret);
try { if (!s) return cb('badSecret');
s=Wallet.decodeSecret(secret);
} catch (e) {
return cb('badSecret');
}
//Create our PrivateK //Create our PrivateK
var privateKey = new PrivateKey({ networkName: this.networkName }); var privateKey = new PrivateKey({ networkName: this.networkName });