otp

package
v1.0.3 Latest Latest
Warning

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

Go to latest
Published: Mar 20, 2024 License: MIT Imports: 5 Imported by: 0

Documentation

Index

Constants

This section is empty.

Variables

This section is empty.

Functions

This section is empty.

Types

type Builder

type Builder struct {
	Data     *string
	MetaData map[string]string
}

func NewBuilder

func NewBuilder(data *string, metaData map[string]string) *Builder

func (*Builder) Build

func (d *Builder) Build() (string, error)

type EmailCode

type EmailCode struct {
	CreatedAt time.Time `json:"CreatedAt" bson:"CreatedAt"`
	Purpose   string    `json:"Purpose" bson:"Purpose"`
	Code      string    `json:"Code" bson:"Code"`
	Entity    string    `json:"Entity" bson:"Entity"` // something identifying the Entity, maybe the user email address
}

type OTP

type OTP struct {
	CM         Store
	ExpireIn   time.Duration
	CodeLength int
}

func NewOTP

func NewOTP(cm Store, expireIn time.Duration, codeLength int) *OTP

NewOTP creates a new OTP

func (*OTP) ProcessEmailsCode

func (o *OTP) ProcessEmailsCode(interval time.Duration) func()

ProcessEmailsCode processes the codes by spawning a ticker of teh specified interval. It checks the codes and removes the expired ones from the list of codes It returns a function to stop the process.

func (*OTP) Send

func (o *OTP) Send(
	email *emailutils.Email,
	provider emailutils.Provider,
	purpose, entity string,
) error

Send sends an email with the code and registers it. It will assume your email subject and body has a template with the following keys: - {{.Code}}: the code to send

func (*OTP) Verify

func (o *OTP) Verify(code, purpose, entity string) bool

Verify verifies the code and removes it from the list of codes if verified

type Store

type Store interface {
	Register(code, purpose, entity string) (*EmailCode, error)
	List() ([]EmailCode, error)
	Get(code, purpose string) (*EmailCode, error)
	Remove(code, purpose string) error
}

Jump to

Keyboard shortcuts

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