userssvc

package
v0.2.0-rc.10 Latest Latest
Warning

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

Go to latest
Published: Nov 18, 2026 License: Apache-2.0 Imports: 25 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         = users.ErrUserNotFound
	ErrEmailAlreadyExists   = users.ErrEmailAlreadyExists
	ErrSlugAlreadyExists    = users.ErrSlugAlreadyExists
	ErrMFAChallengeConsumed = users.ErrMFAChallengeConsumed
)

Re-exported from repository layer — single source of truth.

View Source
var (
	ErrInvalidUserSlug           = xerror.InvalidInput(xerror.User)
	ErrInvalidInput              = xerror.ValidationFailed()
	ErrInvalidUsernameOrPassword = xerror.InvalidCredentials()
	ErrEmailNotVerified          = xerror.EmailNotVerified()
	ErrAlreadyVerified           = xerror.AlreadyVerified()
	ErrInvalidToken              = xerror.InvalidToken()
	ErrLocalPasswordUnavailable  = xerror.ValidationFailed().WithPublicDetail(localPasswordUnavailableDetail).Detail(localPasswordUnavailableDetail)
	ErrMFARequired               = xerror.ValidationFailed().Detail("mfa verification required")
	ErrMFAChallengeExpired       = xerror.InvalidToken().Detail("mfa challenge expired")
	ErrMFAChallengeLocked        = xerror.InvalidToken().Detail("mfa challenge attempt limit exceeded")
)

Service-only errors.

Functions

This section is empty.

Types

type MFAEmailRateLimitError

type MFAEmailRateLimitError struct {
	ResetAt time.Time
}

MFAEmailRateLimitError carries the delivery window to the sign-in handler.

func (*MFAEmailRateLimitError) Error

func (*MFAEmailRateLimitError) Error() string

type Option

type Option func(*usersService)

Option configures optional behavior inside the account transaction.

func WithCreated

func WithCreated(created func(context.Context, postgres.DBTX, *model.User) error) Option

func WithMFAEmailBudget

func WithMFAEmailBudget(repo abusecontrols.Repository, limit int, window time.Duration) Option

WithMFAEmailBudget limits challenge delivery after password verification.

type UsersService

type UsersService interface {
	CreateUser(ctx context.Context, newUser model.NewUser) (*model.User, error)
	BeginLogin(ctx context.Context, email, password string) (*model.SessionLoginResult, error)
	LoginUser(ctx context.Context, email, password string) (*model.User, error)
	GetUserBySlug(ctx context.Context, userSlug slug.Slug) (*model.User, error)
	LoginOIDCUser(ctx context.Context, oidcUser *model.OIDCUserInfo) (*model.User, error)
	LoginOrCreateOIDCUser(ctx context.Context, oidcUser *model.OIDCUserInfo) (*model.User, error)
	VerifyEmail(ctx context.Context, token string) error
	RequestPasswordReset(ctx context.Context, email string) error
	ResetPassword(ctx context.Context, token, password string) error
	ChangePassword(ctx context.Context, userSlug slug.Slug, currentPassword, newPassword string) error
	ResendVerificationEmail(ctx context.Context, email string) error
	UpdateProfile(
		ctx context.Context,
		userSlug slug.Slug,
		update model.UpdateUserProfile,
	) (*model.User, error)
	VerifySessionMFA(ctx context.Context, challengeToken, code string) (*model.User, error)
}

func New

func New(
	txm postgres.TransactionManager,
	hasher crypto.Hasher,
	usersRepository users.Repository,
	emailProducer workerproducer.EmailProducer,
	eventProducer workerproducer.EventProducer,
	frontendURL string,
	options ...Option,
) UsersService

New creates a new users service with the given querier and users repository.

func NewUsersServiceWithLogging

func NewUsersServiceWithLogging(base UsersService, logger *slog.Logger) UsersService

NewUsersServiceWithLogging wraps base with method completion logging.

type UsersServiceWithLogging

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

UsersServiceWithLogging implements UsersService with method completion logging.

func (UsersServiceWithLogging) BeginLogin

func (_d UsersServiceWithLogging) BeginLogin(ctx context.Context, email string, password string) (sp1 *model.SessionLoginResult, err error)

BeginLogin implements UsersService.

func (UsersServiceWithLogging) ChangePassword

func (_d UsersServiceWithLogging) ChangePassword(ctx context.Context, userSlug slug.Slug, currentPassword string, newPassword string) (err error)

ChangePassword implements UsersService.

func (UsersServiceWithLogging) CreateUser

func (_d UsersServiceWithLogging) CreateUser(ctx context.Context, newUser model.NewUser) (up1 *model.User, err error)

CreateUser implements UsersService.

func (UsersServiceWithLogging) GetUserBySlug

func (_d UsersServiceWithLogging) GetUserBySlug(ctx context.Context, userSlug slug.Slug) (up1 *model.User, err error)

GetUserBySlug implements UsersService.

func (UsersServiceWithLogging) LoginOIDCUser

func (_d UsersServiceWithLogging) LoginOIDCUser(ctx context.Context, oidcUser *model.OIDCUserInfo) (up1 *model.User, err error)

LoginOIDCUser implements UsersService.

func (UsersServiceWithLogging) LoginOrCreateOIDCUser

func (_d UsersServiceWithLogging) LoginOrCreateOIDCUser(ctx context.Context, oidcUser *model.OIDCUserInfo) (up1 *model.User, err error)

LoginOrCreateOIDCUser implements UsersService.

func (UsersServiceWithLogging) LoginUser

func (_d UsersServiceWithLogging) LoginUser(ctx context.Context, email string, password string) (up1 *model.User, err error)

LoginUser implements UsersService.

func (UsersServiceWithLogging) RequestPasswordReset

func (_d UsersServiceWithLogging) RequestPasswordReset(ctx context.Context, email string) (err error)

RequestPasswordReset implements UsersService.

func (UsersServiceWithLogging) ResendVerificationEmail

func (_d UsersServiceWithLogging) ResendVerificationEmail(ctx context.Context, email string) (err error)

ResendVerificationEmail implements UsersService.

func (UsersServiceWithLogging) ResetPassword

func (_d UsersServiceWithLogging) ResetPassword(ctx context.Context, token string, password string) (err error)

ResetPassword implements UsersService.

func (UsersServiceWithLogging) UpdateProfile

func (_d UsersServiceWithLogging) UpdateProfile(ctx context.Context, userSlug slug.Slug, update model.UpdateUserProfile) (up1 *model.User, err error)

UpdateProfile implements UsersService.

func (UsersServiceWithLogging) VerifyEmail

func (_d UsersServiceWithLogging) VerifyEmail(ctx context.Context, token string) (err error)

VerifyEmail implements UsersService.

func (UsersServiceWithLogging) VerifySessionMFA

func (_d UsersServiceWithLogging) VerifySessionMFA(ctx context.Context, challengeToken string, code string) (up1 *model.User, err error)

VerifySessionMFA implements UsersService.

Jump to

Keyboard shortcuts

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