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 @@
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 @@