Guest User

Untitled

a guest
Oct 18th, 2017
97
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
text 0.98 KB | None | 0 0
  1. const crypto = require('../../helpers/crypto')
  2. const Errors = require('../../errors/sistem/pt-br')
  3. const Validate = require('../../helpers/validate')
  4.  
  5.  
  6. const authenticate = (User, Validate, Business, Errors) => (req, res, next) => {
  7.  
  8. const exclude = ['password',
  9. 'created_at',
  10. 'updated_at',
  11. 'master',
  12. 'token',
  13. 'forgot',
  14. 'active'
  15. ]
  16. const query = {
  17. attributes: {
  18. exclude
  19. },
  20. where: {
  21. $and: [{
  22. email: req.body.email
  23. }, {
  24. password: crypto.md5(req.body.password)
  25. }]
  26. }
  27. }
  28.  
  29. Validate.searchQuery(User, query)
  30. .then(Validate.isEmptyObject(res, Errors.notAuthorization))
  31. .then(Business.authenticate(res))
  32. .catch(err => console.log(err))
  33. }
  34.  
  35. module.exports = app => {
  36. const User = app.datasource.models.User
  37. const Business = require('../business/authenticate')(app)
  38.  
  39. return {
  40. authenticate: authenticate(User, Validate, Business, Errors)
  41. }
  42. }
Add Comment
Please, Sign In to add comment