Skip to content

Instantly share code, notes, and snippets.

@PavelDemyanenko
Last active August 29, 2015 14:14
Show Gist options
  • Save PavelDemyanenko/605d88d09aa271038e75 to your computer and use it in GitHub Desktop.
Save PavelDemyanenko/605d88d09aa271038e75 to your computer and use it in GitHub Desktop.
authController
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