mirror of
				https://github.com/NodeBB/NodeBB.git
				synced 2025-10-31 02:55:58 +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) { | 		if (data.email && userData.uid > 1) { | ||||||
| 			await User.email.sendValidationEmail(userData.uid, { | 			if (!data.token || !await User.isInviteTokenValid(data.token, data.email)) { | ||||||
| 				email: data.email, | 				await User.email.sendValidationEmail(userData.uid, { | ||||||
| 				template: 'welcome', | 					email: data.email, | ||||||
| 				subject: `[[email:welcome-to, ${meta.config.title || meta.config.browserTitle || 'NodeBB'}]]`, | 					template: 'welcome', | ||||||
| 			}).catch(err => winston.error(`[user.create] Validation email failed to send\n[emailer.send] ${err.stack}`)); | 					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) { | 		if (userNameChanged) { | ||||||
| 			await User.notifications.sendNameChangeNotification(userData.uid, userData.username); | 			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) { | 	User.confirmIfInviteEmailIsUsed = async function (token, enteredEmail, uid) { | ||||||
| 		if (!enteredEmail) { | 		if (!enteredEmail) { | ||||||
| 			return; | 			return; | ||||||
|   | |||||||
		Reference in New Issue
	
	Block a user