mirror of
https://github.com/NodeBB/NodeBB.git
synced 2025-10-26 16:46:12 +01:00
feat: show a friendly message on invalid or expired code, closes #12738
This commit is contained in:
@@ -83,6 +83,7 @@
|
|||||||
"email-confirmed": "Email Confirmed",
|
"email-confirmed": "Email Confirmed",
|
||||||
"email-confirmed-message": "Thank you for validating your email. Your account is now fully activated.",
|
"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": "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.",
|
"email-confirm-sent": "Confirmation email sent.",
|
||||||
|
|
||||||
"none": "None",
|
"none": "None",
|
||||||
|
|||||||
@@ -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 {
|
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);
|
await user.email.confirmByCode(req.params.code, req.session.id);
|
||||||
if (req.session.registration) {
|
if (req.session.registration) {
|
||||||
// After confirmation, no need to send user back to email change form
|
// After confirmation, no need to send user back to email change form
|
||||||
delete req.session.registration.updateEmail;
|
delete req.session.registration.updateEmail;
|
||||||
}
|
}
|
||||||
|
|
||||||
res.render('confirm', {
|
renderPage();
|
||||||
title: '[[pages:confirm]]',
|
|
||||||
});
|
|
||||||
} catch (e) {
|
} catch (e) {
|
||||||
if (e.message === '[[error:invalid-data]]') {
|
if (e.message === '[[error:invalid-data]]' || e.message === '[[error:confirm-email-expired]]') {
|
||||||
return next();
|
renderPage({ error: true });
|
||||||
|
return;
|
||||||
}
|
}
|
||||||
|
|
||||||
throw e;
|
throw e;
|
||||||
|
|||||||
@@ -1,7 +1,19 @@
|
|||||||
|
{{{ if alreadyValidated }}}
|
||||||
|
<div class="alert alert-info">
|
||||||
|
<p>[[notifications:email-confirm-error-message-already-validated]]</p>
|
||||||
|
{{{ end }}}
|
||||||
|
|
||||||
|
{{{ if error }}}
|
||||||
|
<div class="alert alert-warning">
|
||||||
|
<p>[[notifications:email-confirm-error-message]]</p>
|
||||||
|
{{{ end }}}
|
||||||
|
|
||||||
|
{{{ if (!error && !alreadyValidated )}}}
|
||||||
<div class="alert alert-success">
|
<div class="alert alert-success">
|
||||||
<strong>[[notifications:email-confirmed]]</strong>
|
<strong>[[notifications:email-confirmed]]</strong>
|
||||||
<p>[[notifications:email-confirmed-message]]</p>
|
<p>[[notifications:email-confirmed-message]]</p>
|
||||||
<p>
|
{{{ end }}}
|
||||||
|
<p class="mb-0">
|
||||||
<a href="{config.relative_path}/">[[notifications:back-to-home, {config.siteTitle}]]</a>
|
<a href="{config.relative_path}/">[[notifications:back-to-home, {config.siteTitle}]]</a>
|
||||||
</p>
|
</p>
|
||||||
</div>
|
</div>
|
||||||
Reference in New Issue
Block a user