Guest User

Untitled

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