users

package
v0.2.0-rc.14-linux-arm64 Latest Latest
Warning

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

Go to latest
Published: Nov 19, 2026 License: Apache-2.0 Imports: 12 Imported by: 1 module, 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 (
	ErrUserNotFound         = xerror.NotFound(xerror.User)
	ErrEmailAlreadyExists   = xerror.AlreadyExists(xerror.UserEmail)
	ErrSlugAlreadyExists    = xerror.AlreadyExists(xerror.User)
	ErrMFAChallengeConsumed = xerror.InvalidToken().Detail(
		"mfa challenge already consumed",
	)
)

Functions

This section is empty.

Types

type CreateEmailVerificationTokenParams

type CreateEmailVerificationTokenParams struct {
	Slug                            slug.Slug
	EmailVerificationTokenHash      string
	EmailVerificationTokenExpiresAt time.Time
}

type CreateOIDCUserParams

type CreateOIDCUserParams struct {
	Slug           slug.Slug
	Email          string
	FullName       string
	OIDCProvider   string
	OIDCProviderID string
	AvatarURL      string
	Role           model.Role
	Locale         string
}

type CreateParams

type CreateParams struct {
	Slug     slug.Slug
	Email    string
	FullName string
	Password string
	Role     model.Role
	Locale   string
}

type CreatePasswordResetTokenParams

type CreatePasswordResetTokenParams struct {
	Slug                        slug.Slug
	PasswordResetTokenHash      string
	PasswordResetTokenExpiresAt time.Time
}

type MFAChallenge

type MFAChallenge struct {
	ID           int
	User         *UserPublic
	CodeHash     string
	ExpiresAt    time.Time
	ConsumedAt   time.Time
	AttemptCount int
}

type Repository

type Repository interface {
	CreateUser(ctx context.Context, tx postgres.DBTX, user *CreateParams) (*UserPublic, error)
	CreateOIDCUser(
		ctx context.Context,
		tx postgres.DBTX,
		params *CreateOIDCUserParams,
	) (*UserPublic, error)
	FindBySlug(ctx context.Context, tx postgres.DBTX, slug slug.Slug) (*UserPublic, error)
	IsSlugReserved(ctx context.Context, tx postgres.DBTX, slug slug.Slug) (bool, error)
	FindByEmailWithPassword(
		ctx context.Context,
		tx postgres.DBTX,
		email string,
	) (*UserWithPassword, error)
	FindBySlugWithPassword(
		ctx context.Context,
		tx postgres.DBTX,
		slug slug.Slug,
	) (*UserWithPassword, error)
	FindByOIDCProvider(
		ctx context.Context,
		tx postgres.DBTX,
		provider, providerID string,
	) (*UserPublic, error)
	FindByEmail(ctx context.Context, tx postgres.DBTX, email string) (*UserPublic, error)
	CreateEmailVerificationToken(
		ctx context.Context,
		tx postgres.DBTX,
		params CreateEmailVerificationTokenParams,
	) error
	CreatePasswordResetToken(
		ctx context.Context,
		tx postgres.DBTX,
		params CreatePasswordResetTokenParams,
	) error
	CreateMFAChallenge(
		ctx context.Context,
		tx postgres.DBTX,
		userSlug slug.Slug,
		challengeTokenHash string,
		codeHash string,
		expiresAt time.Time,
	) error
	FindMFAChallengeByToken(
		ctx context.Context,
		tx postgres.DBTX,
		challengeTokenHash string,
	) (*MFAChallenge, error)
	IncrementMFAChallengeAttempts(ctx context.Context, tx postgres.DBTX, id int) error
	ConsumeMFAChallenge(ctx context.Context, tx postgres.DBTX, id int) error
	FindByEmailVerificationToken(
		ctx context.Context,
		tx postgres.DBTX,
		tokenHash string,
	) (*UserPublic, error)
	FindByPasswordResetToken(
		ctx context.Context,
		tx postgres.DBTX,
		tokenHash string,
	) (*UserPublic, error)
	MarkEmailAsVerified(
		ctx context.Context,
		tx postgres.DBTX,
		slug slug.Slug,
		verifiedAt time.Time,
	) error
	UpdatePassword(
		ctx context.Context,
		tx postgres.DBTX,
		slug slug.Slug,
		hashedPassword string,
	) error
	UpdateProfile(ctx context.Context, tx postgres.DBTX, params *UpdateProfileParams) error
}

func NewRepository

func NewRepository() Repository

func NewRepositoryWithLogging

func NewRepositoryWithLogging(base Repository, logger *slog.Logger) Repository

NewRepositoryWithLogging wraps base with method completion logging.

type RepositoryWithLogging

type RepositoryWithLogging struct {
	// contains filtered or unexported fields
}

RepositoryWithLogging implements Repository with method completion logging.

func (RepositoryWithLogging) ConsumeMFAChallenge

func (_d RepositoryWithLogging) ConsumeMFAChallenge(ctx context.Context, tx postgres.DBTX, id int) (err error)

ConsumeMFAChallenge implements Repository.

func (RepositoryWithLogging) CreateEmailVerificationToken

func (_d RepositoryWithLogging) CreateEmailVerificationToken(ctx context.Context, tx postgres.DBTX, params CreateEmailVerificationTokenParams) (err error)

CreateEmailVerificationToken implements Repository.

func (RepositoryWithLogging) CreateMFAChallenge

func (_d RepositoryWithLogging) CreateMFAChallenge(ctx context.Context, tx postgres.DBTX, userSlug slug.Slug, challengeTokenHash string, codeHash string, expiresAt time.Time) (err error)

CreateMFAChallenge implements Repository.

func (RepositoryWithLogging) CreateOIDCUser

func (_d RepositoryWithLogging) CreateOIDCUser(ctx context.Context, tx postgres.DBTX, params *CreateOIDCUserParams) (up1 *UserPublic, err error)

CreateOIDCUser implements Repository.

func (RepositoryWithLogging) CreatePasswordResetToken

func (_d RepositoryWithLogging) CreatePasswordResetToken(ctx context.Context, tx postgres.DBTX, params CreatePasswordResetTokenParams) (err error)

CreatePasswordResetToken implements Repository.

func (RepositoryWithLogging) CreateUser

func (_d RepositoryWithLogging) CreateUser(ctx context.Context, tx postgres.DBTX, user *CreateParams) (up1 *UserPublic, err error)

CreateUser implements Repository.

func (RepositoryWithLogging) FindByEmail

func (_d RepositoryWithLogging) FindByEmail(ctx context.Context, tx postgres.DBTX, email string) (up1 *UserPublic, err error)

FindByEmail implements Repository.

func (RepositoryWithLogging) FindByEmailVerificationToken

func (_d RepositoryWithLogging) FindByEmailVerificationToken(ctx context.Context, tx postgres.DBTX, tokenHash string) (up1 *UserPublic, err error)

FindByEmailVerificationToken implements Repository.

func (RepositoryWithLogging) FindByEmailWithPassword

func (_d RepositoryWithLogging) FindByEmailWithPassword(ctx context.Context, tx postgres.DBTX, email string) (up1 *UserWithPassword, err error)

FindByEmailWithPassword implements Repository.

func (RepositoryWithLogging) FindByOIDCProvider

func (_d RepositoryWithLogging) FindByOIDCProvider(ctx context.Context, tx postgres.DBTX, provider string, providerID string) (up1 *UserPublic, err error)

FindByOIDCProvider implements Repository.

func (RepositoryWithLogging) FindByPasswordResetToken

func (_d RepositoryWithLogging) FindByPasswordResetToken(ctx context.Context, tx postgres.DBTX, tokenHash string) (up1 *UserPublic, err error)

FindByPasswordResetToken implements Repository.

func (RepositoryWithLogging) FindBySlug

func (_d RepositoryWithLogging) FindBySlug(ctx context.Context, tx postgres.DBTX, slug slug.Slug) (up1 *UserPublic, err error)

FindBySlug implements Repository.

func (RepositoryWithLogging) FindBySlugWithPassword

func (_d RepositoryWithLogging) FindBySlugWithPassword(ctx context.Context, tx postgres.DBTX, slug slug.Slug) (up1 *UserWithPassword, err error)

FindBySlugWithPassword implements Repository.

func (RepositoryWithLogging) FindMFAChallengeByToken

func (_d RepositoryWithLogging) FindMFAChallengeByToken(ctx context.Context, tx postgres.DBTX, challengeTokenHash string) (mp1 *MFAChallenge, err error)

FindMFAChallengeByToken implements Repository.

func (RepositoryWithLogging) IncrementMFAChallengeAttempts

func (_d RepositoryWithLogging) IncrementMFAChallengeAttempts(ctx context.Context, tx postgres.DBTX, id int) (err error)

IncrementMFAChallengeAttempts implements Repository.

func (RepositoryWithLogging) IsSlugReserved

func (_d RepositoryWithLogging) IsSlugReserved(ctx context.Context, tx postgres.DBTX, slug slug.Slug) (b1 bool, err error)

IsSlugReserved implements Repository.

func (RepositoryWithLogging) MarkEmailAsVerified

func (_d RepositoryWithLogging) MarkEmailAsVerified(ctx context.Context, tx postgres.DBTX, slug slug.Slug, verifiedAt time.Time) (err error)

MarkEmailAsVerified implements Repository.

func (RepositoryWithLogging) UpdatePassword

func (_d RepositoryWithLogging) UpdatePassword(ctx context.Context, tx postgres.DBTX, slug slug.Slug, hashedPassword string) (err error)

UpdatePassword implements Repository.

func (RepositoryWithLogging) UpdateProfile

func (_d RepositoryWithLogging) UpdateProfile(ctx context.Context, tx postgres.DBTX, params *UpdateProfileParams) (err error)

UpdateProfile implements Repository.

type UpdateProfileParams

type UpdateProfileParams struct {
	Slug            slug.Slug
	FullName        *string
	Locale          *string
	AvatarURL       *string
	PhoneNumber     *string
	JobTitle        *string
	Timezone        *string
	MFAEmailEnabled *bool
}

type UserPublic

type UserPublic struct {
	AuthenticationVersion int64
	Slug                  slug.Slug
	Email                 string
	FullName              string
	Role                  model.Role
	Locale                string
	AvatarURL             string
	PhoneNumber           string
	JobTitle              string
	Timezone              string
	MFAEmailEnabled       bool
	HasLocalPassword      bool
	VerifiedAt            time.Time
	CreatedAt             time.Time
	UpdatedAt             time.Time
}

type UserWithPassword

type UserWithPassword struct {
	Slug            slug.Slug
	Email           string
	FullName        string
	Password        string
	MFAEmailEnabled bool
}

UserWithPassword is a user with a password. Separate type has been created to make it harder to leak password hashes by accident.

Jump to

Keyboard shortcuts

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