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