Skip to content

Instantly share code, notes, and snippets.

@Octagon-simon
Created October 21, 2022 08:09
Show Gist options
  • Save Octagon-simon/f225d2934cd3111cb21d73d9a32eb6ae to your computer and use it in GitHub Desktop.
Save Octagon-simon/f225d2934cd3111cb21d73d9a32eb6ae to your computer and use it in GitHub Desktop.
//reset route
app.get('/reset', async (req, res) => {
try {
//check for email and hash in query parameter
if (req.query && req.query.email && req.query.hash) {
//find user with suh email address
const user = await User.findOne({ email: req.query.email })
//check if user object is not empty
if (user) {
//now check if hash is valid
if (new User(user).verifyPasswordResetHash(req.query.hash)) {
//save email to session
req.session.email = req.query.email;
//issue a password reset form
return res.sendFile(__dirname + '/views/new_pass.html')
} else {
return res.status(400).json({
message: "You have provided an invalid reset link"
})
}
} else {
return res.status(400).json({
message: "You have provided an invalid reset link"
})
}
} else {
//if there are no query parameters, serve the normal request form
return res.sendFile(__dirname + '/views/reset.html')
}
} catch (err) {
console.log(err)
return res.status(500).json({
message: "Internal server error"
})
}
})
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment