Created
October 18, 2017 00:42
-
-
Save higordiego/8dcecd949d5ea4364cb3c8e1477e3ee7 to your computer and use it in GitHub Desktop.
This file contains hidden or 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
module.exports = app => { | |
const User = app.datasource.models.User | |
const Business = require('../business/authenticate')(app) | |
const crypto = require('../../helpers/crypto') | |
const Errors = require('../../errors/sistem/pt-br') | |
return { | |
authenticate: (req, res) => { | |
const query = { | |
attributes: { | |
exclude: ['password', 'created_at', 'updated_at', 'master', 'token', 'forgot', 'active'] | |
}, | |
where: { | |
$and: [{ | |
email: req.body.email | |
}, { | |
password: crypto.md5(req.body.password) | |
}] | |
} | |
} | |
User.findOne(query) | |
.then(user => | |
user | |
? Business.authenticate(user, res) | |
: res.status(401).json([Errors.notAuthorization]) | |
).catch(err => console.log(err)) | |
} | |
} | |
} |
This file contains hidden or 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
module.exports = app => { | |
const User = app.datasource.models.User | |
const Business = require('../business/authenticate')(app) | |
const crypto = require('../../helpers/crypto') | |
const Errors = require('../../errors/sistem/pt-br') | |
const Validate = require('../../helpers/validate') | |
return { | |
authenticate: (req, res) => { | |
const query = { | |
attributes: { | |
exclude: ['password', 'created_at', 'updated_at', 'master', 'token', 'forgot', 'active'] | |
}, | |
where: { | |
$and: [{ | |
email: req.body.email | |
}, { | |
password: crypto.md5(req.body.password) | |
}] | |
} | |
} | |
Validate.searchQuery(User, query) | |
.then(Validate.isEmptyObject(res, Errors.notAuthorization)) | |
.then(Business.authenticate(res)) | |
.catch(err => console.log(err)) | |
} | |
} | |
} |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment