Documentation
¶
Overview ¶
Package reset provides password reset token management functionality
Index ¶
- func ValidateConfig(cfg *Config) error
- type CleanupService
- type Config
- type TokenManager
- func (tm *TokenManager) CleanupExpiredTokens(ctx context.Context) error
- func (tm *TokenManager) CreateToken(ctx context.Context, userID int32) (*models.PasswordResetToken, error)
- func (tm *TokenManager) GetTokenStats(ctx context.Context) (*models.GetPasswordResetTokenStatsRow, error)
- func (tm *TokenManager) GetTokenTimeRemaining(token *models.PasswordResetToken) time.Duration
- func (tm *TokenManager) InvalidateUserTokens(ctx context.Context, userID int32) error
- func (tm *TokenManager) UseToken(ctx context.Context, token string) error
- func (tm *TokenManager) ValidateToken(ctx context.Context, token string) (*models.PasswordResetToken, error)
Constants ¶
This section is empty.
Variables ¶
This section is empty.
Functions ¶
func ValidateConfig ¶
ValidateConfig validates a password reset token configuration
Types ¶
type CleanupService ¶
type CleanupService struct {
// contains filtered or unexported fields
}
CleanupService handles periodic cleanup of expired password reset tokens
func NewCleanupService ¶
func NewCleanupService(tokenManager *TokenManager, interval time.Duration, logger *slog.Logger) *CleanupService
NewCleanupService creates a new cleanup service
func (*CleanupService) RunOnce ¶
func (cs *CleanupService) RunOnce(ctx context.Context) error
RunOnce performs a single cleanup operation (useful for testing or manual cleanup)
func (*CleanupService) Start ¶
func (cs *CleanupService) Start(ctx context.Context)
Start begins the cleanup service in a background goroutine
func (*CleanupService) Stop ¶
func (cs *CleanupService) Stop()
Stop gracefully stops the cleanup service
type Config ¶
type Config struct {
TokenLength int // Length of generated tokens (default: 32)
TokenLifetime time.Duration // How long tokens are valid (default: 1 hour)
CleanupInterval time.Duration // How often to clean up expired tokens (default: 24 hours)
MaxTokensPerUser int // Maximum active tokens per user (default: 3)
}
Config contains configuration for password reset tokens
func DefaultConfig ¶
func DefaultConfig() Config
DefaultConfig returns the default configuration for password reset tokens
func LoadConfigFromViper ¶
LoadConfigFromViper loads password reset token configuration from viper settings
type TokenManager ¶
type TokenManager struct {
// contains filtered or unexported fields
}
TokenManager handles password reset token operations
func NewTokenManager ¶
func NewTokenManager(queries models.Querier, config *Config) *TokenManager
NewTokenManager creates a new password reset token manager
func (*TokenManager) CleanupExpiredTokens ¶
func (tm *TokenManager) CleanupExpiredTokens(ctx context.Context) error
CleanupExpiredTokens removes expired tokens from the database
func (*TokenManager) CreateToken ¶
func (tm *TokenManager) CreateToken(ctx context.Context, userID int32) (*models.PasswordResetToken, error)
CreateToken creates a new password reset token for the given user
func (*TokenManager) GetTokenStats ¶
func (tm *TokenManager) GetTokenStats(ctx context.Context) (*models.GetPasswordResetTokenStatsRow, error)
GetTokenStats returns statistics about password reset tokens
func (*TokenManager) GetTokenTimeRemaining ¶
func (tm *TokenManager) GetTokenTimeRemaining(token *models.PasswordResetToken) time.Duration
GetTokenTimeRemaining returns the time remaining before a token expires
func (*TokenManager) InvalidateUserTokens ¶
func (tm *TokenManager) InvalidateUserTokens(ctx context.Context, userID int32) error
InvalidateUserTokens invalidates all active password reset tokens for a user
func (*TokenManager) UseToken ¶
func (tm *TokenManager) UseToken(ctx context.Context, token string) error
UseToken marks a password reset token as used
func (*TokenManager) ValidateToken ¶
func (tm *TokenManager) ValidateToken(ctx context.Context, token string) (*models.PasswordResetToken, error)
ValidateToken validates a password reset token and returns the token if valid