utils

package
v0.0.0-...-c968cd1 Latest Latest
Warning

This package is not in the latest version of its module.

Go to latest
Published: Apr 9, 2025 License: MIT Imports: 8 Imported by: 0

Documentation

Index

Constants

This section is empty.

Variables

This section is empty.

Functions

func AddPendingReset

func AddPendingReset(email string, reset PendingReset)

Reset Functions

func AddPendingUser

func AddPendingUser(email string, user PendingUser)

Registration Functions

func CleanupExpiredCache

func CleanupExpiredCache()

func CleanupExpiredRegistrations

func CleanupExpiredRegistrations()

Cleanup Functions

func CleanupExpiredResets

func CleanupExpiredResets()

func DeletePendingReset

func DeletePendingReset(email string)

func DeletePendingUser

func DeletePendingUser(email string)

func GenerateOTP

func GenerateOTP() string

GenerateOTP generates a 6-digit OTP

func GenerateRefreshToken

func GenerateRefreshToken(userID uint) (string, time.Time, error)

GenerateRefreshToken generates a refresh token

func GenerateToken

func GenerateToken(userID uint, role string) (string, error)

GenerateToken generates a JWT token for a user

func IncrementPendingResetAttempts

func IncrementPendingResetAttempts(email string)

func IncrementPendingUserAttempts

func IncrementPendingUserAttempts(email string)

Types

type Claims

type Claims struct {
	UserID    uint   `json:"user_id"`
	Role      string `json:"role"`
	TokenType string `json:"token_type"`
	jwt.RegisteredClaims
}

Claims represents the JWT claims

func ValidateToken

func ValidateToken(tokenString string, expectedTokenType string) (*Claims, error)

ValidateToken validates a JWT token

type PendingReset

type PendingReset struct {
	Email        string    // User's email
	OTP          string    // One-time password
	OTPExpiresAt time.Time // When the OTP expires
	LastOTPSent  time.Time // When the last OTP was sent
	Attempts     int       // Number of OTP attempts
	CreatedAt    time.Time // When the reset was initiated
}

PendingReset represents a password reset request waiting for OTP verification

func GetPendingReset

func GetPendingReset(email string) (PendingReset, bool)

type PendingUser

type PendingUser struct {
	Name         string    // User's name
	Email        string    // User's email
	PasswordHash string    // Hashed password
	OTP          string    // One-time password
	OTPExpiresAt time.Time // When the OTP expires
	LastOTPSent  time.Time // When the last OTP was sent
	Attempts     int       // Number of OTP attempts
	CreatedAt    time.Time // When the registration was initiated
}

PendingUser represents a user waiting for OTP verification during registration

func GetPendingUser

func GetPendingUser(email string) (PendingUser, bool)

Jump to

Keyboard shortcuts

? : This menu
/ : Search site
f or F : Jump to
y or Y : Canonical URL