Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- 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)
- }
- }
Add Comment
Please, Sign In to add comment