models

package
v0.18.9 Latest Latest
Warning

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

Go to latest
Published: Feb 2, 2025 License: BSD-3-Clause Imports: 13 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",
	)
)

Functions

func DeleteToken added in v0.18.9

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

func UpdateUserPassword

func UpdateUserPassword(
	ctx context.Context,
	data UpdateUserPasswordPayload,
	q func(
		ctx context.Context,
		userID uuid.UUID,
		newPassword string,
		updatedAt time.Time,
	) error,
) 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"`
	ResourceID uuid.UUID `validate:"required,uuid"`
	Scope      Scope     `validate:"required"`
}

type NewTokenPayload

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

type NewUserPayload

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

type Resource

type Resource string
var (
	ResourceUser       Resource = "users"
	ResourceSubscriber Resource = "subscribers"
)

type Scope

type Scope string
var (
	ScopeEmailVerification Scope = "email_verification"
	ScopeUnsubscribe       Scope = "unsubscribe"
	ScopeResetPassword     Scope = "password_reset"
)

type Token

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

func GetToken

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

func NewToken

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

func (Token) IsValid added in v0.18.9

func (te Token) IsValid() bool

type UpdateUserPasswordPayload

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

type UpdateUserPayload

type UpdateUserPayload struct {
	ID             uuid.UUID `validate:"required,uuid"`
	UpdatedAt      time.Time `validate:"required"`
	Name           string    `validate:"required,gte=2,lte=25"`
	Email          string    `validate:"required,email"`
	EmailUpdatedAt time.Time
}

type UserEntity

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

func GetUser

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

func GetUserByEmail

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

func MakeUserAdmin added in v0.17.1

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

func NewUser

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

func UpdateUser

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

func (UserEntity) IsVerified

func (ue UserEntity) IsVerified() bool

Directories

Path Synopsis
internal
db

Jump to

Keyboard shortcuts

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