models

package
v0.24.3 Latest Latest
Warning

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

Go to latest
Published: May 26, 2025 License: BSD-3-Clause Imports: 17 Imported by: 0

Documentation

Index

Constants

This section is empty.

Variables

View Source
var (
	ErrDomainValidation = errors.New("the provided payload failed validations")
	ErrMustBeAdmin      = errors.New(
		"this action requires the actor to be an admin",
	)
)
View Source
var (
	ScopeEmailVerification Scope = "email_verification"
	ScopeUnsubscribe       Scope = "unsubscribe"

	ScopeResetPassword Scope = "password_reset"

	ResourceUser       Resource = "users"
	ResourceSubscriber Resource = "subscribers"
)

Functions

func DeleteToken added in v0.18.9

func DeleteToken(
	ctx context.Context,
	dbtx db.DBTX,
	tokenID uuid.UUID,
) error

func HashPassword added in v0.24.3

func HashPassword(password string) []byte

func UpdateUserEmailToVerified added in v0.19.2

func UpdateUserEmailToVerified(
	ctx context.Context,
	dbtx db.DBTX,
	data UpdateUserEmailToVerifiedPayload,
) error

func UpdateUserPassword

func UpdateUserPassword(
	ctx context.Context,
	dbtx db.DBTX,
	data UpdateUserPasswordPayload,
) error

Types

type MakeUserAdminPayload added in v0.17.1

type MakeUserAdminPayload struct {
	UserID    uuid.UUID `validate:"required,uuid"`
	UpdatedAt time.Time `validate:"required"`
	ActorID   uuid.UUID `validate:"required,uuid"`
}

type MetaInformation

type MetaInformation struct {
	Resource   Resource  `validate:"required"      json:"resource"`
	ResourceID uuid.UUID `validate:"required,uuid" json:"resource_id"`
	Scope      Scope     `validate:"required"      json:"scope"`
}

type NewTokenPayload

type NewTokenPayload struct {
	Expiration time.Time       `validate:"required"`
	Meta       MetaInformation `validate:"required" json:"meta"`
}

type NewUserPayload

type NewUserPayload struct {
	Email    string `validate:"required,email"`
	Password PasswordPair
}

type PasswordPair added in v0.19.2

type PasswordPair struct {
	Password        string `validate:"required,gte=6"`
	ConfirmPassword string `validate:"required,gte=6"`
}

type Resource

type Resource string

type Scope

type Scope string

type Token

type Token struct {
	ID         uuid.UUID
	CreatedAt  time.Time
	Expiration time.Time
	Value      string
	Meta       MetaInformation
}

func GetHashedToken added in v0.24.3

func GetHashedToken(
	ctx context.Context,
	dbtx db.DBTX,
	token string,
) (Token, error)

func GetToken

func GetToken(
	ctx context.Context,
	dbtx db.DBTX,
	token string,
) (Token, error)

func NewCodeToken added in v0.24.3

func NewCodeToken(
	ctx context.Context,
	dbtx db.DBTX,
	data NewTokenPayload,
) (Token, error)

func NewHashedToken added in v0.24.3

func NewHashedToken(
	ctx context.Context,
	dbtx db.DBTX,
	data NewTokenPayload,
) (Token, error)

func NewToken

func NewToken(
	ctx context.Context,
	dbtx db.DBTX,
	data NewTokenPayload,
) (Token, error)

func (Token) IsValid added in v0.18.9

func (te Token) IsValid() bool

type UpdateUserEmailToVerifiedPayload added in v0.19.2

type UpdateUserEmailToVerifiedPayload struct {
	ID         uuid.UUID `validate:"required,uuid"`
	Email      string    `validate:"required,email"`
	VerifiedAt time.Time `validate:"required"`
}

type UpdateUserPasswordPayload

type UpdateUserPasswordPayload struct {
	ID        uuid.UUID `validate:"required,uuid"`
	UpdatedAt time.Time `validate:"required"`
	Password  PasswordPair
}

type UpdateUserPayload

type UpdateUserPayload struct {
	ID        uuid.UUID `validate:"required,uuid"`
	UpdatedAt time.Time `validate:"required"`
	Email     string    `validate:"required,email"`
}

type UserEntity

type UserEntity struct {
	ID              uuid.UUID
	CreatedAt       time.Time
	UpdatedAt       time.Time
	Email           string
	EmailVerifiedAt time.Time
	IsAdmin         bool
	HashedPassword  string
}

func GetUser

func GetUser(
	ctx context.Context,
	dbtx db.DBTX,
	id uuid.UUID,
) (UserEntity, error)

func GetUserByEmail

func GetUserByEmail(
	ctx context.Context,
	dbtx db.DBTX,
	email string,
) (UserEntity, error)

func MakeUserAdmin added in v0.17.1

func MakeUserAdmin(
	ctx context.Context,
	dbtx db.DBTX,
	data MakeUserAdminPayload,
) (UserEntity, error)

func NewUser

func NewUser(
	ctx context.Context,
	dbtx db.DBTX,
	data NewUserPayload,
) (UserEntity, error)

func UpdateUser

func UpdateUser(
	ctx context.Context,
	dbtx db.DBTX,
	data UpdateUserPayload,
) (UserEntity, error)

func (UserEntity) IsVerified

func (ue UserEntity) IsVerified() bool

func (UserEntity) ValidatePassword added in v0.19.2

func (ue UserEntity) ValidatePassword(providedPassword string) error

Directories

Path Synopsis
internal
db

Jump to

Keyboard shortcuts

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