From 3360c31a12e1cd971d138d29e661f370cd3fd5ed Mon Sep 17 00:00:00 2001 From: Matias Alejo Garcia Date: Sat, 1 Nov 2014 21:34:03 -0300 Subject: [PATCH] fix login / create form errors and confirmed messages --- config.js | 3 +++ css/src/main.css | 2 +- js/controllers/createProfile.js | 5 ++--- js/controllers/emailConfirmation.js | 6 ++++++ js/controllers/home.js | 18 ++++++++++++++++-- js/plugins/InsightStorage.js | 4 ++-- js/routes.js | 4 ++++ js/services/identityService.js | 20 +++++++++++++++----- views/createProfile.html | 14 ++++++++++---- views/home.html | 21 +++++++++++++++------ 10 files changed, 74 insertions(+), 23 deletions(-) create mode 100644 js/controllers/emailConfirmation.js diff --git a/config.js b/config.js index 00c88f3ac..9282864b0 100644 --- a/config.js +++ b/config.js @@ -62,6 +62,9 @@ var defaultConfig = { }, EncryptedInsightStorage: { + // THIS IS WRONG BUT DO NOT CHANGE IT WITH OUT A MIGRATION PLAN + // ALSO CHANGE THE DEFAULT AT js/plugins/InsightStorage.js + // url: 'https://test-insight.bitpay.com:443/api/email' // url: 'http://localhost:3001/api/email' }, diff --git a/css/src/main.css b/css/src/main.css index 2db9e908d..c9110c4d3 100644 --- a/css/src/main.css +++ b/css/src/main.css @@ -355,7 +355,7 @@ a:hover { .logo-setup { text-align: center; - padding: 7rem 0 5rem; + padding: 5rem 0 4rem; color: #fff; } diff --git a/js/controllers/createProfile.js b/js/controllers/createProfile.js index 34997f5a7..c59a4fe1a 100644 --- a/js/controllers/createProfile.js +++ b/js/controllers/createProfile.js @@ -2,11 +2,10 @@ angular.module('copayApp.controllers').controller('CreateProfileController', function($scope, $rootScope, $location, notification, controllerUtils, pluginManager, identityService) { controllerUtils.redirIfLogged(); - $scope.retreiving = false; - + $scope.loading = false; $scope.createProfile = function(form) { if (form && form.$invalid) { - notification.error('Error', 'Please enter the required fields'); + $scope.error('Error', 'Please enter the required fields'); return; } $scope.loading = true; diff --git a/js/controllers/emailConfirmation.js b/js/controllers/emailConfirmation.js new file mode 100644 index 000000000..8ae1d2d0e --- /dev/null +++ b/js/controllers/emailConfirmation.js @@ -0,0 +1,6 @@ +'use strict'; + +angular.module('copayApp.controllers').controller('EmailConfirmationController', function($scope, $rootScope, $location) { + $rootScope.fromEmailConfirmation = true; + $location.path('/'); +}); diff --git a/js/controllers/home.js b/js/controllers/home.js index 657102d3d..1a9a85c2b 100644 --- a/js/controllers/home.js +++ b/js/controllers/home.js @@ -2,13 +2,27 @@ angular.module('copayApp.controllers').controller('HomeController', function($scope, $rootScope, $location, notification, controllerUtils, pluginManager, identityService, Compatibility) { controllerUtils.redirIfLogged(); - $scope.confirmedEmail = getParam('confirmed'); + + // This is only for backwards compat, insight api should link to #!/confirmed directly + if (getParam('confirmed')) { + var hashIndex = window.location.href.indexOf('/?'); + window.location = window.location.href.substr(0, hashIndex) + '#!/confirmed'; + return; + } + + + if ($rootScope.fromEmailConfirmation) { + $scope.confirmedEmail = true; + $rootScope.fromEmailConfirmation = false; + } + $scope.retreiving = false; Compatibility.check($scope); $scope.openProfile = function(form) { + $scope.confirmedEmail = false; if (form && form.$invalid) { - notification.error('Error', 'Please enter the required fields'); + $scope.error = 'Please enter the required fields'; return; } $scope.loading = true; diff --git a/js/plugins/InsightStorage.js b/js/plugins/InsightStorage.js index 4614f0c1c..799163e9c 100644 --- a/js/plugins/InsightStorage.js +++ b/js/plugins/InsightStorage.js @@ -5,7 +5,7 @@ var Identity = require('../models/Identity'); function InsightStorage(config) { this.type = 'DB'; - this.storeUrl = config.url || 'https://insight.is/api/email'; + this.storeUrl = config.url || 'https://test-insight.bitpay.com:443/api/email'; this.request = config.request || request; } @@ -65,7 +65,7 @@ InsightStorage.prototype.setItem = function(name, value, callback) { return callback('Connection error'); } if (response.statusCode === 409) { - return callback('Invalid username or password'); + return callback('BADCREDENTIALS: Invalid username or password'); } if (response.statusCode !== 200) { return callback('Unable to store data on insight'); diff --git a/js/routes.js b/js/routes.js index 9eaaf29f2..a19ef2666 100644 --- a/js/routes.js +++ b/js/routes.js @@ -15,6 +15,10 @@ angular .when('/unsupported', { templateUrl: 'views/unsupported.html' }) + .when('/confirmed', { + template: " ", // just fire controller + controller: 'EmailConfirmationController', + }) .when('/uri-payment/:data', { templateUrl: 'views/uri-payment.html' }) diff --git a/js/services/identityService.js b/js/services/identityService.js index eff52061e..7bffa1cb2 100644 --- a/js/services/identityService.js +++ b/js/services/identityService.js @@ -33,8 +33,14 @@ angular.module('copayApp.services') passphraseConfig: config.passphraseConfig, failIfExists: true, }, function(err, iden) { + scope.loading = false; if (err || !iden) { - controllerUtils.onErrorDigest(scope, 'User already exists!'); + copay.logger.debug(err); + if (err && ( err.match('EEXISTS') || err.match('BADCREDENTIALS'))) { + scope.error = 'User already exists!'; + } else { + scope.error = 'Unknown error when connecting Insight Server'; + } return; } var walletOptions = { @@ -47,10 +53,10 @@ angular.module('copayApp.services') }; iden.createWallet(walletOptions, function(err, wallet) { if (err || !wallet) { - controllerUtils.onErrorDigest(scope, 'Could not create default wallet'); + copay.logger.debug(err); + scope.error = 'Could not create default wallet'; return; } - scope.loading = false; controllerUtils.bindProfile(scope, iden, wallet.id); }); }); @@ -69,8 +75,12 @@ angular.module('copayApp.services') passphraseConfig: config.passphraseConfig, }, function(err, iden) { if (err && !iden) { - controllerUtils.onErrorDigest( - scope, (err.toString() || '').match('PNOTFOUND') ? 'Invalid email or password' : 'Unknown error'); + if ((err.toString() || '').match('PNOTFOUND')) { + scope.error = 'Invalid email or password'; + } + else { + scope.error = 'Unknown error'; + } } else { var firstWallet = iden.getLastFocusedWallet(); controllerUtils.bindProfile(scope, iden, firstWallet); diff --git a/views/createProfile.html b/views/createProfile.html index b0a0d3354..c886d067c 100644 --- a/views/createProfile.html +++ b/views/createProfile.html @@ -1,10 +1,10 @@
- Retreiving information from storage... + Creating profile...
-
+
Copay
@@ -17,10 +17,16 @@ + !profileForm.email.$pristine && !error"> + !profileForm.email.$pristine || error">
+

+ + {{error|translate}} +

+
- Synchronizing with storage... + Accessing your profile...
@@ -11,14 +11,17 @@
- +
-
- Copay now needs a confirmation.
- You have to sign in to confirm your email +
+

+ Your email was confimed! +

+ + Please sign in to access your wallets
-
+
@@ -29,6 +32,12 @@

Sign in to Copay

+

+ + {{error|translate}} +

+