create working

This commit is contained in:
Matias Alejo Garcia 2014-12-05 14:53:54 -03:00
parent a70d04af77
commit d3726d658c
2 changed files with 38 additions and 30 deletions

View File

@ -50,7 +50,16 @@ angular.module('copayApp.controllers').controller('CreateProfileController', fun
});
};
$scope.selectStorage = function (storage) {
$scope.setStep = function(step) {
$scope.error = null;
$scope.createStep = step;
$timeout(function() {
$scope.$digest();
}, 1);
};
$scope.selectStorage = function(storage) {
$scope.useLocalstorage = storage == 'local';
$timeout(function() {
$scope.$digest();
@ -58,14 +67,11 @@ angular.module('copayApp.controllers').controller('CreateProfileController', fun
};
$scope.goToEmail = function() {
console.log('[createProfile.js.53:useLocalstorage:]', $scope.useLocalstorage); //TODO
$scope.createStep = 'email';
$scope.useEmail = !$scope.useLocalstorage;
};
$scope.setEmailOrUsername = function(form) {
console.log('[createProfile.js.53:useLocalstorage:]', $scope.useLocalstorage); //TODO
$scope.userOrEmail = $scope.useLocalstorage ? form.username.$modelValue : form.email.$modelValue;
preconditions.checkState($scope.userOrEmail);
@ -91,29 +97,23 @@ angular.module('copayApp.controllers').controller('CreateProfileController', fun
};
$scope._doCreateProfile = function(emailOrUsername, password) {
$scope._doCreateProfile = function(emailOrUsername, password, cb) {
preconditions.checkArgument(_.isString(emailOrUsername));
preconditions.checkArgument(_.isString(password));
$rootScope.hideNavigation = false;
$scope.loading = true;
identityService.create(emailOrUsername, password, function(err) {
$scope.loading = false;
$scope.error = null;
if (err) {
var msg = err.toString();
if (msg.indexOf('EEXIST') >= 0 || msg.indexOf('BADC') >= 0) {
msg = 'This profile already exists'
}
$timeout(function() {
form.password.$setViewValue('');
form.password.$render();
form.repeatpassword.$setViewValue('');
form.repeatpassword.$render();
form.$setPristine();
$scope.error = msg;
}, 1);
$scope.error = msg;
} else {
$scope.error = null;
// mobile
if ($scope.isMobile) {
_credentials = {
@ -125,38 +125,46 @@ angular.module('copayApp.controllers').controller('CreateProfileController', fun
$timeout(function() {
$rootScope.$digest();
}, 1);
return;
} else {
$scope.createDefaultWallet();
}
}
return cb();
});
};
$scope.createProfile = function(form) {
$rootScope.hideNavigation = false;
if (form && form.$invalid) {
$scope.error = 'Please enter the required fields';
return;
}
$scope.loading = true;
$scope.saveSettings = function(cb) {
var plugins = config.plugins;
plugins.EncryptedLocalStorage = false;
plugins.EncryptedInsightStorage = false;
var pluginName = $scope.useLocalstorage ? 'EncryptedLocalStorage' : 'EncryptedInsightStorage';
plugins[pluginName] = true;
console.log('[createProfile.js.102:plugins:]', plugins); //TODO
configService.set({
plugins: plugins
}, function() {
$scope._doCreateProfile($scope.userOrEmail, form.password.$modelValue);
}, cb);
};
$scope.createProfile = function(form) {
if (form && form.$invalid) {
$scope.error = 'Please enter the required fields';
return;
}
$scope.saveSettings(function(err) {
$scope._doCreateProfile($scope.userOrEmail, form.password.$modelValue, function(err) {
$timeout(function() {
form.password.$setViewValue('');
form.password.$render();
form.repeatpassword.$setViewValue('');
form.repeatpassword.$render();
form.$setPristine();
}, 1);
});
});
};

View File

@ -136,7 +136,7 @@
>
<div class="box-setup-footer">
<div class="left">
<a class="text-gray" ng-click="createStep='storage'">
<a class="text-gray" ng-click="setStep('storage')">
<i class="icon-arrow-left4"></i>
<span translate>Back</span>
</a>
@ -178,7 +178,7 @@
<div class="box-setup-footer">
<div class="left">
<a class="text-gray" ng-click="createStep='email'">
<a class="text-gray" ng-click="setStep('email')">
<i class="icon-arrow-left4"></i>
<span translate>Back</span>
</a>