mirror of
https://github.com/NodeBB/NodeBB.git
synced 2026-03-03 11:01:20 +01:00
fix: when registering through an invite, prepopulate the email field on /register/complete with the email
This commit is contained in:
@@ -32,12 +32,12 @@ async function registerAndLoginUser(req, res, userData) {
|
|||||||
if (deferRegistration) {
|
if (deferRegistration) {
|
||||||
userData.register = true;
|
userData.register = true;
|
||||||
req.session.registration = userData;
|
req.session.registration = userData;
|
||||||
|
const next = `${nconf.get('relative_path')}/register/complete`;
|
||||||
if (req.body?.noscript === 'true') {
|
if (req.body?.noscript === 'true') {
|
||||||
res.redirect(`${nconf.get('relative_path')}/register/complete`);
|
res.redirect(next);
|
||||||
return;
|
return;
|
||||||
}
|
}
|
||||||
res.json({ next: `${nconf.get('relative_path')}/register/complete` });
|
res.json({ next });
|
||||||
return;
|
return;
|
||||||
}
|
}
|
||||||
|
|
||||||
@@ -71,6 +71,7 @@ async function registerAndLoginUser(req, res, userData) {
|
|||||||
return complete;
|
return complete;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
// POST /register
|
||||||
authenticationController.register = async function (req, res) {
|
authenticationController.register = async function (req, res) {
|
||||||
const registrationType = meta.config.registrationType || 'normal';
|
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) {
|
authenticationController.registerComplete = async function (req, res) {
|
||||||
try {
|
try {
|
||||||
// For the interstitials that respond, execute the callback with the form body
|
// 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) => {
|
authenticationController.registerAbort = async (req, res) => {
|
||||||
if (req.uid && req.session.registration) {
|
if (req.uid && req.session.registration) {
|
||||||
// Email is the only cancelable interstitial
|
// Email is the only cancelable interstitial
|
||||||
@@ -204,6 +207,7 @@ authenticationController.registerAbort = async (req, res) => {
|
|||||||
});
|
});
|
||||||
};
|
};
|
||||||
|
|
||||||
|
// POST /login
|
||||||
authenticationController.login = async (req, res, next) => {
|
authenticationController.login = async (req, res, next) => {
|
||||||
let { strategy } = await plugins.hooks.fire('filter:login.override', { req, strategy: 'local' });
|
let { strategy } = await plugins.hooks.fire('filter:login.override', { req, strategy: 'local' });
|
||||||
if (!passport._strategy(strategy)) {
|
if (!passport._strategy(strategy)) {
|
||||||
|
|||||||
@@ -192,6 +192,7 @@ Controllers.register = async function (req, res, next) {
|
|||||||
}
|
}
|
||||||
};
|
};
|
||||||
|
|
||||||
|
// GET /register/complete
|
||||||
Controllers.registerInterstitial = async function (req, res, next) {
|
Controllers.registerInterstitial = async function (req, res, next) {
|
||||||
if (!req.session.hasOwnProperty('registration')) {
|
if (!req.session.hasOwnProperty('registration')) {
|
||||||
return res.redirect(`${nconf.get('relative_path')}/register`);
|
return res.redirect(`${nconf.get('relative_path')}/register`);
|
||||||
|
|||||||
@@ -36,6 +36,8 @@ Interstitials.email = async (data) => {
|
|||||||
let email;
|
let email;
|
||||||
if (data.userData.uid) {
|
if (data.userData.uid) {
|
||||||
email = await user.getUserField(data.userData.uid, 'email');
|
email = await user.getUserField(data.userData.uid, 'email');
|
||||||
|
} else if (data.userData.token) {
|
||||||
|
email = await user.getEmailFromToken(data.userData.token);
|
||||||
}
|
}
|
||||||
|
|
||||||
data.interstitials.push({
|
data.interstitials.push({
|
||||||
|
|||||||
@@ -78,6 +78,11 @@ module.exports = function (User) {
|
|||||||
return email && email === enteredEmail;
|
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) {
|
User.confirmIfInviteEmailIsUsed = async function (token, enteredEmail, uid) {
|
||||||
if (!enteredEmail) {
|
if (!enteredEmail) {
|
||||||
return;
|
return;
|
||||||
@@ -100,11 +105,9 @@ module.exports = function (User) {
|
|||||||
return;
|
return;
|
||||||
}
|
}
|
||||||
|
|
||||||
if (!groupsToJoin || groupsToJoin.length < 1) {
|
if (Array.isArray(groupsToJoin) && groupsToJoin.length) {
|
||||||
return;
|
await groups.join(groupsToJoin, uid);
|
||||||
}
|
}
|
||||||
|
|
||||||
await groups.join(groupsToJoin, uid);
|
|
||||||
};
|
};
|
||||||
|
|
||||||
User.deleteInvitation = async function (invitedBy, email) {
|
User.deleteInvitation = async function (invitedBy, email) {
|
||||||
|
|||||||
Reference in New Issue
Block a user