fix: when registering through an invite, prepopulate the email field on /register/complete with the email

This commit is contained in:
Barış Soner Uşaklı
2026-02-17 19:07:28 -05:00
parent 59f35e6fdb
commit 2015777fd1
4 changed files with 17 additions and 7 deletions

View File

@@ -32,12 +32,12 @@ async function registerAndLoginUser(req, res, userData) {
if (deferRegistration) {
userData.register = true;
req.session.registration = userData;
const next = `${nconf.get('relative_path')}/register/complete`;
if (req.body?.noscript === 'true') {
res.redirect(`${nconf.get('relative_path')}/register/complete`);
res.redirect(next);
return;
}
res.json({ next: `${nconf.get('relative_path')}/register/complete` });
res.json({ next });
return;
}
@@ -71,6 +71,7 @@ async function registerAndLoginUser(req, res, userData) {
return complete;
}
// POST /register
authenticationController.register = async function (req, res) {
const registrationType = meta.config.registrationType || 'normal';
@@ -109,6 +110,7 @@ authenticationController.register = async function (req, res) {
}
};
// POST /register/complete
authenticationController.registerComplete = async function (req, res) {
try {
// For the interstitials that respond, execute the callback with the form body
@@ -185,6 +187,7 @@ authenticationController.registerComplete = async function (req, res) {
}
};
// POST /register/abort
authenticationController.registerAbort = async (req, res) => {
if (req.uid && req.session.registration) {
// Email is the only cancelable interstitial
@@ -204,6 +207,7 @@ authenticationController.registerAbort = async (req, res) => {
});
};
// POST /login
authenticationController.login = async (req, res, next) => {
let { strategy } = await plugins.hooks.fire('filter:login.override', { req, strategy: 'local' });
if (!passport._strategy(strategy)) {

View File

@@ -192,6 +192,7 @@ Controllers.register = async function (req, res, next) {
}
};
// GET /register/complete
Controllers.registerInterstitial = async function (req, res, next) {
if (!req.session.hasOwnProperty('registration')) {
return res.redirect(`${nconf.get('relative_path')}/register`);

View File

@@ -36,6 +36,8 @@ Interstitials.email = async (data) => {
let email;
if (data.userData.uid) {
email = await user.getUserField(data.userData.uid, 'email');
} else if (data.userData.token) {
email = await user.getEmailFromToken(data.userData.token);
}
data.interstitials.push({

View File

@@ -78,6 +78,11 @@ module.exports = function (User) {
return email && email === enteredEmail;
};
User.getEmailFromToken = async function (token) {
if (!token) return null;
return await db.getObjectField(`invitation:token:${token}`, 'email');
};
User.confirmIfInviteEmailIsUsed = async function (token, enteredEmail, uid) {
if (!enteredEmail) {
return;
@@ -100,11 +105,9 @@ module.exports = function (User) {
return;
}
if (!groupsToJoin || groupsToJoin.length < 1) {
return;
if (Array.isArray(groupsToJoin) && groupsToJoin.length) {
await groups.join(groupsToJoin, uid);
}
await groups.join(groupsToJoin, uid);
};
User.deleteInvitation = async function (invitedBy, email) {