user

package
v0.3.0 Latest Latest
Warning

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

Go to latest
Published: Dec 23, 2025 License: Apache-2.0 Imports: 4 Imported by: 0 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

Index

Constants

This section is empty.

Variables

View Source
var (
	ErrInvalidEmail    = errors.New("invalid email address")
	ErrPasswordTooWeak = errors.New("password is too weak")
	ErrUserNotFound    = errors.New("user not found")
)

Common domain errors

Functions

This section is empty.

Types

type Address

type Address struct {
	ID        uuid.UUID `json:"id" db:"id"`
	UserID    uuid.UUID `json:"user_id" db:"user_id"`
	Label     string    `json:"label" db:"label"` // e.g., "Home", "Work"
	Line1     string    `json:"line1" db:"line1"`
	Line2     string    `json:"line2,omitempty" db:"line2"`
	City      string    `json:"city" db:"city"`
	State     string    `json:"state" db:"state"`
	ZipCode   string    `json:"zip_code" db:"zip_code"`
	Country   string    `json:"country" db:"country"`
	IsDefault bool      `json:"is_default" db:"is_default"`
	CreatedAt time.Time `json:"created_at" db:"created_at"`
	UpdatedAt time.Time `json:"updated_at" db:"updated_at"`
}

Address represents a physical location associated with a user.

type Biometric

type Biometric struct {
	ID              uuid.UUID `json:"id" db:"id"`
	UserID          uuid.UUID `json:"user_id" db:"user_id"`
	CredentialID    []byte    `json:"credential_id" db:"credential_id"` // WebAuthn Credential ID
	PublicKey       []byte    `json:"-" db:"public_key"`                // Public Key for verification
	AttestationType string    `json:"attestation_type" db:"attestation_type"`
	AAGUID          uuid.UUID `json:"aaguid" db:"aaguid"`
	SignCount       uint32    `json:"sign_count" db:"sign_count"`
	DeviceName      string    `json:"device_name" db:"device_name"` // Friendly name for the authenticator
	CreatedAt       time.Time `json:"created_at" db:"created_at"`
	LastUsedAt      time.Time `json:"last_used_at" db:"last_used_at"`
}

Biometric represents FIDO2/WebAuthn credentials or other biometric data references.

type Device

type Device struct {
	ID           uuid.UUID  `json:"id" db:"id"`
	UserID       uuid.UUID  `json:"user_id" db:"user_id"`
	DeviceToken  string     `json:"-" db:"device_token"` // Push notification token, kept private
	Name         string     `json:"name" db:"name"`      // e.g., "iPhone 13"
	Type         string     `json:"type" db:"type"`      // "ios", "android", "web"
	UserAgent    string     `json:"user_agent" db:"user_agent"`
	IPAddress    string     `json:"ip_address" db:"ip_address"`
	LastActiveAt time.Time  `json:"last_active_at" db:"last_active_at"`
	CreatedAt    time.Time  `json:"created_at" db:"created_at"`
	ExpiresAt    *time.Time `json:"expires_at,omitempty" db:"expires_at"`
}

Device represents a trusted device or active session.

type Preferences

type Preferences struct {
	Theme            string `json:"theme"`            // "light", "dark", "system"
	Language         string `json:"language"`         // ISO code
	Timezone         string `json:"timezone"`         // IANA Timezone string
	Notifications    bool   `json:"notifications"`    // Global toggle
	MarketingEmails  bool   `json:"marketing_emails"` // Newsletter opt-in
	TwoFactorEnabled bool   `json:"two_factor_enabled"`
	DataSharingOptIn bool   `json:"data_sharing_opt_in"`
}

Preferences stores user-specific configuration settings. This is often stored as a JSONB column in the database.

type Role

type Role string

Role represents the authorization level of a user.

const (
	RoleUser       Role = "user"
	RoleAdmin      Role = "admin"
	RoleSuperAdmin Role = "super_admin"
	RoleModerator  Role = "moderator"
)

type Status

type Status string

Status represents the current state of the user account.

const (
	StatusPending   Status = "pending"
	StatusActive    Status = "active"
	StatusSuspended Status = "suspended"
	StatusBanned    Status = "banned"
	StatusArchived  Status = "archived"
)

type User

type User struct {
	ID           uuid.UUID   `json:"id" db:"id"`
	Email        string      `json:"email" db:"email"`
	Phone        *string     `json:"phone,omitempty" db:"phone"`
	PasswordHash string      `json:"-" db:"password_hash"` // Never serialize password hash
	FirstName    string      `json:"first_name" db:"first_name"`
	LastName     string      `json:"last_name" db:"last_name"`
	Role         Role        `json:"role" db:"role"`
	Status       Status      `json:"status" db:"status"`
	AvatarURL    *string     `json:"avatar_url,omitempty" db:"avatar_url"`
	Preferences  Preferences `json:"preferences" db:"preferences"`
	Addresses    []Address   `json:"addresses,omitempty" db:"-"` // Loaded via relation
	Devices      []Device    `json:"devices,omitempty" db:"-"`   // Loaded via relation
	Biometrics   []Biometric `json:"biometrics,omitempty" db:"-"`
	LastLoginAt  *time.Time  `json:"last_login_at,omitempty" db:"last_login_at"`
	CreatedAt    time.Time   `json:"created_at" db:"created_at"`
	UpdatedAt    time.Time   `json:"updated_at" db:"updated_at"`
	DeletedAt    *time.Time  `json:"deleted_at,omitempty" db:"deleted_at"`
}

User is the aggregate root for the user domain.

func NewUser

func NewUser(email, firstName, lastName string) (*User, error)

NewUser creates a new user instance with default values.

func (*User) Activate

func (u *User) Activate()

Activate sets the user status to active.

func (*User) FullName

func (u *User) FullName() string

FullName returns the concatenated first and last name.

func (*User) HasRole

func (u *User) HasRole(role Role) bool

HasRole checks if the user possesses a specific role.

func (*User) IsActive

func (u *User) IsActive() bool

IsActive checks if the user status allows for login.

func (*User) IsAdmin

func (u *User) IsAdmin() bool

IsAdmin checks if the user has administrative privileges.

func (*User) UpdateLastLogin

func (u *User) UpdateLastLogin()

UpdateLastLogin updates the user's last login timestamp.

Jump to

Keyboard shortcuts

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