Documentation
¶
Index ¶
- Variables
- func NormalizeEmail(email string) (string, error)
- type Account
- func (a *Account) ApplyPasswordResetToken(token string, expires, now time.Time)
- func (a *Account) ApplyVerificationToken(token string, expires, now time.Time)
- func (a *Account) ClearResetToken(now time.Time)
- func (a *Account) ClearVerificationToken(now time.Time)
- func (a *Account) CreatedAt() time.Time
- func (a *Account) Email() string
- func (a *Account) HasValidResetToken(token string, now time.Time) bool
- func (a *Account) HasValidVerificationToken(token string, now time.Time) bool
- func (a *Account) ID() ids.BaseID
- func (a *Account) MarkVerified(now time.Time)
- func (a *Account) PasswordHash() string
- func (a *Account) ResetToken() string
- func (a *Account) Snapshot() AccountSnapshot
- func (a *Account) State() AccountState
- func (a *Account) Status() AccountStatus
- func (a *Account) UpdatePasswordHash(hash string, now time.Time)
- func (a *Account) UpdatedAt() time.Time
- func (a *Account) VerificationToken() string
- type AccountRepository
- type AccountSnapshot
- type AccountState
- type AccountStatus
- type Notifier
- type PasswordHasher
- type PasswordPolicy
- type TokenGenerator
- type TokenPurpose
Constants ¶
This section is empty.
Variables ¶
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 ¶
Types ¶
type Account ¶
type Account struct {
// contains filtered or unexported fields
}
func NewAccount ¶
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 (*Account) ApplyVerificationToken ¶
func (*Account) ClearResetToken ¶
func (*Account) ClearVerificationToken ¶
func (*Account) HasValidResetToken ¶
func (*Account) HasValidVerificationToken ¶
func (*Account) MarkVerified ¶
func (*Account) PasswordHash ¶
func (*Account) ResetToken ¶
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 (*Account) VerificationToken ¶
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" )