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: {
url: 'https://test-insight.bitpay.com:443/api/email'
// url: 'http://localhost:3001/api/email'
},
GoogleDrive: {

View File

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

View File

@ -9,13 +9,15 @@ inherits(EncryptedInsightStorage, InsightStorage);
EncryptedInsightStorage.prototype.getItem = function(name, callback) {
var key = cryptoUtil.kdf(this.password, this.email);
InsightStorage.prototype.getItem.apply(this, [name, function(err, body) {
var decryptedJson = cryptoUtil.decrypt(key, body);
if (!decryptedJson) {
return callback('Internal Error');
InsightStorage.prototype.getItem.apply(this, [name,
function(err, body) {
var decryptedJson = cryptoUtil.decrypt(key, body);
if (!decryptedJson) {
return callback('Internal Error');
}
return callback(null, decryptedJson);
}
return callback(null, decryptedJson);
}]);
]);
};
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]);
};
EncryptedInsightStorage.prototype.removeItem = function(name, callback) {
var key = cryptoUtil.kdf(this.password, this.email);
InsightStorage.prototype.removeItem.apply(this, [name, callback]);
};
module.exports = EncryptedInsightStorage;

View File

@ -1,48 +1,47 @@
'use strict';
angular.module('copayApp.services')
.factory('identityService', function($rootScope, $location, pluginManager, controllerUtils) {
var root = {};
.factory('identityService', function($rootScope, $location, pluginManager, controllerUtils) {
var root = {};
root.create = function (scope, form) {
copay.Identity.create({
email: form.email.$modelValue,
password: form.password.$modelValue,
pluginManager: pluginManager,
network: config.network,
networkName: config.networkName,
walletDefaults: config.wallet,
passphraseConfig: config.passphraseConfig,
}, function(err, iden) {
var firstWallet = iden.getLastFocusedWallet();
controllerUtils.bindProfile(scope, iden, firstWallet);
scope.loading = false;
});
};
root.open = function (scope, form) {
copay.Identity.open({
email: form.email.$modelValue,
password: form.password.$modelValue,
pluginManager: pluginManager,
network: config.network,
networkName: config.networkName,
walletDefaults: config.wallet,
passphraseConfig: config.passphraseConfig,
}, function(err, iden) {
if (err && !iden) {
console.log('Error:' + err)
controllerUtils.onErrorDigest(
scope, (err.toString() || '').match('PNOTFOUND') ? 'Profile not found' : 'Unknown error');
} else {
root.create = function(scope, form) {
copay.Identity.create({
email: form.email.$modelValue,
password: form.password.$modelValue,
pluginManager: pluginManager,
network: config.network,
networkName: config.networkName,
walletDefaults: config.wallet,
passphraseConfig: config.passphraseConfig,
}, function(err, iden) {
var firstWallet = iden.getLastFocusedWallet();
controllerUtils.bindProfile(scope, iden, firstWallet);
}
scope.loading = false;
});
}
scope.loading = false;
});
};
return root;
});
root.open = function(scope, form) {
copay.Identity.open({
email: form.email.$modelValue,
password: form.password.$modelValue,
pluginManager: pluginManager,
network: config.network,
networkName: config.networkName,
walletDefaults: config.wallet,
passphraseConfig: config.passphraseConfig,
}, function(err, iden) {
if (err && !iden) {
console.log('Error:' + err)
controllerUtils.onErrorDigest(
scope, (err.toString() || '').match('PNOTFOUND') ? 'Profile not found' : 'Unknown error');
} else {
var firstWallet = iden.getLastFocusedWallet();
controllerUtils.bindProfile(scope, iden, firstWallet);
}
scope.loading = false;
});
}
return root;
});