Documentation
¶
Index ¶
- Variables
- func ValidateUsername(username string) error
- type AuthService
- type CreateTokenResult
- type FirstLoginService
- type LoginRequest
- type LoginResult
- type LoginService
- type PasswordResetResult
- type PasswordResetService
- type RegisterRequest
- type RegisterResult
- type RegistrationService
- type RequestPasswordResetResult
- type UserInfo
- type VerificationResult
- type VerificationService
Constants ¶
This section is empty.
Variables ¶
var ( ErrAccountLocked = errors.New("account locked due to too many failed login attempts") ErrEmailNotVerified = errors.New("email address not verified") ErrAccountSuspended = errors.New("account has been suspended") ErrAccountDeleted = errors.New("account has been deleted") ErrInvalidCredentials = errors.New("invalid username or password") MaxFailedLoginAttempts = 3 AccountLockoutDuration = 15 * time.Minute )
var ( // ErrResetTokenInvalid is returned when password reset token is invalid ErrResetTokenInvalid = errors.New("invalid password reset token") // ErrResetTokenExpired is returned when password reset token has expired ErrResetTokenExpired = errors.New("password reset token has expired") // ErrResetFailed is returned when password reset fails ErrResetFailed = errors.New("password reset failed") )
var ( // ErrUsernameInvalid is returned when username format is invalid ErrUsernameInvalid = errors.New("username must be 1-50 characters and contain only letters, numbers, underscores, and hyphens") // ErrUsernameExists is returned when username already exists ErrUsernameExists = errors.New("username already exists") // ErrEmailExists is returned when email already exists ErrEmailExists = errors.New("email address already registered") // ErrRegistrationFailed is returned when registration fails ErrRegistrationFailed = errors.New("registration failed") )
var ( // ErrTokenInvalid is returned when verification token is invalid ErrTokenInvalid = errors.New("invalid verification token") // ErrTokenExpired is returned when verification token has expired ErrTokenExpired = errors.New("verification token has expired") // ErrVerificationFailed is returned when email verification fails ErrVerificationFailed = errors.New("email verification failed") )
Functions ¶
func ValidateUsername ¶
ValidateUsername checks if a username has a valid format
Types ¶
type AuthService ¶
type AuthService struct {
// contains filtered or unexported fields
}
AuthService handles authentication business logic
func NewAuthService ¶
func NewAuthService(passwordHash string) *AuthService
NewAuthService creates a new auth service with default admin credentials
type CreateTokenResult ¶
CreateTokenResult contains the result of token creation
type FirstLoginService ¶
type FirstLoginService struct {
// contains filtered or unexported fields
}
FirstLoginService manages first-login setup state by deriving it from the database. Setup is considered complete when the admin password differs from the default.
func NewFirstLoginService ¶
func NewFirstLoginService(defaultPasswordHash string) *FirstLoginService
NewFirstLoginService creates a new first-login service
func (*FirstLoginService) IsSetupComplete ¶
func (f *FirstLoginService) IsSetupComplete(currentAdminHash string) bool
IsSetupComplete returns whether first-login setup is complete by comparing the current admin password hash against the default password hash.
type LoginRequest ¶
LoginRequest represents a login request
type LoginResult ¶
LoginResult represents the result of a successful login
type LoginService ¶
type LoginService struct {
// contains filtered or unexported fields
}
LoginService handles login business logic with account lockout
func NewLoginService ¶
func NewLoginService( userRepo repository.UserRepo, failedLoginRepo repository.FailedLoginAttemptRepo, logger *util.Logger, ) *LoginService
NewLoginService creates a new login service
func (*LoginService) GetFailedLoginAttempts ¶
GetFailedLoginAttempts returns the number of failed login attempts for a user
func (*LoginService) IsAccountLocked ¶
func (s *LoginService) IsAccountLocked(ctx context.Context, username string) (bool, *time.Time, error)
IsAccountLocked checks if an account is currently locked
func (*LoginService) Login ¶
func (s *LoginService) Login(ctx context.Context, req LoginRequest) (*LoginResult, error)
Login performs login with account lockout mechanism
type PasswordResetResult ¶
PasswordResetResult contains the result of a successful password reset
type PasswordResetService ¶
type PasswordResetService struct {
// contains filtered or unexported fields
}
PasswordResetService handles password reset business logic
func NewPasswordResetService ¶
func NewPasswordResetService( userRepo repository.UserRepo, tokenRepo repository.PasswordResetTokenRepo, expirationHours int, ) *PasswordResetService
NewPasswordResetService creates a new password reset service
func (*PasswordResetService) RequestPasswordReset ¶
func (s *PasswordResetService) RequestPasswordReset(ctx context.Context, email string) (*RequestPasswordResetResult, error)
RequestPasswordReset creates a password reset token for a user
func (*PasswordResetService) ResetPassword ¶
func (s *PasswordResetService) ResetPassword(ctx context.Context, token, newPassword string) (*PasswordResetResult, error)
ResetPassword verifies the token and updates the user's password
type RegisterRequest ¶
type RegisterRequest struct {
Username string `json:"username"`
Name string `json:"name"`
Email string `json:"email"`
Password string `json:"password"`
}
RegisterRequest represents a user registration request
type RegisterResult ¶
RegisterResult contains the result of a successful registration
type RegistrationService ¶
type RegistrationService struct {
// contains filtered or unexported fields
}
RegistrationService handles user registration business logic
func NewRegistrationService ¶
func NewRegistrationService(userRepo repository.UserRepo) *RegistrationService
NewRegistrationService creates a new registration service
func (*RegistrationService) RegisterUser ¶
func (s *RegistrationService) RegisterUser(ctx context.Context, req RegisterRequest) (*RegisterResult, error)
RegisterUser registers a new user with validation
type RequestPasswordResetResult ¶
RequestPasswordResetResult contains the result of a password reset request
type VerificationResult ¶
VerificationResult contains the result of a successful verification
type VerificationService ¶
type VerificationService struct {
// contains filtered or unexported fields
}
VerificationService handles email verification business logic
func NewVerificationService ¶
func NewVerificationService( userRepo repository.UserRepo, tokenRepo repository.VerificationTokenRepo, expirationHours int, ) *VerificationService
NewVerificationService creates a new verification service
func (*VerificationService) CleanupExpiredTokens ¶
func (s *VerificationService) CleanupExpiredTokens(ctx context.Context) error
CleanupExpiredTokens removes expired tokens from the database
func (*VerificationService) CreateVerificationToken ¶
func (s *VerificationService) CreateVerificationToken(ctx context.Context, userID int) (*CreateTokenResult, error)
CreateVerificationToken creates a new verification token for a user
func (*VerificationService) VerifyEmail ¶
func (s *VerificationService) VerifyEmail(ctx context.Context, token string) (*VerificationResult, error)
VerifyEmail verifies a user's email using a token