Created
October 3, 2016 02:12
-
-
Save sungwoncho/3debebf11704a60d09108aa739b09baf 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
login(req, res) { | |
const { username, shaHash } = req.body; | |
res.setHeader('Content-Type', 'application/json'); | |
User.findOne({ username, verified: true }, (err, user) => { | |
if (!user) { | |
console.log('No user with that username found or not verified'); | |
res.status(500); | |
res.end(); | |
return; | |
} | |
console.log('user', user); | |
bcrypt.compare(shaHash, user.password, (err, isMatch) => { | |
if (err) { | |
console.log('err', err); | |
res.status(500); | |
res.end(); | |
return; | |
} | |
if (isMatch) { | |
res.status(200); | |
res.end(JSON.stringify(user)); | |
} else { | |
res.status(500); | |
res.end(); | |
} | |
}); | |
}); | |
} |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment