Secure your code as it's written. Use Snyk Code to scan source code in minutes - no build needed - and fix issues immediately.
.post((req, res) => {
if (!req.body.email) return res.status(422).json('email not set');
Authentication.findOne({ 'email': req.body.email })
.then(() => {
return randomBytes(64);
})
.then(buf => {
const random = buf.toString('hex');
// save reset code for a day
req.uwave.redis.set(`reset:${user.req.body.email}`, random, `NX EXPIRE ${24*60*60}`);
res.status(200).json(random);
})
.catch(redis.ReplyError, e => {
log(`couldn't set reset link. Err: ${e}`);
res.status(410).json('could not generate reset code');
})
.catch(e => {
log(`error occured while generating reset code. Err: ${e}`);
res.status(500).json('internal server error, please try again later');
});
})