update auther interface
This commit is contained in:
12
auth/auth.go
12
auth/auth.go
@ -4,7 +4,7 @@ import "context"
|
|||||||
|
|
||||||
// Authenticator is an interface for user authentication.
|
// Authenticator is an interface for user authentication.
|
||||||
type Authenticator interface {
|
type Authenticator interface {
|
||||||
Authenticate(ctx context.Context, user, password string) (ok bool, id string)
|
Authenticate(ctx context.Context, user, password string) (id string, ok bool)
|
||||||
}
|
}
|
||||||
|
|
||||||
type authenticatorGroup struct {
|
type authenticatorGroup struct {
|
||||||
@ -17,18 +17,18 @@ func AuthenticatorGroup(authers ...Authenticator) Authenticator {
|
|||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
func (p *authenticatorGroup) Authenticate(ctx context.Context, user, password string) (bool, string) {
|
func (p *authenticatorGroup) Authenticate(ctx context.Context, user, password string) (string, bool) {
|
||||||
if len(p.authers) == 0 {
|
if len(p.authers) == 0 {
|
||||||
return false, ""
|
return "", false
|
||||||
}
|
}
|
||||||
for _, auther := range p.authers {
|
for _, auther := range p.authers {
|
||||||
if auther == nil {
|
if auther == nil {
|
||||||
continue
|
continue
|
||||||
}
|
}
|
||||||
|
|
||||||
if ok, id := auther.Authenticate(ctx, user, password); ok {
|
if id, ok := auther.Authenticate(ctx, user, password); ok {
|
||||||
return ok, id
|
return id, ok
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
return false, ""
|
return "", false
|
||||||
}
|
}
|
||||||
|
Reference in New Issue
Block a user