login working on the UX
This commit is contained in:
parent
7a2906c8d1
commit
92f1bacf82
10 changed files with 125 additions and 72 deletions
|
|
@ -98,6 +98,13 @@ Identity._walletDelete = function(id, cb) {
|
|||
return Wallet.delete(id, cb);
|
||||
};
|
||||
|
||||
/* for stubbing */
|
||||
Identity._openProfile = function(email, password, storage, cb) {
|
||||
Profile.open(email, password, storage, cb);
|
||||
};
|
||||
|
||||
|
||||
|
||||
/**
|
||||
* creates and Identity
|
||||
*
|
||||
|
|
@ -160,10 +167,14 @@ Identity.prototype.validate = function(authcode, cb) {
|
|||
Identity.open = function(email, password, opts, cb) {
|
||||
var iden = new Identity(email, password, opts);
|
||||
|
||||
Identity._createProfile(email, password, iden.storage, function(err, profile) {
|
||||
Identity._openProfile(email, password, iden.storage, function(err, profile) {
|
||||
if (err) return cb(err);
|
||||
iden.profile = profile;
|
||||
return cb(null, iden);
|
||||
var wid = iden.listWallets()[0].id;
|
||||
iden.openWallet(wid, password, function(err, w) {
|
||||
return cb(err, iden, w);
|
||||
})
|
||||
|
||||
});
|
||||
};
|
||||
|
||||
|
|
@ -217,15 +228,17 @@ Identity.prototype.store = function(opts, cb) {
|
|||
Identity.prototype.close = function(cb) {
|
||||
preconditions.checkState(this.profile);
|
||||
|
||||
var l = self.openWallets.length,
|
||||
var l = this.openWallets.length,
|
||||
i = 0;
|
||||
if (!l) return cb();
|
||||
if (!l) {
|
||||
return cb ? cb() : null;
|
||||
}
|
||||
|
||||
_.each(self.openWallets, function(w) {
|
||||
_.each(this.openWallets, function(w) {
|
||||
w.close(function(err) {
|
||||
if (err) return cb(err);
|
||||
|
||||
if (++i == l)
|
||||
if (++i == l && cb)
|
||||
return cb();
|
||||
})
|
||||
});
|
||||
|
|
@ -390,18 +403,19 @@ Identity.prototype.openWallet = function(walletId, password, cb) {
|
|||
var self = this;
|
||||
|
||||
self.storage.setPassword(password);
|
||||
self.migrateWallet(walletId, password, function() {
|
||||
// TODO
|
||||
// self.migrateWallet(walletId, password, function() {
|
||||
|
||||
Identity._walletRead(walletId, self.storage, self.networks, self.blockchains, [], function(err, w) {
|
||||
if (err) return cb(err);
|
||||
Identity._walletRead(walletId, self.storage, self.networks, self.blockchains, [], function(err, w) {
|
||||
if (err) return cb(err);
|
||||
|
||||
w.store(function(err) {
|
||||
self.profile.setLastOpenedTs(walletId, function() {
|
||||
return cb(err, w);
|
||||
});
|
||||
w.store(function(err) {
|
||||
self.profile.setLastOpenedTs(walletId, function() {
|
||||
return cb(err, w);
|
||||
});
|
||||
});
|
||||
});
|
||||
// });
|
||||
};
|
||||
|
||||
|
||||
|
|
|
|||
|
|
@ -13,9 +13,9 @@ function Profile(info, storage) {
|
|||
this.hash = info.hash;
|
||||
this.email = info.email;
|
||||
this.extra = info.extra;
|
||||
this.walletInfos = info.walletInfos || {};
|
||||
|
||||
this.key = Profile.key(this.hash);
|
||||
this.walletInfos = {};
|
||||
this.storage = storage;
|
||||
};
|
||||
|
||||
|
|
@ -36,29 +36,31 @@ Profile.create = function(email, password, storage, cb) {
|
|||
|
||||
var p = new Profile({
|
||||
email: email,
|
||||
hash: Profile.hash(email,password),
|
||||
hash: Profile.hash(email, password),
|
||||
}, storage);
|
||||
p.store({}, function(err) {
|
||||
return cb(err,p);
|
||||
return cb(err, p);
|
||||
});
|
||||
};
|
||||
|
||||
Profile.open = function(email, password, storage, cb) {
|
||||
preconditions.checkArgument(cb);
|
||||
preconditions.checkState(storage.hasPassphrase());
|
||||
|
||||
var key = Profile.key(Profile.hash(email, password));
|
||||
storage.getGlobal(key, function(err, val) {
|
||||
if (err) return cb(err);
|
||||
|
||||
if (!val)
|
||||
storage.get(key, function(err, val) {
|
||||
if (err || !val)
|
||||
return cb(new Error('PNOTFOUND: Profile not found'));
|
||||
|
||||
return cb(new Profile(val, storage));
|
||||
if (!val.email)
|
||||
return cb(new Error('PERROR: Could not open profile'));
|
||||
|
||||
return cb(null, new Profile(val, storage));
|
||||
});
|
||||
};
|
||||
|
||||
Profile.prototype.toObj = function() {
|
||||
return JSON.parse(JSON.stringify(this));
|
||||
return _.clone(_.pick(this, 'hash', 'email', 'extra', 'walletInfos'));
|
||||
};
|
||||
|
||||
Profile.prototype.getWallet = function(walletId, cb) {
|
||||
|
|
@ -74,7 +76,7 @@ Profile.prototype.listWallets = function(opts, cb) {
|
|||
|
||||
Profile.prototype.deleteWallet = function(walletId, cb) {
|
||||
if (!this.walletInfos[walletId])
|
||||
return cb(new Error('WNOEXIST: Wallet not on profile'));
|
||||
return cb(new Error('WNOEXIST: Wallet not on profile '));
|
||||
|
||||
delete this.walletInfos[walletId];
|
||||
|
||||
|
|
@ -85,7 +87,7 @@ Profile.prototype.deleteWallet = function(walletId, cb) {
|
|||
|
||||
Profile.prototype.addToWallet = function(walletId, info, cb) {
|
||||
if (!this.walletInfos[walletId])
|
||||
return cb(new Error('WNOEXIST: Wallet not on profile'));
|
||||
return cb(new Error('WNOEXIST: Wallet not on profile '));
|
||||
|
||||
this.walletInfos[walletId] = _.extend(this.walletInfos[walletId], info);
|
||||
|
||||
|
|
@ -100,7 +102,7 @@ Profile.prototype.addWallet = function(walletId, info, cb) {
|
|||
preconditions.checkArgument(cb);
|
||||
|
||||
if (this.walletInfos[walletId])
|
||||
return cb(new Error('WEXIST: Wallet already on profile'));
|
||||
return cb(new Error('WEXIST: Wallet already on profile '));
|
||||
|
||||
this.walletInfos[walletId] = _.extend(info, {
|
||||
createdTs: Date.now(),
|
||||
|
|
@ -128,7 +130,7 @@ Profile.prototype.store = function(opts, cb) {
|
|||
|
||||
if (val2 && !opts.overwrite) {
|
||||
if (cb)
|
||||
return cb(new Error('PEXISTS: Profile already exist'))
|
||||
return cb(new Error('PEXISTS: Profile already exist '))
|
||||
} else {
|
||||
self.storage.set(key, val, function(err) {
|
||||
log.debug('Profile stored');
|
||||
|
|
|
|||
|
|
@ -89,7 +89,7 @@ Storage.prototype._read = function(k, cb) {
|
|||
var self = this;
|
||||
this.db.getItem(k, function(ret) {
|
||||
if (!ret) return cb(null);
|
||||
var ret = self._decrypt(ret);
|
||||
ret = self._decrypt(ret);
|
||||
if (!ret) return cb(null);
|
||||
|
||||
ret = ret.toString(CryptoJS.enc.Utf8);
|
||||
|
|
|
|||
|
|
@ -71,6 +71,7 @@ function Wallet(opts) {
|
|||
self[k] = opts[k];
|
||||
});
|
||||
|
||||
|
||||
this.id = opts.id || Wallet.getRandomId();
|
||||
this.secretNumber = opts.secretNumber || Wallet.getRandomNumber();
|
||||
this.lock = new WalletLock(this.storage, this.id, opts.lockTimeOutMin);
|
||||
|
|
@ -94,10 +95,12 @@ function Wallet(opts) {
|
|||
|
||||
this.paymentRequests = opts.paymentRequests || {};
|
||||
|
||||
var networkName = Wallet.obtainNetworkName(opts);
|
||||
this.network = networkName && this.network[networkName] ? this.network[networkName] : this.network;
|
||||
this.blockchain = networkName && this.blockchain[networkName] ? this.blockchain[networkName] : this.blockchain;
|
||||
|
||||
var networkName = Wallet.obtainNetworkName(this);
|
||||
this.network = _.isArray(this.network)? this.network[networkName] : this.network;
|
||||
this.blockchain = _.isArray(this.blockchain) ? this.blockchain[networkName] : this.blockchain;
|
||||
preconditions.checkArgument(this.network.setHexNonce, 'Incorrect network parameter');
|
||||
preconditions.checkArgument(this.blockchain.getTransaction, 'Incorrect blockchain parameter');
|
||||
|
||||
|
||||
this.network.maxPeers = this.totalCopayers;
|
||||
|
|
@ -217,8 +220,9 @@ Wallet.delete = function(walletId, storage, cb) {
|
|||
* @param {function} callback - {err, Wallet}
|
||||
* @return {undefined}
|
||||
*/
|
||||
Wallet.read = function(walletId, storage, network, blockchain, skipFields, cb) {
|
||||
Wallet.read = function(walletId, storage, network, blockchain, skipFields, cb) {
|
||||
preconditions.checkArgument(cb);
|
||||
preconditions.checkArgument(storage.setPassword);
|
||||
|
||||
var self = this,
|
||||
err;
|
||||
|
|
@ -237,10 +241,12 @@ Wallet.read = function(walletId, storage, network, blockchain, skipFields, cb)
|
|||
var w, err;
|
||||
obj.id = walletId;
|
||||
try {
|
||||
console.log('[Wallet.js.218:network:]',network); //TODO
|
||||
w = self.fromObj(obj, storage, network, blockchain, skipFields);
|
||||
} catch (e) {
|
||||
log.debug("ERROR: ", e.message);
|
||||
if (e && e.message && e.message.indexOf('MISSOPTS')) {
|
||||
err = new Error('WERROR: Could not read: ' + walletId);
|
||||
err = new Error('WERROR: Could not read: ' + walletId + ': ' + e.message);
|
||||
} else {
|
||||
err = e;
|
||||
}
|
||||
|
|
@ -1637,6 +1643,7 @@ Wallet.prototype.sendPaymentTx = function(ntxid, options, cb) {
|
|||
options = {};
|
||||
}
|
||||
|
||||
console.log('[Wallet.js.1613:ntxid:]',ntxid); //TODO
|
||||
var txp = this.txProposals.get(ntxid);
|
||||
if (!txp) return;
|
||||
|
||||
|
|
|
|||
Loading…
Add table
Add a link
Reference in a new issue