Created
October 24, 2016 20:09
-
-
Save wheresvic/0272c92a5ffec2874d6c184b982aafdb 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 authenticateUser = function(req, res, next) { | |
Promise.coroutine(function*() { | |
try { | |
let user = yield User.findOne({ username: req.body.username }); | |
if (user) { | |
let isPasswordMatch = yield user.verifyPassword(req.body.password); | |
if (isPasswordMatch) { | |
let token = yield issueToken(user._id); | |
res.status(200).send(token); | |
return; | |
} | |
} | |
res.status(401).send(); | |
} catch (err) { | |
next(err); | |
} | |
})(); | |
} |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment