Files
hfb_sys/backend/internal/modules/adminauth/service.go
T
2026-05-22 17:20:47 +08:00

43 lines
1.1 KiB
Go

package adminauth
import "errors"
var (
ErrDependencyUnavailable = errors.New("dependency unavailable")
ErrInvalidCredential = errors.New("invalid credential")
ErrCaptchaInvalid = errors.New("captcha invalid")
ErrAdminDisabled = errors.New("admin disabled")
)
type Service struct {
repo *Repository
}
func NewService(repo *Repository) *Service {
return &Service{repo: repo}
}
func (s *Service) Captcha() (*CaptchaDTO, error) {
if s.repo == nil {
return nil, ErrDependencyUnavailable
}
return s.repo.Captcha()
}
func (s *Service) Login(username string, password string, captchaID string, captchaCode string) (LoginResult, error) {
if s.repo == nil {
return LoginResult{}, ErrDependencyUnavailable
}
if username == "" || password == "" || captchaID == "" || captchaCode == "" {
return LoginResult{}, ErrInvalidCredential
}
return s.repo.Login(username, password, captchaID, captchaCode)
}
func (s *Service) Me(adminID uint64) (*AdminDTO, error) {
if s.repo == nil {
return nil, ErrDependencyUnavailable
}
return s.repo.FindByID(adminID)
}