-
-
Save suissa/a17079973a24b1f497e4e88feedaaff3 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
const crypto = require('../../helpers/crypto') | |
const Errors = require('../../errors/sistem/pt-br') | |
const Validate = require('../../helpers/validate') | |
const authenticate = (User, Validate, Business, Errors) => (req, res, next) => { | |
const exclude = ['password', | |
'created_at', | |
'updated_at', | |
'master', | |
'token', | |
'forgot', | |
'active' | |
] | |
const query = { | |
attributes: { | |
exclude | |
}, | |
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)) | |
} | |
module.exports = app => { | |
const User = app.datasource.models.User | |
const Business = require('../business/authenticate')(app) | |
return { | |
authenticate: authenticate(User, Validate, Business, Errors) | |
} | |
} |
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