mirror of
				https://github.com/NodeBB/NodeBB.git
				synced 2025-10-31 02:55:58 +01:00 
			
		
		
		
	feat: show a friendly message on invalid or expired code, closes #12738
This commit is contained in:
		| @@ -219,20 +219,31 @@ Controllers.registerInterstitial = async function (req, res, next) { | ||||
| 	} | ||||
| }; | ||||
|  | ||||
| Controllers.confirmEmail = async (req, res, next) => { | ||||
| Controllers.confirmEmail = async (req, res) => { | ||||
| 	function renderPage(opts = {}) { | ||||
| 		res.render('confirm', { | ||||
| 			title: '[[pages:confirm]]', | ||||
| 			...opts, | ||||
| 		}); | ||||
| 	} | ||||
| 	try { | ||||
| 		if (req.uid) { | ||||
| 			const emailValidated = await user.getUserField(req.uid, 'email:confirmed'); | ||||
| 			if (emailValidated) { | ||||
| 				return renderPage({ alreadyValidated: true }); | ||||
| 			} | ||||
| 		} | ||||
| 		await user.email.confirmByCode(req.params.code, req.session.id); | ||||
| 		if (req.session.registration) { | ||||
| 			// After confirmation, no need to send user back to email change form | ||||
| 			delete req.session.registration.updateEmail; | ||||
| 		} | ||||
|  | ||||
| 		res.render('confirm', { | ||||
| 			title: '[[pages:confirm]]', | ||||
| 		}); | ||||
| 		renderPage(); | ||||
| 	} catch (e) { | ||||
| 		if (e.message === '[[error:invalid-data]]') { | ||||
| 			return next(); | ||||
| 		if (e.message === '[[error:invalid-data]]' || e.message === '[[error:confirm-email-expired]]') { | ||||
| 			renderPage({ error: true }); | ||||
| 			return; | ||||
| 		} | ||||
|  | ||||
| 		throw e; | ||||
|   | ||||
		Reference in New Issue
	
	Block a user