user

package
v0.0.0-...-421433b Latest Latest
Warning

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

Go to latest
Published: Oct 1, 2025 License: MIT Imports: 9 Imported by: 0

Documentation

Index

Constants

View Source
const (
	CodeValidationFailed apperr.Code = "user/validation_failed"
	CodeNotFound         apperr.Code = "user/not_found"
	CodeEmailDuplicate   apperr.Code = "user/email_duplicate"
	CodeSamePassword     apperr.Code = "user/same_password"
	CodePasswordMismatch apperr.Code = "user/password_mismatch"
)
View Source
const (
	FieldEmail    apperr.Field = "email"
	FieldName     apperr.Field = "name"
	FieldPassword apperr.Field = "password"
	FieldUserID   apperr.Field = "user_id"
	FieldUser     apperr.Field = "user"
)

Variables

This section is empty.

Functions

func ErrEmailTooLong

func ErrEmailTooLong(max int) error

func ErrInvalidEmail

func ErrInvalidEmail() error

func ErrNameEmpty

func ErrNameEmpty() error

func ErrNameTooLong

func ErrNameTooLong(max int) error

func ErrPasswordTooLong

func ErrPasswordTooLong(max int) error

func ErrPasswordTooShort

func ErrPasswordTooShort(min int) error

func ErrUserNotFound

func ErrUserNotFound() error

func ErrUserWithEmailAlreadyExists

func ErrUserWithEmailAlreadyExists() error

func NewCore

func NewCore(repo Repository, idGenerator IDGenerator, passwordHasher PasswordHasher, validator Validator, cfg Config) (*core, error)

Types

type Config

type Config struct {
	PasswordHashCost int `mapstructure:"password_hash_cost" json:"password_hash_cost"`
}

type CreateUserReq

type CreateUserReq struct {
	Email    string
	Name     string
	Password []byte `json:"-"`
}

type IDGenerator

type IDGenerator interface {
	New() (uuid.UUID, error)
}

type PasswordHasher

type PasswordHasher interface {
	HashPassword(password []byte, cost int) ([]byte, error)
}

type Repository

type Repository interface {
	CreateUser(ctx context.Context, req CreateUserReq, id uuid.UUID, passwordHash string) error
	GetUser(ctx context.Context, id uuid.UUID) (User, string, error)
	GetUserByEmail(ctx context.Context, email string) (User, string, error)
	GetAllUsers(ctx context.Context) ([]User, error)
	UpdateUser(ctx context.Context, req UpdateUserReq) error
	DeleteUser(ctx context.Context, id uuid.UUID) error
	ChangePassword(ctx context.Context, id uuid.UUID, newPasswordHash string) error
}

type UpdateUserReq

type UpdateUserReq struct {
	UserID uuid.UUID `json:"user_id"`
	Email  string    `json:"email"`
	Name   string    `json:"name"`
}

type User

type User struct {
	ID             uuid.UUID  `json:"id"`
	Email          string     `json:"email"`
	Name           string     `json:"name"`
	SessionVersion int        `json:"session_version"`
	CreatedAt      time.Time  `json:"created_at"`
	UpdatedAt      time.Time  `json:"updated_at"`
	DeletedAt      *time.Time `json:"deleted_at"`
}

type ValidationConfig

type ValidationConfig struct {
	MaxEmailLength    int `mapstructure:"max_email_length" json:"max_email_length"`
	MaxNameLength     int `mapstructure:"max_name_length" json:"max_name_length"`
	MinPasswordLength int `mapstructure:"min_password_length" json:"min_password_length"`
	MaxPasswordLength int `mapstructure:"max_password_length" json:"max_password_length"`
}

type Validator

type Validator interface {
	ValidatePassword(password []byte) error
	ValidateEmail(address string, validateLength bool) error
	ValidateName(name string) error
	NormalizeName(name string) string
	NormalizeEmail(address string) string
}

func NewValidator

func NewValidator(cfg ValidationConfig) (Validator, error)

Directories

Path Synopsis
repo
transport

Jump to

Keyboard shortcuts

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