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