This commit is contained in:
2026-03-20 12:33:37 +01:00
commit ce3925423f
44 changed files with 3143 additions and 0 deletions

32
internal/auth/service.go Normal file
View File

@@ -0,0 +1,32 @@
package auth
import (
"ResendIt/internal/security"
"ResendIt/internal/user"
"errors"
)
type Service struct {
repo *Repository
}
func NewService(r *Repository) *Service {
return &Service{repo: r}
}
func (s *Service) Login(username, password string) (string, error) {
u, err := s.repo.FindByUsername(username)
if errors.Is(err, user.ErrUserNotFound) {
// Prevent user enumeration by returning a generic error message
return "", ErrInvalidCredentials
} else if err != nil {
return "", err
}
if !security.CheckPassword(password, u.PasswordHash) {
return "", ErrInvalidCredentials
}
return GenerateJWT(u.Username, u.Role)
}