emailverification

package
v0.2.0 Latest Latest
Warning

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

Go to latest
Published: Sep 14, 2026 License: Apache-2.0 Imports: 7 Imported by: ? modules, 0 packages

The first number is the count of modules that contain a package that imports this one. The module count is a better indicator of popularity than the package count. A module with 100 importing packages is counted only once instead of 100 times, reflecting the fact that the choice to use the package was likely made only once, not 100 times.
A '?' means that the value hasn't been computed yet.

Documentation

Overview

Package emailverification manages email ownership verification.

Index

Constants

This section is empty.

Variables

View Source
var (
	ErrAlreadyVerified = errors.New("email already verified")
	ErrAttemptBlocked  = errors.New("email verification attempt blocked")
	ErrConflict        = errors.New("email verification conflict")
	ErrInactiveToken   = errors.New("email verification token is inactive")
	ErrInvalidConfig   = errors.New("invalid email verification configuration")
	ErrInvalidRecord   = errors.New("invalid email verification record")
	ErrInvalidToken    = token.ErrInvalidToken
	ErrNotFound        = errors.New("email verification record not found")
)

Functions

This section is empty.

Types

type Attempt

type Attempt struct {
	Operation Operation
	Email     string
	SourceKey string
}

type AttemptGuard

type AttemptGuard interface {
	Check(ctx context.Context, attempt Attempt) error
}

type Config

type Config struct {
	Lifetime       time.Duration
	Sender         Sender
	AttemptGuard   AttemptGuard
	SecurityEvents SecurityEventSink
	NormalizeEmail emailaddress.Normalizer
	Now            func() time.Time
}

type EventType

type EventType string
const (
	EventMessageSent  EventType = "verification_message_sent"
	EventVerified     EventType = "email_verified"
	EventVerifyFailed EventType = "email_verification_failed"
)

type Manager

type Manager struct {
	// contains filtered or unexported fields
}

func NewManager

func NewManager(store Store, config Config) (*Manager, error)

func (*Manager) IsVerified

func (manager *Manager) IsVerified(ctx context.Context, email string) (bool, error)

func (*Manager) Request

func (manager *Manager) Request(ctx context.Context, input RequestInput) error

func (*Manager) Verify

func (manager *Manager) Verify(ctx context.Context, input VerifyInput) (User, error)

type Message

type Message struct {
	UserID    string
	Email     string
	Token     string
	URL       string
	ExpiresAt time.Time
}

type Operation

type Operation string
const (
	OperationRequest Operation = "request"
	OperationVerify  Operation = "verify"
)

type Record

type Record struct {
	UserID    string
	Email     string
	TokenHash TokenHash
	CreatedAt time.Time
	ExpiresAt time.Time
}

type RequestInput

type RequestInput struct {
	Email     string
	SourceKey string
}

type SecurityEvent

type SecurityEvent struct {
	Type       EventType
	SubjectID  string
	SourceKey  string
	OccurredAt time.Time
}

type SecurityEventSink

type SecurityEventSink interface {
	Record(ctx context.Context, event SecurityEvent)
}

type Sender

type Sender interface {
	SendVerification(ctx context.Context, message Message) error
}

type Store

type Store interface {
	FindUserByEmail(ctx context.Context, normalizedEmail string) (User, error)
	Issue(ctx context.Context, record Record) error
	Verify(ctx context.Context, tokenHash TokenHash, verifiedAt time.Time) (User, error)
}

Issue replaces the user's earlier token. Verify accepts the current token once before expiry and marks the same email as verified in one storage operation.

type TokenHash

type TokenHash token.Hash

type User

type User struct {
	ID       string
	Email    string
	Verified bool
}

type VerifyInput

type VerifyInput struct {
	Token     string
	SourceKey string
}

Jump to

Keyboard shortcuts

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