-
Notifications
You must be signed in to change notification settings - Fork 0
/
usuario_dao.go
39 lines (30 loc) · 941 Bytes
/
usuario_dao.go
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
package dao
import "github.com/helderfarias/ges/api/lib/orm"
import "github.com/helderfarias/ges/api/dominio"
import "github.com/helderfarias/ges/api/util"
import "errors"
const (
SQL_BUSCAR_USUARIO_POR_LOGIN = `SELECT nome, senha
FROM usuarios
WHERE login = :login`
)
type UsuarioDAO interface {
Existe(login, senha string) (*dominio.Usuario, error)
}
type usuarioDAO struct {
em orm.EntityManager
}
func NewUsuarioDAO(em orm.EntityManager) UsuarioDAO {
return &usuarioDAO{em: em}
}
func (s *usuarioDAO) Existe(login, senha string) (*dominio.Usuario, error) {
var usuario dominio.Usuario
err := s.em.Get(&usuario, SQL_BUSCAR_USUARIO_POR_LOGIN, map[string]interface{}{"login": login})
if err != nil {
return nil, err
}
if !util.ComparePassword(senha, usuario.Senha) {
return nil, errors.New("Credências não confere")
}
return &usuario, err
}