Redirect to normal page on invalid referral code

We don't want to be misleading people with random referral links
that don't actually apply!
This commit is contained in:
Badri 2022-02-20 15:56:38 +05:30
parent d9785d601e
commit 11cefdada0

View file

@ -224,6 +224,10 @@ let homeView = async (req, res) => {
referrer = pledge.get('anonymous') ? 'Anonymous' : pledge.get('name')
} catch(e) {
if (DEBUG) console.debug(`Skipping referral ${req.params.referralCode} because not found: ${e}`)
// if the referrer doesn't exist, send people to the normal homepage!
res.redirect('/')
return
}
}
@ -687,6 +691,13 @@ The Snipette Team`
})
router.get('/thanks', async (req, res) => {
// validate referral code
if (!!req.query.ref && !await findReferrer(req.query.ref)) {
if (DEBUG) console.debug(`Invalid referral: redirecting to normal page`)
res.redirect('/thanks')
return
}
let output = await twing.render('thanks.htm.twig', {
referral_code: req.query.ref,
})