2020-10-02 01:11:05 -05:00
|
|
|
const bcrypt = require('bcrypt')
|
|
|
|
|
const Operador = require('../../db/tables/Operador')
|
|
|
|
|
|
|
|
|
|
const login = (body) => {
|
|
|
|
|
return Operador.findOne({ where: { nombre: body.nombre } })
|
|
|
|
|
.then((res) => {
|
|
|
|
|
if (res) {
|
2020-10-02 11:55:27 -05:00
|
|
|
if (!bcrypt.compareSync(body.password, res.password)) {
|
2020-10-02 01:11:05 -05:00
|
|
|
throw new Error('El usuario o contraseña son incorrectos.')
|
2020-10-02 11:55:27 -05:00
|
|
|
}
|
2020-10-02 01:11:05 -05:00
|
|
|
return { res }
|
|
|
|
|
}
|
|
|
|
|
throw new Error('El usuario o contraseña son incorrectos.')
|
|
|
|
|
})
|
|
|
|
|
.catch((err) => {})
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
module.exports = login
|
2020-10-02 11:55:27 -05:00
|
|
|
|
|
|
|
|
// login({ nombre: 'lemuel', password: 'hola' })
|