Node.js based forum software built for the modern web
fix: when registering through an invite, prepopulate the email field on /register/complete with the email
Barış Soner Uşaklı2015777fd1f8
diff --git a/src/controllers/authentication.js b/src/controllers/authentication.jsindex f948e053b5..3c5b337801 100644--- a/src/controllers/authentication.js+++ b/src/controllers/authentication.js@@ -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 /registerauthenticationController.register = async function (req, res) {const registrationType = meta.config.registrationType || 'normal';@@ -109,6 +110,7 @@ authenticationController.register = async function (req, res) {}};+// POST /register/completeauthenticationController.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/abortauthenticationController.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 /loginauthenticationController.login = async (req, res, next) => {let { strategy } = await plugins.hooks.fire('filter:login.override', { req, strategy: 'local' });if (!passport._strategy(strategy)) {diff --git a/src/controllers/index.js b/src/controllers/index.jsindex 879774c17f..0336db8d1d 100644--- a/src/controllers/index.js+++ b/src/controllers/index.js@@ -192,6 +192,7 @@ Controllers.register = async function (req, res, next) {}};+// GET /register/completeControllers.registerInterstitial = async function (req, res, next) {if (!req.session.hasOwnProperty('registration')) {return res.redirect(`${nconf.get('relative_path')}/register`);diff --git a/src/user/interstitials.js b/src/user/interstitials.jsindex 672af70d80..1558899497 100644--- a/src/user/interstitials.js+++ b/src/user/interstitials.js@@ -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({diff --git a/src/user/invite.js b/src/user/invite.jsindex 344e09fd6b..fd308af56c 100644--- a/src/user/invite.js+++ b/src/user/invite.js@@ -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) {