refactor identityService

This commit is contained in:
Gustavo Maximiliano Cortez 2014-10-24 11:58:22 -03:00
commit ad87c4fc56
3 changed files with 26 additions and 20 deletions

View file

@ -4,7 +4,7 @@ angular.module('copayApp.controllers').controller('CreateProfileController', fun
controllerUtils.redirIfLogged();
$scope.retreiving = true;
identityService.checkIdentity($scope);
identityService.check($scope);
$scope.createProfile = function(form) {
if (form && form.$invalid) {
@ -12,7 +12,7 @@ angular.module('copayApp.controllers').controller('CreateProfileController', fun
return;
}
$scope.loading = true;
identityService.createIdentity($scope, form);
identityService.create($scope, form);
}
});

View file

@ -4,7 +4,7 @@ angular.module('copayApp.controllers').controller('HomeController', function($sc
controllerUtils.redirIfLogged();
$scope.retreiving = true;
identityService.checkIdentity($scope);
identityService.check($scope);
$scope.openProfile = function(form) {
if (form && form.$invalid) {
@ -12,20 +12,6 @@ angular.module('copayApp.controllers').controller('HomeController', function($sc
return;
}
$scope.loading = true;
copay.Identity.open(form.email.$modelValue, form.password.$modelValue, {
pluginManager: pluginManager,
network: config.network,
networkName: config.networkName,
walletDefaults: config.wallet,
passphraseConfig: config.passphraseConfig,
}, function(err, iden, lastFocusedWallet) {
if (err && !iden) {
console.log('Error:' + err)
controllerUtils.onErrorDigest(
$scope, (err.toString() || '').match('PNOTFOUND') ? 'Profile not found' : 'Unknown error');
} else {
controllerUtils.bindProfile($scope, iden, lastFocusedWallet);
}
});
identityService.open($scope, form);
}
});

View file

@ -4,7 +4,7 @@ angular.module('copayApp.services')
.factory('identityService', function($rootScope, $location, pluginManager, controllerUtils) {
var root = {};
root.checkIdentity = function (scope) {
root.check = function (scope) {
copay.Identity.anyProfile({
pluginManager: pluginManager,
}, function(anyProfile) {
@ -22,7 +22,7 @@ angular.module('copayApp.services')
});
};
root.createIdentity = function (scope, form) {
root.create = function (scope, form) {
copay.Identity.create(form.email.$modelValue, form.password.$modelValue, {
pluginManager: pluginManager,
network: config.network,
@ -35,6 +35,26 @@ angular.module('copayApp.services')
});
};
root.open = function (scope, form) {
copay.Identity.open(form.email.$modelValue, form.password.$modelValue, {
pluginManager: pluginManager,
network: config.network,
networkName: config.networkName,
walletDefaults: config.wallet,
passphraseConfig: config.passphraseConfig,
}, function(err, iden, lastFocusedWallet) {
if (err && !iden) {
console.log('Error:' + err)
controllerUtils.onErrorDigest(
scope, (err.toString() || '').match('PNOTFOUND') ? 'Profile not found' : 'Unknown error');
} else {
controllerUtils.bindProfile(scope, iden, lastFocusedWallet);
}
scope.loading = false;
});
}
return root;
});