diff --git a/public/language/en-GB/notifications.json b/public/language/en-GB/notifications.json index 2782fdaff9..ebfd7b1d7b 100644 --- a/public/language/en-GB/notifications.json +++ b/public/language/en-GB/notifications.json @@ -83,6 +83,7 @@ "email-confirmed": "Email Confirmed", "email-confirmed-message": "Thank you for validating your email. Your account is now fully activated.", "email-confirm-error-message": "There was a problem validating your email address. Perhaps the code was invalid or has expired.", + "email-confirm-error-message-already-validated": "Your email address was already validated.", "email-confirm-sent": "Confirmation email sent.", "none": "None", diff --git a/src/controllers/index.js b/src/controllers/index.js index 2cf50a7785..b3542851ee 100644 --- a/src/controllers/index.js +++ b/src/controllers/index.js @@ -219,20 +219,31 @@ Controllers.registerInterstitial = async function (req, res, next) { } }; -Controllers.confirmEmail = async (req, res, next) => { +Controllers.confirmEmail = async (req, res) => { + function renderPage(opts = {}) { + res.render('confirm', { + title: '[[pages:confirm]]', + ...opts, + }); + } try { + if (req.uid) { + const emailValidated = await user.getUserField(req.uid, 'email:confirmed'); + if (emailValidated) { + return renderPage({ alreadyValidated: true }); + } + } await user.email.confirmByCode(req.params.code, req.session.id); if (req.session.registration) { // After confirmation, no need to send user back to email change form delete req.session.registration.updateEmail; } - res.render('confirm', { - title: '[[pages:confirm]]', - }); + renderPage(); } catch (e) { - if (e.message === '[[error:invalid-data]]') { - return next(); + if (e.message === '[[error:invalid-data]]' || e.message === '[[error:confirm-email-expired]]') { + renderPage({ error: true }); + return; } throw e; diff --git a/src/views/confirm.tpl b/src/views/confirm.tpl index fb81b63823..0235ced0d5 100644 --- a/src/views/confirm.tpl +++ b/src/views/confirm.tpl @@ -1,7 +1,19 @@ +{{{ if alreadyValidated }}} +
+

[[notifications:email-confirm-error-message-already-validated]]

+{{{ end }}} + +{{{ if error }}} +
+

[[notifications:email-confirm-error-message]]

+{{{ end }}} + +{{{ if (!error && !alreadyValidated )}}}
[[notifications:email-confirmed]]

[[notifications:email-confirmed-message]]

-

+{{{ end }}} +

[[notifications:back-to-home, {config.siteTitle}]]

-
+
\ No newline at end of file