Documentation
¶
Index ¶
- type DatabaseService
- func (s *DatabaseService) ClearExpiredTokens() error
- func (s *DatabaseService) ConsumeToken(ctx context.Context, token string) error
- func (s *DatabaseService) GenerateToken(ctx context.Context, userID string) (string, error)
- func (s *DatabaseService) GetExpiredTokenCount() (int64, error)
- func (s *DatabaseService) GetTokenCount() (int64, error)
- func (s *DatabaseService) GetTotalTokenCount() (int64, error)
- func (s *DatabaseService) GetUsedTokenCount() (int64, error)
- func (s *DatabaseService) IsTokenUsed(token string) (bool, error)
- func (s *DatabaseService) ValidateToken(ctx context.Context, token string) (string, error)
- type PasswordResetServiceInterface
- type PasswordResetToken
- type Service
Constants ¶
This section is empty.
Variables ¶
This section is empty.
Functions ¶
This section is empty.
Types ¶
type DatabaseService ¶
type DatabaseService struct {
// contains filtered or unexported fields
}
DatabaseService manages password reset tokens using database instead of Redis
func NewDatabaseService ¶
func NewDatabaseService(db *gorm.DB, ttl time.Duration) *DatabaseService
NewDatabaseService creates a new database-based password reset service
func (*DatabaseService) ClearExpiredTokens ¶
func (s *DatabaseService) ClearExpiredTokens() error
ClearExpiredTokens removes expired tokens from the database
func (*DatabaseService) ConsumeToken ¶
func (s *DatabaseService) ConsumeToken(ctx context.Context, token string) error
ConsumeToken deletes the token to enforce single-use semantics
func (*DatabaseService) GenerateToken ¶
GenerateToken creates a new secure token for the given user ID and stores it in database Returns the token string which should be sent to the user via email link
func (*DatabaseService) GetExpiredTokenCount ¶
func (s *DatabaseService) GetExpiredTokenCount() (int64, error)
GetExpiredTokenCount returns the number of expired tokens that can be cleaned up
func (*DatabaseService) GetTokenCount ¶
func (s *DatabaseService) GetTokenCount() (int64, error)
GetTokenCount returns the number of active (unused and not expired) tokens
func (*DatabaseService) GetTotalTokenCount ¶
func (s *DatabaseService) GetTotalTokenCount() (int64, error)
GetTotalTokenCount returns the total number of tokens in the database
func (*DatabaseService) GetUsedTokenCount ¶
func (s *DatabaseService) GetUsedTokenCount() (int64, error)
GetUsedTokenCount returns the number of used tokens
func (*DatabaseService) IsTokenUsed ¶
func (s *DatabaseService) IsTokenUsed(token string) (bool, error)
IsTokenUsed checks if a token has been used
func (*DatabaseService) ValidateToken ¶
ValidateToken returns the associated userID if the token exists and is not expired
type PasswordResetServiceInterface ¶
type PasswordResetServiceInterface interface { GenerateToken(ctx context.Context, userID string) (string, error) ValidateToken(ctx context.Context, token string) (string, error) ConsumeToken(ctx context.Context, token string) error }
PasswordResetServiceInterface defines the interface for password reset operations
func NewPasswordResetServiceFactory ¶
func NewPasswordResetServiceFactory(redisClient *redis.Client, db *gorm.DB, ttl time.Duration) PasswordResetServiceInterface
NewPasswordResetServiceFactory creates password reset service based on environment configuration
type PasswordResetToken ¶
type PasswordResetToken struct { model.Base Token string `gorm:"uniqueIndex;not null" json:"token"` UserID string `gorm:"not null;index" json:"user_id"` ExpiresAt time.Time `gorm:"not null;index" json:"expires_at"` IsUsed bool `gorm:"default:false;index" json:"is_used"` }
PasswordResetToken represents a password reset token in the database
type Service ¶
type Service struct {
// contains filtered or unexported fields
}
Service manages password reset tokens using Redis with expiry and single-use semantics.
func NewService ¶
func (*Service) ConsumeToken ¶
ConsumeToken deletes the token to enforce single-use semantics.
func (*Service) GenerateToken ¶
GenerateToken creates a new secure token for the given user ID and stores it in Redis. Returns the token string which should be sent to the user via email link.