copay/js/services/identityService.js

67 lines
2.0 KiB
JavaScript
Raw Normal View History

'use strict';
angular.module('copayApp.services')
2014-10-27 07:10:32 -07:00
.factory('identityService', function($rootScope, $location, pluginManager, controllerUtils) {
var root = {};
2014-10-27 07:10:32 -07:00
root.create = function(scope, form) {
var iden = copay.Identity.create({
2014-10-27 07:10:32 -07:00
email: form.email.$modelValue,
password: form.password.$modelValue,
pluginManager: pluginManager,
network: config.network,
networkName: config.networkName,
walletDefaults: config.wallet,
passphraseConfig: config.passphraseConfig,
});
var walletOptions = {
nickname: iden.fullName,
networkName: config.networkName,
requiredCopayers: 1,
totalCopayers: 1,
password: iden.password,
name: 'My wallet',
};
iden.createWallet(walletOptions, function(err, wallet) {
if (err) {
controllerUtils.onErrorDigest(
scope, 'Could not create default wallet');
} else {
iden.store({failIfExists: true}, function(err) {
if (err) {
controllerUtils.onErrorDigest(scope, 'User already exists!');
} else {
controllerUtils.bindProfile(scope, iden, wallet.id);
}
});
}
2014-10-27 07:10:32 -07:00
scope.loading = false;
});
};
2014-10-24 07:58:22 -07:00
2014-10-27 07:10:32 -07:00
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) {
controllerUtils.onErrorDigest(
scope, (err.toString() || '').match('PNOTFOUND') ? 'Invalid email or password' : 'Unknown error');
2014-10-27 07:10:32 -07:00
} else {
var firstWallet = iden.getLastFocusedWallet();
controllerUtils.bindProfile(scope, iden, firstWallet);
}
scope.loading = false;
});
};
2014-10-27 07:10:32 -07:00
return root;
});