From 173e5f2b12918c222358af0de6064a950532004f Mon Sep 17 00:00:00 2001 From: Ivan Socolsky Date: Thu, 18 Dec 2014 09:37:07 -0300 Subject: [PATCH 1/4] added resend button --- index.html | 1 + js/controllers/index.js | 6 +++++- js/services/identityService.js | 4 ++++ 3 files changed, 10 insertions(+), 1 deletion(-) diff --git a/index.html b/index.html index e261d9cc9..57e57b0a1 100644 --- a/index.html +++ b/index.html @@ -58,6 +58,7 @@ Email not confirmed.
Please confirm your email address using the confirmation link at the message we sent you + Resend
diff --git a/js/controllers/index.js b/js/controllers/index.js index 285506ee9..8f4afdb2d 100644 --- a/js/controllers/index.js +++ b/js/controllers/index.js @@ -1,10 +1,14 @@ 'use strict'; -angular.module('copayApp.controllers').controller('IndexController', function($scope, go, isCordova) { +angular.module('copayApp.controllers').controller('IndexController', function($scope, go, isCordova, identityService) { $scope.init = function() { }; + $scope.resendVerificationEmail = function (cb) { + identityService.resendVerificationEmail(cb); + }; + $scope.swipe = function(invert) { go.swipe(invert); }; diff --git a/js/services/identityService.js b/js/services/identityService.js index 8dcc89a04..2dc23ed4a 100644 --- a/js/services/identityService.js +++ b/js/services/identityService.js @@ -62,6 +62,10 @@ angular.module('copayApp.services') }); }; + root.resendVerificationEmail = function (cb) { + console.log('yes'); + }; + root.setServerStatus = function(headers) { if (!headers) return; From b0c31b37c3e499f54f69277c4529e88e2a08366a Mon Sep 17 00:00:00 2001 From: Ivan Socolsky Date: Thu, 18 Dec 2014 15:50:42 -0300 Subject: [PATCH 2/4] methods to resend email from identity --- js/controllers/index.js | 4 ++-- js/models/Identity.js | 9 +++++++++ js/plugins/EncryptedInsightStorage.js | 4 ++++ js/plugins/InsightStorage.js | 25 +++++++++++++++++++++++++ js/services/identityService.js | 3 ++- 5 files changed, 42 insertions(+), 3 deletions(-) diff --git a/js/controllers/index.js b/js/controllers/index.js index 8f4afdb2d..d3ac91d4a 100644 --- a/js/controllers/index.js +++ b/js/controllers/index.js @@ -5,8 +5,8 @@ angular.module('copayApp.controllers').controller('IndexController', function($s }; - $scope.resendVerificationEmail = function (cb) { - identityService.resendVerificationEmail(cb); + $scope.resendVerificationEmail = function () { + identityService.resendVerificationEmail(function () {}); }; $scope.swipe = function(invert) { diff --git a/js/models/Identity.js b/js/models/Identity.js index 60fc2ecd2..4ed14f0db 100644 --- a/js/models/Identity.js +++ b/js/models/Identity.js @@ -105,6 +105,15 @@ Identity.create = function(opts, cb) { }); }; +Identity.prototype.resendVerificationEmail = function (cb) { + var self = this; + + preconditions.checkArgument(_.isFunction(cb)); + preconditions.checkState(_.isFunction(self.storage.resendVerificationEmail)); + + self.storage.resendVerificationEmail(cb); +}; + /** * Open an Identity from the given storage. diff --git a/js/plugins/EncryptedInsightStorage.js b/js/plugins/EncryptedInsightStorage.js index ff994be5c..ce377796c 100644 --- a/js/plugins/EncryptedInsightStorage.js +++ b/js/plugins/EncryptedInsightStorage.js @@ -16,6 +16,10 @@ EncryptedInsightStorage.prototype._brokenDecrypt = function(body) { return decryptedJson; }; +EncryptedInsightStorage.prototype.resendVerificationEmail = function(callback) { + InsightStorage.prototype.resendVerificationEmail.apply(this, [callback]); +}; + EncryptedInsightStorage.prototype.getItem = function(name, callback) { var self = this; InsightStorage.prototype.getItem.apply(this, [name, diff --git a/js/plugins/InsightStorage.js b/js/plugins/InsightStorage.js index 1f28eccde..cb8ec6fc4 100644 --- a/js/plugins/InsightStorage.js +++ b/js/plugins/InsightStorage.js @@ -37,6 +37,31 @@ InsightStorage.prototype.createItem = function(name, value, callback) { }); }; +InsightStorage.prototype.resendVerificationEmail = function (callback) { + var passphrase = this.getPassphrase(); + var authHeader = new buffers.Buffer(this.email + ':' + passphrase).toString('base64'); + var resendUrl = this.storeUrl + '/resend_email'; + + log.debug('Resending verification email: ' + this.email); + this.request.get({ + url: resendUrl, + headers: { + 'Authorization': authHeader + }, + body: null, + }, function(err, response, body) { + if (err) { + return callback('Connection error'); + } + if (response.statusCode === 409) { + return callback('BADCREDENTIALS: Invalid username or password'); + } else if (response.statusCode !== 200) { + return callback('Unable to process the request'); + } + return callback(); + }); +}; + function mayBeOldPassword(password) { // Test for base64 return /^[a-zA-Z0-9\/=\+]+$/.test(password); diff --git a/js/services/identityService.js b/js/services/identityService.js index 2dc23ed4a..e7a993213 100644 --- a/js/services/identityService.js +++ b/js/services/identityService.js @@ -63,7 +63,8 @@ angular.module('copayApp.services') }; root.resendVerificationEmail = function (cb) { - console.log('yes'); + var iden = $rootScope.iden; + iden.resendVerificationEmail(cb); }; root.setServerStatus = function(headers) { From 94a8ecbf2b3ac2a888327a8718900780311bcde5 Mon Sep 17 00:00:00 2001 From: Ivan Socolsky Date: Thu, 18 Dec 2014 16:04:00 -0300 Subject: [PATCH 3/4] give feedback to the user --- js/controllers/index.js | 14 +++++++++++--- 1 file changed, 11 insertions(+), 3 deletions(-) diff --git a/js/controllers/index.js b/js/controllers/index.js index d3ac91d4a..8e1f4e689 100644 --- a/js/controllers/index.js +++ b/js/controllers/index.js @@ -1,12 +1,20 @@ 'use strict'; -angular.module('copayApp.controllers').controller('IndexController', function($scope, go, isCordova, identityService) { +angular.module('copayApp.controllers').controller('IndexController', function($scope, go, isCordova, identityService, notification) { $scope.init = function() { }; - $scope.resendVerificationEmail = function () { - identityService.resendVerificationEmail(function () {}); + $scope.resendVerificationEmail = function() { + identityService.resendVerificationEmail(function(err) { + if (err) { + notification.error('Could not send email', 'There was a problem sending the verification email.'); + setTimeout(function() { + $scope.$digest(); + }, 1); + return; + } + }); }; $scope.swipe = function(invert) { From 1bf60e64ffd8d4abdf9f7764a95287e0a9cc5cb7 Mon Sep 17 00:00:00 2001 From: Ivan Socolsky Date: Thu, 18 Dec 2014 18:27:25 -0300 Subject: [PATCH 4/4] styling resend button --- index.html | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/index.html b/index.html index 57e57b0a1..d0b9b38a4 100644 --- a/index.html +++ b/index.html @@ -53,12 +53,12 @@ Network Error.
Attempting to reconnect..
+ Resend Email not confirmed.
Please confirm your email address using the confirmation link at the message we sent you
- Resend