Documentation
¶
Index ¶
Constants ¶
This section is empty.
Variables ¶
View Source
var ( ErrRedisConnection = &OTPError{Code: "ERR_REDIS_CONNECTION", Message: "Failed to connect to Redis"} ErrGenerateOTP = &OTPError{Code: "ERR_GENERATE_OTP", Message: "Failed to generate OTP"} ErrGenerateToken = &OTPError{Code: "ERR_GENERATE_TOKEN", Message: "Failed to generate token"} ErrInvalidOTP = &OTPError{Code: "ERR_INVALID_OTP", Message: "Invalid OTP"} ErrExpiredOTP = &OTPError{Code: "ERR_EXPIRED_OTP", Message: "OTP expired"} ErrTokenUsed = &OTPError{Code: "ERR_TOKEN_USED", Message: "Token already used"} ErrMaxAttempts = &OTPError{Code: "ERR_MAX_ATTEMPTS", Message: "Maximum attempts exceeded"} ErrWaitBeforeResend = &OTPError{Code: "ERR_WAIT_BEFORE_RESEND", Message: "Please wait before requesting a new OTP"} )
Functions ¶
This section is empty.
Types ¶
type EmailRequest ¶
type EmailRequest struct {
Email string `json:"email"`
}
type EmailResponse ¶
type ErrorHandler ¶
type NewOTP ¶
type NewOTP struct {
// contains filtered or unexported fields
}
NewOTP struct to hold Redis client and context
func Initialize ¶
func Initialize(redisAddr, redisPassword string, redisDB int, maxAttempts int, expirationTime time.Duration) (*NewOTP, error)
Initialize initializes the Redis client and returns a NewOTP struct
func (*NewOTP) GenerateOTP ¶
func (n *NewOTP) GenerateOTP(email string) (*EmailResponse, string, error)
GenerateOTP generates an OTP and stores it along with a session token in Redis
func (*NewOTP) ResendOTP ¶
func (n *NewOTP) ResendOTP(email string) (*EmailResponse, string, error)
ResendOTP resends a new OTP and token to the user
func (*NewOTP) VerifyOTP ¶
func (n *NewOTP) VerifyOTP(req VerifyRequest) (*VerifyResponse, error)
VerifyOTP verifies the provided OTP and session token
type OTPService ¶
type OTPService interface { GenerateOTP(email string) (*EmailResponse, string, error) VerifyOTP(req VerifyRequest) (*VerifyResponse, error) ResendOTP(email string) (*EmailResponse, string, error) }
OTPService defines the methods for generating, sending, verifying, and resending OTPs
type SessionToken ¶
type VerifyRequest ¶
type VerifyResponse ¶
Click to show internal directories.
Click to hide internal directories.