Skip to content

Commit

Permalink
fix: #9217, render 400 error page on bad access to /register
Browse files Browse the repository at this point in the history
  • Loading branch information
julianlam committed Jan 24, 2021
1 parent 06e2ef1 commit b2b1450
Show file tree
Hide file tree
Showing 3 changed files with 18 additions and 4 deletions.
6 changes: 5 additions & 1 deletion public/language/en-GB/register.json
Original file line number Diff line number Diff line change
Expand Up @@ -24,5 +24,9 @@
"interstitial.errors-found": "We could not complete your registration:",
"gdpr_agree_data": "I consent to the collection and processing of my personal information on this website.",
"gdpr_agree_email": "I consent to receive digest and notification emails from this website.",
"gdpr_consent_denied": "You must give consent to this site to collect/process your information, and to send you emails."
"gdpr_consent_denied": "You must give consent to this site to collect/process your information, and to send you emails.",

"invite.error-admin-only": "Direct user registration has been disabled. Please contact an administrator for more details.",
"invite.error-invite-only": "Direct user registration has been disabled. You must be invited by an existing user in order to access this forum.",
"invite.error-invalid-data": "The registration data received does not correspond to our records. Please contact an administrator for more details"
}
8 changes: 7 additions & 1 deletion src/controllers/index.js
Original file line number Diff line number Diff line change
Expand Up @@ -149,7 +149,13 @@ Controllers.register = async function (req, res, next) {
}
try {
if (registrationType === 'invite-only' || registrationType === 'admin-invite-only') {
await user.verifyInvitation(req.query);
try {
await user.verifyInvitation(req.query);
} catch (e) {
res.render('400', {
error: e.message,
});
}
}

const loginStrategies = require('../routes/authentication').getLoginStrategies();
Expand Down
8 changes: 6 additions & 2 deletions src/user/invite.js
Original file line number Diff line number Diff line change
Expand Up @@ -58,11 +58,15 @@ module.exports = function (User) {

User.verifyInvitation = async function (query) {
if (!query.token || !query.email) {
throw new Error('[[error:invalid-data]]');
if (meta.config.registrationType.startsWith('admin-')) {
throw new Error('[[register:invite.error-admin-only]]');
} else {
throw new Error('[[register:invite.error-invite-only]]');
}
}
const token = await db.getObjectField('invitation:email:' + query.email, 'token');
if (!token || token !== query.token) {
throw new Error('[[error:invalid-token]]');
throw new Error('[[register:invite.error-invalid-data]]');
}
};

Expand Down

0 comments on commit b2b1450

Please sign in to comment.