blasphem/pkg/auth/user.go

43 lines
840 B
Go
Raw Normal View History

2022-11-12 13:34:39 -05:00
package auth
import (
"github.com/rs/zerolog/log"
)
2022-11-12 15:56:17 -05:00
type UserID string
type GroupID string
type CredID string
2022-11-12 13:34:39 -05:00
type User struct {
2022-11-12 17:42:51 -05:00
ID UserID `json:"id"`
GroupIDs []GroupID `json:"group_ids"`
Data interface{} `json:"data,omitempty"`
2022-11-12 13:34:39 -05:00
UserMetadata
}
type UserMetadata struct {
2022-11-12 17:42:51 -05:00
Active bool `json:"is_active"`
Owner bool `json:"is_owner"`
LocalOnly bool `json:"local_only"`
SystemGenerated bool `json:"system_generated"`
Name string `json:"name"`
2022-11-12 13:34:39 -05:00
}
func (u *User) allowedToAuth() error {
if !u.Active {
2022-11-12 17:58:24 -05:00
return ErrDisabled
2022-11-12 13:34:39 -05:00
}
return nil
}
func (a *Authenticator) getOrCreateUser(c *Credential) (*User, error) {
2022-11-13 09:05:09 -05:00
log.Debug().Interface("userdata", c).Msg("getOrCreateUser")
2022-11-12 17:50:01 -05:00
u := a.store.User(c.UserID)
if u == nil {
2022-11-12 17:58:24 -05:00
return nil, ErrInvalidAuth
2022-11-12 17:50:01 -05:00
}
return u, nil
2022-11-12 13:34:39 -05:00
}