Merge pull request #34 from isocolsky/fix/identity

Fix/identity
This commit is contained in:
Matias Alejo Garcia 2014-10-27 12:03:22 -03:00
commit 3323ee7662
4 changed files with 65 additions and 51 deletions

View file

@ -62,6 +62,7 @@ var defaultConfig = {
EncryptedInsightStorage: { EncryptedInsightStorage: {
url: 'https://test-insight.bitpay.com:443/api/email' url: 'https://test-insight.bitpay.com:443/api/email'
// url: 'http://localhost:3001/api/email'
}, },
GoogleDrive: { GoogleDrive: {

View file

@ -224,12 +224,18 @@ Identity.prototype.storeWallet = function(wallet, cb) {
}; };
Identity.prototype.toObj = function() { Identity.prototype.toObj = function() {
return _.extend({walletIds: _.keys(this.wallets)}, return _.extend({
walletIds: _.keys(this.wallets)
},
_.pick(this, 'version', 'fullName', 'password', 'email')); _.pick(this, 'version', 'fullName', 'password', 'email'));
}; };
Identity.prototype.exportWithWalletInfo = function() { Identity.prototype.exportWithWalletInfo = function() {
return _.extend({wallets: _.map(this.wallets, function(wallet) { return wallet.toObj(); })}, return _.extend({
wallets: _.map(this.wallets, function(wallet) {
return wallet.toObj();
})
},
_.pick(this, 'version', 'fullName', 'password', 'email')); _.pick(this, 'version', 'fullName', 'password', 'email'));
}; };
@ -493,7 +499,7 @@ Identity.prototype.deleteWallet = function(walletId, cb) {
var self = this; var self = this;
delete this.wallets[walletId]; delete this.wallets[walletId];
this.storage.deleteItem(walletId, function(err) { this.storage.removeItem(Wallet.getStorageKey(walletId), function(err) {
if (err) { if (err) {
return cb(err); return cb(err);
} }
@ -513,6 +519,7 @@ Identity.prototype.decodeSecret = function(secret) {
}; };
Identity.prototype.getLastFocusedWallet = function() { Identity.prototype.getLastFocusedWallet = function() {
if (_.keys(this.wallets).length == 0) return;
return _.max(this.wallets, function(wallet) { return _.max(this.wallets, function(wallet) {
return wallet.lastTimestamp || 0; return wallet.lastTimestamp || 0;
}); });

View file

@ -9,13 +9,15 @@ inherits(EncryptedInsightStorage, InsightStorage);
EncryptedInsightStorage.prototype.getItem = function(name, callback) { EncryptedInsightStorage.prototype.getItem = function(name, callback) {
var key = cryptoUtil.kdf(this.password, this.email); var key = cryptoUtil.kdf(this.password, this.email);
InsightStorage.prototype.getItem.apply(this, [name, function(err, body) { InsightStorage.prototype.getItem.apply(this, [name,
function(err, body) {
var decryptedJson = cryptoUtil.decrypt(key, body); var decryptedJson = cryptoUtil.decrypt(key, body);
if (!decryptedJson) { if (!decryptedJson) {
return callback('Internal Error'); return callback('Internal Error');
} }
return callback(null, decryptedJson); return callback(null, decryptedJson);
}]); }
]);
}; };
EncryptedInsightStorage.prototype.setItem = function(name, value, callback) { EncryptedInsightStorage.prototype.setItem = function(name, value, callback) {
@ -24,4 +26,9 @@ EncryptedInsightStorage.prototype.setItem = function(name, value, callback) {
InsightStorage.prototype.setItem.apply(this, [name, record, callback]); InsightStorage.prototype.setItem.apply(this, [name, record, callback]);
}; };
EncryptedInsightStorage.prototype.removeItem = function(name, callback) {
var key = cryptoUtil.kdf(this.password, this.email);
InsightStorage.prototype.removeItem.apply(this, [name, callback]);
};
module.exports = EncryptedInsightStorage; module.exports = EncryptedInsightStorage;

View file

@ -1,10 +1,10 @@
'use strict'; 'use strict';
angular.module('copayApp.services') angular.module('copayApp.services')
.factory('identityService', function($rootScope, $location, pluginManager, controllerUtils) { .factory('identityService', function($rootScope, $location, pluginManager, controllerUtils) {
var root = {}; var root = {};
root.create = function (scope, form) { root.create = function(scope, form) {
copay.Identity.create({ copay.Identity.create({
email: form.email.$modelValue, email: form.email.$modelValue,
password: form.password.$modelValue, password: form.password.$modelValue,
@ -21,7 +21,7 @@ angular.module('copayApp.services')
}; };
root.open = function (scope, form) { root.open = function(scope, form) {
copay.Identity.open({ copay.Identity.open({
email: form.email.$modelValue, email: form.email.$modelValue,
password: form.password.$modelValue, password: form.password.$modelValue,
@ -44,5 +44,4 @@ angular.module('copayApp.services')
} }
return root; return root;
}); });