From d3726d658c10eff50a1686f921a8f854abafb090 Mon Sep 17 00:00:00 2001 From: Matias Alejo Garcia Date: Fri, 5 Dec 2014 14:53:54 -0300 Subject: [PATCH] create working --- js/controllers/createProfile.js | 64 ++++++++++++++++++--------------- views/createProfile.html | 4 +-- 2 files changed, 38 insertions(+), 30 deletions(-) diff --git a/js/controllers/createProfile.js b/js/controllers/createProfile.js index 8d35c8d48..acf8c86fa 100644 --- a/js/controllers/createProfile.js +++ b/js/controllers/createProfile.js @@ -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); + }); }); }; diff --git a/views/createProfile.html b/views/createProfile.html index 82bdd0cde..7df084927 100644 --- a/views/createProfile.html +++ b/views/createProfile.html @@ -136,7 +136,7 @@ >