Skip to content

Instantly share code, notes, and snippets.

@higordiego
Created October 18, 2017 00:42
Show Gist options
  • Save higordiego/8dcecd949d5ea4364cb3c8e1477e3ee7 to your computer and use it in GitHub Desktop.
Save higordiego/8dcecd949d5ea4364cb3c8e1477e3ee7 to your computer and use it in GitHub Desktop.
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))
}
}
}
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