From ad76c347ea22c8007af85bb7288c80ac0969f94d Mon Sep 17 00:00:00 2001 From: rebeccadumazert Date: Tue, 17 Dec 2024 17:40:48 +0100 Subject: [PATCH] refactor(routes): delete verify-email-help route --- assets/js/disabled-with-countdown.js | 26 ++++----- src/controllers/user/verify-email.ts | 39 ++++--------- src/routers/user.ts | 8 --- src/views/partials/card-button-container.ejs | 10 ++-- src/views/user/verify-email.ejs | 58 ++++++++++---------- 5 files changed, 58 insertions(+), 83 deletions(-) diff --git a/assets/js/disabled-with-countdown.js b/assets/js/disabled-with-countdown.js index dd501d9b..3076b320 100644 --- a/assets/js/disabled-with-countdown.js +++ b/assets/js/disabled-with-countdown.js @@ -10,25 +10,25 @@ document.addEventListener( const nowInSeconds = new Date().getTime() / 1000; let secondsToEndDate = Math.round(endDateInSeconds - nowInSeconds); let intervalId; + element.disabled = true; - intervalId = setInterval(function () { - secondsToEndDate--; - const prefixText = - element.value.match(/(.*)( \(disponible dans \d+:\d+\))/)?.[1] || - element.value; - let suffixText = ""; + function updateButtonText() { + const minutes = Math.floor(secondsToEndDate / 60); + const seconds = String(secondsToEndDate % 60).padStart(2, "0"); + element.textContent = `Recevoir un nouvel email (disponible dans ${minutes}:${seconds})`; + } - if (secondsToEndDate > 0) { - const minutes = Math.floor(secondsToEndDate / 60); - const seconds = String(secondsToEndDate % 60).padStart(2, "0"); - suffixText = ` (disponible dans ${minutes}:${seconds})`; - } + updateButtonText(); - element.value = prefixText + suffixText; + intervalId = setInterval(function () { + secondsToEndDate--; - if (secondsToEndDate <= 0) { + if (secondsToEndDate > 0) { + updateButtonText(); + } else { element.disabled = false; + element.textContent = "Recevoir un nouvel email"; clearInterval(intervalId); } }, 1000); diff --git a/src/controllers/user/verify-email.ts b/src/controllers/user/verify-email.ts index d9d78871..195db319 100644 --- a/src/controllers/user/verify-email.ts +++ b/src/controllers/user/verify-email.ts @@ -35,8 +35,11 @@ export const getVerifyEmailController = async ( const { new_code_sent } = await schema.parseAsync(req.query); - const { email, needs_inclusionconnect_onboarding_help } = - getUserFromAuthenticatedSession(req); + const { + email, + needs_inclusionconnect_onboarding_help, + verify_email_sent_at, + } = getUserFromAuthenticatedSession(req); const { codeSent, updatedUser } = await sendEmailAddressVerificationEmail({ email, @@ -49,7 +52,12 @@ export const getVerifyEmailController = async ( pageTitle: "Vérifier votre email", notifications: await getNotificationsFromRequest(req), email, - csrfToken: csrfToken(req), + countdownEndDate: moment(verify_email_sent_at) + .add(MIN_DURATION_BETWEEN_TWO_VERIFICATION_CODE_SENDING_IN_SECONDS, "s") + .tz("Europe/Paris") + .locale("fr") + .format(), + csrfToken: email && csrfToken(req), newCodeSent: new_code_sent, codeSent, needs_inclusionconnect_onboarding_help, @@ -136,28 +144,3 @@ export const postSendEmailVerificationController = async ( next(error); } }; - -export const getVerifyEmailHelpController = async ( - req: Request, - res: Response, - next: NextFunction, -) => { - try { - const { email, verify_email_sent_at } = - getUserFromAuthenticatedSession(req); - - return res.render("user/verify-email-help", { - pageTitle: "Aide code de vérification", - email, - countdownEndDate: moment(verify_email_sent_at) - .add(MIN_DURATION_BETWEEN_TWO_VERIFICATION_CODE_SENDING_IN_SECONDS, "s") - .tz("Europe/Paris") - .locale("fr") - .format(), - csrfToken: email && csrfToken(req), - illustration: "illu-password.svg", - }); - } catch (error) { - next(error); - } -}; diff --git a/src/routers/user.ts b/src/routers/user.ts index a2d8e92c..19ee4344 100644 --- a/src/routers/user.ts +++ b/src/routers/user.ts @@ -52,7 +52,6 @@ import { } from "../controllers/user/update-personal-informations"; import { getVerifyEmailController, - getVerifyEmailHelpController, postSendEmailVerificationController, postVerifyEmailController, } from "../controllers/user/verify-email"; @@ -191,13 +190,6 @@ export const userRouter = () => { issueSessionOrRedirectController, ); - userRouter.get( - "/verify-email-help", - checkUserTwoFactorAuthMiddleware, - csrfProtectionMiddleware, - getVerifyEmailHelpController, - ); - userRouter.post( "/send-email-verification", rateLimiterMiddleware, diff --git a/src/views/partials/card-button-container.ejs b/src/views/partials/card-button-container.ejs index 5ebcfef3..a79471d7 100644 --- a/src/views/partials/card-button-container.ejs +++ b/src/views/partials/card-button-container.ejs @@ -1,6 +1,6 @@
- - <% if (locals.showGoBackButton) { %> + <% if (locals.showGoBackButton) { %> +
diff --git a/src/views/user/verify-email.ejs b/src/views/user/verify-email.ejs index 2cedc059..a13897f0 100644 --- a/src/views/user/verify-email.ejs +++ b/src/views/user/verify-email.ejs @@ -1,7 +1,7 @@
<%- include('../partials/notifications.ejs', {notifications: notifications, noWrapperDiv: true}) %>

- Vérifier votre email + Confirmer votre adresse

<% if (locals.needs_inclusionconnect_onboarding_help) { %>
@@ -11,24 +11,19 @@
<% } %>
-
+ <% if (codeSent || newCodeSent) { %> -

- Un <% if (newCodeSent) { %>nouveau <% } %>code de vérification a été envoyé à - - <%= email; %> - . -

+
+

Un <% if (newCodeSent) { %>nouveau <% } %>code de vérification a été envoyé à <%= email; %>. +

+
<% } %> - - - -
+
- <%- include('../partials/card-button-container.ejs', {label: 'Vérifier', showGoBackButton: true}) %> + <%- include('../partials/card-button-container.ejs', {label: 'Valider', showGoBackButton: false, button:'width: 100%; justify-content: center;', margin: "fr-2w"}) %> + +
+ +
- + + Vous ne recevez rien ? Consulter la page d'aide +
+