Last active
August 29, 2015 14:14
-
-
Save PavelDemyanenko/605d88d09aa271038e75 to your computer and use it in GitHub Desktop.
authController
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
authenticate: function(req, res) { | |
var email = req.param('email'); | |
var password = req.param('password'); | |
if (!email || !password) { | |
return res.json(401, {err: 'email and password required'}); | |
} | |
User.findOneByEmail(email, function(err, user) { | |
if (!user) { | |
return res.json(401, {err: 'invalid email or password'}); | |
} | |
User.validPassword(password, user, function(err, valid) { | |
if (err) { | |
return res.json(403, {err: 'forbidden'}); | |
} | |
if (!valid) { | |
return res.json(401, {err: 'invalid email or password'}); | |
} else { | |
res.json({user: user, token: sailsTokenAuth.issueToken(user.id)}); | |
} | |
}); | |
}) | |
} |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment