36 lines
592 B
Go
36 lines
592 B
Go
![]() |
package user
|
||
|
|
||
|
import (
|
||
|
"strings"
|
||
|
|
||
|
"github.com/tiagoapimenta/nginx-ldap-auth/ldap"
|
||
|
)
|
||
|
|
||
|
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) {
|
||
|
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)
|
||
|
}
|