mirror of
https://github.com/NodeBB/NodeBB.git
synced 2025-11-01 03:26:04 +01:00
fix: closes #13526, dont send multiple emails when user is invited
This commit is contained in:
@@ -109,11 +109,13 @@ module.exports = function (User) {
|
||||
}
|
||||
|
||||
if (data.email && userData.uid > 1) {
|
||||
await User.email.sendValidationEmail(userData.uid, {
|
||||
email: data.email,
|
||||
template: 'welcome',
|
||||
subject: `[[email:welcome-to, ${meta.config.title || meta.config.browserTitle || 'NodeBB'}]]`,
|
||||
}).catch(err => winston.error(`[user.create] Validation email failed to send\n[emailer.send] ${err.stack}`));
|
||||
if (!data.token || !await User.isInviteTokenValid(data.token, data.email)) {
|
||||
await User.email.sendValidationEmail(userData.uid, {
|
||||
email: data.email,
|
||||
template: 'welcome',
|
||||
subject: `[[email:welcome-to, ${meta.config.title || meta.config.browserTitle || 'NodeBB'}]]`,
|
||||
}).catch(err => winston.error(`[user.create] Validation email failed to send\n[emailer.send] ${err.stack}`));
|
||||
}
|
||||
}
|
||||
if (userNameChanged) {
|
||||
await User.notifications.sendNameChangeNotification(userData.uid, userData.username);
|
||||
|
||||
@@ -72,6 +72,12 @@ module.exports = function (User) {
|
||||
}
|
||||
};
|
||||
|
||||
User.isInviteTokenValid = async function (token, enteredEmail) {
|
||||
if (!token) return false;
|
||||
const email = await db.getObjectField(`invitation:token:${token}`, 'email');
|
||||
return email && email === enteredEmail;
|
||||
};
|
||||
|
||||
User.confirmIfInviteEmailIsUsed = async function (token, enteredEmail, uid) {
|
||||
if (!enteredEmail) {
|
||||
return;
|
||||
|
||||
Reference in New Issue
Block a user