-
-
Save aanchirinah/4279a7007eb52042f23cdd4ff6ed4f21 to your computer and use it in GitHub Desktop.
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
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