Simplified controllers with identityService
This commit is contained in:
parent
3c8caacc92
commit
ebe415a3d6
4 changed files with 46 additions and 26 deletions
|
|
@ -1,23 +1,10 @@
|
||||||
'use strict';
|
'use strict';
|
||||||
|
|
||||||
angular.module('copayApp.controllers').controller('CreateProfileController', function($scope, $rootScope, $location, notification, controllerUtils, pluginManager) {
|
angular.module('copayApp.controllers').controller('CreateProfileController', function($scope, $rootScope, $location, notification, controllerUtils, pluginManager, identityService) {
|
||||||
controllerUtils.redirIfLogged();
|
controllerUtils.redirIfLogged();
|
||||||
$scope.retreiving = true;
|
$scope.retreiving = true;
|
||||||
|
|
||||||
|
identityService.checkIdentity($scope);
|
||||||
copay.Identity.anyProfile({
|
|
||||||
pluginManager: pluginManager,
|
|
||||||
}, function(anyProfile) {
|
|
||||||
copay.Identity.anyWallet({
|
|
||||||
pluginManager: pluginManager,
|
|
||||||
}, function(anyWallet) {
|
|
||||||
$scope.retreiving = false;
|
|
||||||
$scope.anyProfile = anyProfile;
|
|
||||||
$scope.anyWallet = anyWallet;
|
|
||||||
});
|
|
||||||
|
|
||||||
});
|
|
||||||
|
|
||||||
|
|
||||||
$scope.createProfile = function(form) {
|
$scope.createProfile = function(form) {
|
||||||
if (form && form.$invalid) {
|
if (form && form.$invalid) {
|
||||||
|
|
@ -25,15 +12,7 @@ angular.module('copayApp.controllers').controller('CreateProfileController', fun
|
||||||
return;
|
return;
|
||||||
}
|
}
|
||||||
$scope.loading = true;
|
$scope.loading = true;
|
||||||
copay.Identity.create(form.email.$modelValue, form.password.$modelValue, {
|
identityService.createIdentity($scope, form);
|
||||||
pluginManager: pluginManager,
|
|
||||||
network: config.network,
|
|
||||||
networkName: config.networkName,
|
|
||||||
walletDefaults: config.wallet,
|
|
||||||
passphraseConfig: config.passphraseConfig,
|
|
||||||
}, function(err, iden, firstWallet) {
|
|
||||||
controllerUtils.bindProfile($scope, iden, firstWallet);
|
|
||||||
});
|
|
||||||
}
|
}
|
||||||
|
|
||||||
});
|
});
|
||||||
|
|
|
||||||
|
|
@ -1,9 +1,10 @@
|
||||||
'use strict';
|
'use strict';
|
||||||
|
|
||||||
angular.module('copayApp.controllers').controller('HomeController', function($scope, $rootScope, $location, notification, controllerUtils, pluginManager) {
|
angular.module('copayApp.controllers').controller('HomeController', function($scope, $rootScope, $location, notification, controllerUtils, pluginManager, identityService) {
|
||||||
controllerUtils.redirIfLogged();
|
controllerUtils.redirIfLogged();
|
||||||
|
$scope.retreiving = true;
|
||||||
|
|
||||||
$scope.retreiving = false;
|
identityService.checkIdentity($scope);
|
||||||
|
|
||||||
$scope.openProfile = function(form) {
|
$scope.openProfile = function(form) {
|
||||||
if (form && form.$invalid) {
|
if (form && form.$invalid) {
|
||||||
|
|
|
||||||
40
js/services/identityService.js
Normal file
40
js/services/identityService.js
Normal file
|
|
@ -0,0 +1,40 @@
|
||||||
|
'use strict';
|
||||||
|
|
||||||
|
angular.module('copayApp.services')
|
||||||
|
.factory('identityService', function($rootScope, $location, pluginManager, controllerUtils) {
|
||||||
|
var root = {};
|
||||||
|
|
||||||
|
root.checkIdentity = function (scope) {
|
||||||
|
copay.Identity.anyProfile({
|
||||||
|
pluginManager: pluginManager,
|
||||||
|
}, function(anyProfile) {
|
||||||
|
copay.Identity.anyWallet({
|
||||||
|
pluginManager: pluginManager,
|
||||||
|
}, function(anyWallet) {
|
||||||
|
scope.retreiving = false;
|
||||||
|
scope.anyProfile = anyProfile ? true : false;
|
||||||
|
scope.anyWallet = anyWallet ? true : false;
|
||||||
|
|
||||||
|
if (!scope.anyProfile) {
|
||||||
|
$location.path('/createProfile');
|
||||||
|
}
|
||||||
|
});
|
||||||
|
});
|
||||||
|
};
|
||||||
|
|
||||||
|
root.createIdentity = function (scope, form) {
|
||||||
|
copay.Identity.create(form.email.$modelValue, form.password.$modelValue, {
|
||||||
|
pluginManager: pluginManager,
|
||||||
|
network: config.network,
|
||||||
|
networkName: config.networkName,
|
||||||
|
walletDefaults: config.wallet,
|
||||||
|
passphraseConfig: config.passphraseConfig,
|
||||||
|
}, function(err, iden, firstWallet) {
|
||||||
|
controllerUtils.bindProfile(scope, iden, firstWallet);
|
||||||
|
scope.loading = false;
|
||||||
|
});
|
||||||
|
};
|
||||||
|
|
||||||
|
return root;
|
||||||
|
});
|
||||||
|
|
||||||
Loading…
Add table
Add a link
Reference in a new issue