This repository has been archived on 2023-07-11. You can view files and clone it, but cannot push or open issues or pull requests.
nginx-ldap-auth/user/service.go

40 lines
661 B
Go

package user
import (
"strings"
"github.com/tiagoapimenta/nginx-ldap-auth/ldap"
gldap "gopkg.in/ldap.v2"
)
type Service struct {
pool *ldap.Pool
base string
filter string
}
func NewService(pool *ldap.Pool, base, filter string) *Service {
return &Service{
pool: pool,
base: base,
filter: filter,
}
}
func (p *Service) Find(username string) (bool, string, error) {
username = gldap.EscapeFilter(username)
ok, id, _, err := p.pool.Search(
p.base,
strings.Replace(p.filter, "{0}", username, -1),
"",
)
return ok, id, err
}
func (p *Service) Login(id, password string) (bool, error) {
return p.pool.Validate(id, password)
}