From 4c6f866ba2c3b897d0519ee32859e787a85a23a6 Mon Sep 17 00:00:00 2001 From: Tim Hostetler <6970899+thostetler@users.noreply.github.com> Date: Fri, 21 Jun 2024 15:09:18 -0400 Subject: [PATCH] Add resend verification email page --- src/js/apps/discovery/router.js | 2 +- src/js/components/api_targets.js | 1 + src/js/components/session.js | 53 ++++++++++ .../authentication/templates/log-in.html | 5 +- .../authentication/templates/register.html | 2 +- .../templates/resend-verification-email.html | 25 +++++ src/js/widgets/authentication/widget.js | 100 ++++++++++++++++-- test/mocha/js/components/session.spec.js | 1 + 8 files changed, 176 insertions(+), 13 deletions(-) create mode 100644 src/js/widgets/authentication/templates/resend-verification-email.html diff --git a/src/js/apps/discovery/router.js b/src/js/apps/discovery/router.js index 809255340..ffaa8008a 100644 --- a/src/js/apps/discovery/router.js +++ b/src/js/apps/discovery/router.js @@ -214,7 +214,7 @@ define([ if ( subView && !_.contains( - ['login', 'register', 'reset-password-1', 'reset-password-2'], + ['login', 'register', 'reset-password-1', 'reset-password-2', 'resend-verification-email'], subView ) ) { diff --git a/src/js/components/api_targets.js b/src/js/components/api_targets.js index 0f66e3a40..212ba8ff5 100644 --- a/src/js/components/api_targets.js +++ b/src/js/components/api_targets.js @@ -34,6 +34,7 @@ define([], function () { LOGIN: 'accounts/user/login', LOGOUT: 'accounts/user/logout', VERIFY: 'accounts/verify', + RESEND_VERIFY: `accounts/user/{email}/verify`, RESET_PASSWORD: 'accounts/user/reset-password', CHANGE_PASSWORD: 'accounts/user/change-password', CHANGE_EMAIL: 'accounts/user/change-email', diff --git a/src/js/components/session.js b/src/js/components/session.js index 5f5ea5997..f843a6a9b 100644 --- a/src/js/components/session.js +++ b/src/js/components/session.js @@ -208,6 +208,58 @@ define([ }); }, + + /** + * Resend verification email + * @param {string} email + */ + resendVerificationEmail: function(email) { + const self = this; + this.sendRequestWithNewCSRF(function(csrfToken) { + const request = new ApiRequest({ + target: ApiTargets.RESEND_VERIFY.replace('{email}', email), + query: new ApiQuery({}), + options: { + type: 'PUT', + headers: { 'X-CSRFToken': csrfToken }, + done: function() { + const pubsub = self.getPubSub(); + pubsub.publish( + pubsub.USER_ANNOUNCEMENT, + 'resend_verification_email_success' + ); + }, + fail: function(xhr) { + const pubsub = self.getPubSub(); + const error = utils.extractErrorMessageFromAjax( + xhr, + 'error unknown' + ); + const message = `Resending verification email was unsuccessful (${error})`; + pubsub.publish( + pubsub.ALERT, + new ApiFeedback({ + code: 0, + msg: message, + type: 'danger', + fade: true, + }) + ); + pubsub.publish( + pubsub.USER_ANNOUNCEMENT, + 'resend_verification_email_fail', + message + ); + }, + }, + }); + + return this.getBeeHive() + .getService('Api') + .request(request); + }); + }, + setChangeToken: function(token) { this.model.set('resetPasswordToken', token); }, @@ -365,6 +417,7 @@ define([ resetPassword1: 'sends an email to account', resetPassword2: 'updates the password', setChangeToken: 'the router stores the token to reset password here', + resendVerificationEmail: 'resends the verification email', }, }); diff --git a/src/js/widgets/authentication/templates/log-in.html b/src/js/widgets/authentication/templates/log-in.html index a81a170f1..0d90c0c78 100644 --- a/src/js/widgets/authentication/templates/log-in.html +++ b/src/js/widgets/authentication/templates/log-in.html @@ -28,7 +28,10 @@
{{errorMsg}}
+ +