Help us shape the future of Go! Take the 2026 Go Developer Survey

verifycode

package
v1.21.2 Latest Latest
Warning

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

Go to latest
Published: Oct 27, 2026 License: GPL-3.0 Imports: 24 Imported by: 0

Documentation

Overview

Package verifycode implements the verification-code subdomain of the identity module: issuing and pre-checking the email and SMS codes that gate registration and account mutations. Only the module facade may reach it.

Index

Constants

View Source
const (
	CodesPerIPPerHour = 20
)

Every code costs a delivery, and an SMS costs money. The per-address quotas alone do not bound a client that rotates addresses, so each client address also gets CodesPerIPPerHour codes an hour, whatever the addresses: enough for a person retrying a form or binding several addresses, far too few for a bombing or pumping script. An unknown address shares one quota.

View Source
const IntervalTime = 60

IntervalTime is the default number of seconds between two codes sent to one address.

Variables

This section is empty.

Functions

This section is empty.

Types

type Deps

type Deps struct {
	Store  VerificationIdentityStore
	Redis  *redis.Client
	Queue  VerificationTaskQueue
	Policy registerpolicy.Policy
	// Config snapshots the runtime-mutable settings per request.
	Config func() Snapshot
}

Deps declares the subdomain's dependencies; the identity facade forwards them from the composition root and supplies the account policy from the authentication subdomain.

type Service

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

Service is the verification-code subdomain entry point used by the identity facade.

func NewService

func NewService(deps Deps) *Service

NewService builds the subdomain over the dependencies the facade forwards.

func (*Service) CheckVerificationCode

CheckVerificationCode pre-checks a code without consuming it, for the UI. The phone number is normalized the way SendSmsCode stored it, so a number written with separators still matches its code.

func (*Service) SendEmailCode

func (s *Service) SendEmailCode(ctx context.Context, req *dto.SendCodeRequest) (*dto.SendCodeResponse, error)

SendEmailCode sends a verification code to an email address: a register code to an address no account has, a security code to one an account has.

func (*Service) SendSmsCode

func (s *Service) SendSmsCode(ctx context.Context, req *dto.SendSmsCodeRequest) (*dto.SendCodeResponse, error)

SendSmsCode sends a verification code to a phone number: a register code to a number no account has, a security code to one an account has. The code is stored under the number's E.164 form, the one every checker uses.

type Snapshot

type Snapshot struct {
	DomainSuffixList   string
	EnableDomainSuffix bool
	VerifyCodeInterval int64
	VerifyCodeLimit    int64
	VerifyCodeExpire   int64
	// MobileWhitelist lists the area codes SMS codes may be sent to when
	// MobileWhitelistEnabled is set.
	MobileWhitelistEnabled bool
	MobileWhitelist        []string
	SiteName               string
}

Snapshot is the per-request view of the runtime-mutable settings the verification-code flows consume.

type VerificationIdentityStore

type VerificationIdentityStore interface {
	UserAuth() repository.UserAuthRepo
}

VerificationIdentityStore is the persistence surface the code flows use to tell registration from security codes.

type VerificationTaskQueue

type VerificationTaskQueue interface {
	EnqueueContext(ctx context.Context, task *asynq.Task, opts ...asynq.Option) (*asynq.TaskInfo, error)
}

VerificationTaskQueue publishes verification-code delivery tasks.

Jump to

Keyboard shortcuts

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