Last active
October 24, 2016 20:08
-
-
Save wheresvic/525b049e88995669f168ea190948c83a 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
var authenticateUser = function(req, res, next) { | |
User.findOne({ username: req.body.username }, function(errFindUser, user) { | |
if (errFindUser) return next(errFindUser); | |
if (user) { | |
return user.verifyPassword(req.body.password, function(errVerifyPassword, isPasswordMatch) { | |
if (errVerifyPassword) return next(errVerifyPassword); | |
if (isPasswordMatch) { | |
return issueToken(user._id, function(errIssueToken, token) { | |
if (errIssueToken) return next(errIssueToken); | |
res.status(200).send(token); | |
}); | |
} | |
res.status(401).send(); | |
}); | |
} | |
res.status(401).send(); | |
}); | |
} |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment