Skip to content

Instantly share code, notes, and snippets.

@aanchirinah
Last active July 28, 2018 09:11
Show Gist options
  • Save aanchirinah/4279a7007eb52042f23cdd4ff6ed4f21 to your computer and use it in GitHub Desktop.
Save aanchirinah/4279a7007eb52042f23cdd4ff6ed4f21 to your computer and use it in GitHub Desktop.
const VerificationController = (req, res) => {
return models.User.find({
where: { email: req.query.email }
})
.then(user => {
if (user.isVerified) {
return res.status(202).json(`Email Already Verified`);
} else {
return models.VerificationToken.find({
where: { token: req.query.verificationToken }
})
.then((foundToken) => {
if(foundToken){
return user
.update({ isVerified: true })
.then(updatedUser => {
return res.status(403).json(`User with ${user.email} has been verified`);
})
.catch(reason => {
return res.status(403).json(`Verification failed`);
});
} else {
return res.status(404).json(`Token expired` );
}
})
.catch(reason => {
return res.status(404).json(`Token expired`);
});
}
})
.catch(reason => {
return res.status(404).json(`Email not found`);
});
export default VerificationController;
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment