Advertisement
Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- module.exports = {
- index: function (req, res) {
- var email = req.param('email');
- var password = req.param('password');
- req.checkBody('email', res.i18n('auth.policy.requiredEmail')).notEmpty();
- req.checkBody('password', res.i18n('auth.policy.requiredSenha')).notEmpty();
- var errors = req.validationErrors();
- if (errors) {
- return res.json(401, {err: errors});
- }
- User.findOne({email: email}, function (err, user) {
- if (!user) {
- return res.json(401, {err: 'invalid email or password'});
- }
- User.comparePassword(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: jwToken.issue({id : user.id })
- });
- }
- });
- })
- }
- };
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement