domain

package
v0.0.0-...-a670c85 Latest Latest
Warning

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

Go to latest
Published: Nov 15, 2025 License: AGPL-3.0 Imports: 7 Imported by: 0

Documentation

Index

Constants

This section is empty.

Variables

View Source
var (
	ErrAccountAlreadyExists = errors.New("account already exists")
	ErrAccountNotFound      = errors.New("account not found")
	ErrInvalidEmail         = errors.New("invalid email")
	ErrInvalidPassword      = errors.New("invalid password")
	ErrInvalidCredentials   = errors.New("invalid email or password")
	ErrVerificationToken    = errors.New("verification token invalid or expired")
	ErrPasswordResetToken   = errors.New("password reset token invalid or expired")
	ErrEmailNotVerified     = errors.New("email address not verified")
)

Functions

func NormalizeEmail

func NormalizeEmail(email string) (string, error)

Types

type Account

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

func NewAccount

func NewAccount(id ids.BaseID, email, passwordHash string, now time.Time) (*Account, error)

NewAccount constructs a new account aggregate ensuring email normalization and basic invariants around password hashes are satisfied.

func RestoreAccountFromState

func RestoreAccountFromState(state AccountState) (*Account, error)

RestoreAccountFromState rebuilds an aggregate from persisted state.

func (*Account) ApplyPasswordResetToken

func (a *Account) ApplyPasswordResetToken(token string, expires, now time.Time)

func (*Account) ApplyVerificationToken

func (a *Account) ApplyVerificationToken(token string, expires, now time.Time)

func (*Account) ClearResetToken

func (a *Account) ClearResetToken(now time.Time)

func (*Account) ClearVerificationToken

func (a *Account) ClearVerificationToken(now time.Time)

func (*Account) CreatedAt

func (a *Account) CreatedAt() time.Time

func (*Account) Email

func (a *Account) Email() string

func (*Account) HasValidResetToken

func (a *Account) HasValidResetToken(token string, now time.Time) bool

func (*Account) HasValidVerificationToken

func (a *Account) HasValidVerificationToken(token string, now time.Time) bool

func (*Account) ID

func (a *Account) ID() ids.BaseID

func (*Account) MarkVerified

func (a *Account) MarkVerified(now time.Time)

func (*Account) PasswordHash

func (a *Account) PasswordHash() string

func (*Account) ResetToken

func (a *Account) ResetToken() string

func (*Account) Snapshot

func (a *Account) Snapshot() AccountSnapshot

func (*Account) State

func (a *Account) State() AccountState

func (*Account) Status

func (a *Account) Status() AccountStatus

func (*Account) UpdatePasswordHash

func (a *Account) UpdatePasswordHash(hash string, now time.Time)

func (*Account) UpdatedAt

func (a *Account) UpdatedAt() time.Time

func (*Account) VerificationToken

func (a *Account) VerificationToken() string

type AccountRepository

type AccountRepository interface {
	Create(ctx context.Context, account *Account) error
	Update(ctx context.Context, account *Account) error
	FindByEmail(ctx context.Context, email string) (*Account, error)
	FindByID(ctx context.Context, id ids.BaseID) (*Account, error)
	FindByVerificationToken(ctx context.Context, token string) (*Account, error)
	FindByResetToken(ctx context.Context, token string) (*Account, error)
}

AccountRepository defines the contract the application layer depends on for persisting and retrieving accounts.

type AccountSnapshot

type AccountSnapshot struct {
	ID                  string
	Email               string
	Status              string
	Verified            bool
	VerificationPending bool
	VerificationToken   string
	ResetToken          string
	CreatedAt           time.Time
	UpdatedAt           time.Time
	VerificationExpires time.Time
	ResetExpires        time.Time
}

AccountSnapshot is a read-only representation of an Account used by the application layer to avoid leaking internal pointers.

type AccountState

type AccountState struct {
	ID                  string
	Email               string
	PasswordHash        string
	Status              AccountStatus
	VerificationToken   string
	VerificationExpires time.Time
	ResetToken          string
	ResetExpires        time.Time
	CreatedAt           time.Time
	UpdatedAt           time.Time
}

AccountState captures every persisted field so the repository can store and restore the aggregate without leaking infrastructure details.

type AccountStatus

type AccountStatus string
const (
	AccountStatusPendingVerification AccountStatus = "pending_verification"
	AccountStatusActive              AccountStatus = "active"
)

type Notifier

type Notifier interface {
	SendVerificationEmail(ctx context.Context, email, token string) error
	SendPasswordResetEmail(ctx context.Context, email, token string) error
}

Notifier allows the application layer to deliver verification and password reset notifications. The implementation can log, send email, or enqueue jobs.

type PasswordHasher

type PasswordHasher interface {
	Hash(ctx context.Context, password string) (string, error)
	Compare(ctx context.Context, hash, password string) error
}

PasswordHasher abstracts hashing and verifying passwords so the domain stays agnostic of concrete algorithms.

type PasswordPolicy

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

PasswordPolicy defines the requirements for valid passwords in the account domain. This service centralizes password validation rules for reuse across handlers.

func NewPasswordPolicy

func NewPasswordPolicy() *PasswordPolicy

NewPasswordPolicy creates a PasswordPolicy with default requirements.

func NewPasswordPolicyWithLength

func NewPasswordPolicyWithLength(minLen int) *PasswordPolicy

NewPasswordPolicyWithLength creates a PasswordPolicy with a custom minimum length.

func (*PasswordPolicy) MinLength

func (p *PasswordPolicy) MinLength() int

MinLength returns the minimum required password length.

func (*PasswordPolicy) Validate

func (p *PasswordPolicy) Validate(password string) error

Validate checks if a password meets the policy requirements. Returns ErrInvalidPassword if validation fails.

type TokenGenerator

type TokenGenerator interface {
	Generate(ctx context.Context, purpose TokenPurpose) (string, error)
}

TokenGenerator produces secure random tokens for verification and password-reset flows.

type TokenPurpose

type TokenPurpose string
const (
	TokenPurposeVerification  TokenPurpose = "verification"
	TokenPurposePasswordReset TokenPurpose = "password_reset"
)

Jump to

Keyboard shortcuts

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