user

package
v0.7.9 Latest Latest
Warning

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

Go to latest
Published: Jan 21, 2026 License: MIT Imports: 22 Imported by: 0

Documentation

Index

Constants

View Source
const APIKeySubject = "APIKey"

Variables

View Source
var (
	ErrUserNotExist                    = errors.New("user not found")
	ErrEmptyUsername                   = errors.New("empty username")
	ErrUsernameHasWhitespace           = errors.New("username has leading or trailing whitespace")
	ErrUsernameMatchesEmail            = errors.New("username is the same as email")
	ErrEmptyEmail                      = errors.New("empty email")
	ErrEmailHasWhitespace              = errors.New("email has leading or trailing whitespace")
	ErrInvalidEmail                    = errors.New("not a valid email address")
	ErrPasswordTooShort                = fmt.Errorf("password length < %d", minPasswordLength)
	ErrPasswordTooLong                 = fmt.Errorf("password > %d", maxPasswordLength)
	ErrPasswordInsufficientUniqueChars = fmt.Errorf("password has < %d unique characters", minUniqueChars)
	ErrBannedPassword                  = errors.New("password matches a common password")
	ErrPasswordUsername                = errors.New("password matches username")
	ErrPasswordEmail                   = errors.New("password matches email")
	ErrDeleteSystemUser                = errors.New("system users cannot be deleted")
	ErrChangeModUser                   = errors.New("mod user cannot be modified")
	ErrChangeRootName                  = errors.New("cannot change root username")
	ErrChangeRootRoles                 = errors.New("cannot change root roles")
	ErrAccessDenied                    = errors.New("access denied")
	ErrCurrentPasswordIncorrect        = errors.New("current password incorrect")
)
View Source
var ErrInvalidActivationKey = errors.New("invalid activation key")
View Source
var ErrInvalidToken = errors.New("invalid apikey")
View Source
var ErrNoInviteTokens = errors.New("no invite tokens available")

Functions

func GetUserIDFromAPIKey

func GetUserIDFromAPIKey(apiKey string) (string, error)

GetUserIDFromAPIKey validates the provided api key and returns the user ID

Types

type APIKeyClaims

type APIKeyClaims struct {
	UserID string `json:"uid"`
	jwt.RegisteredClaims
}

type Finder

type Finder interface {
	Find(id uuid.UUID) (*models.User, error)
}

type FinderUpdater

type FinderUpdater interface {
	Finder
	UpdateFull(updatedUser models.User) (*models.User, error)
}

type User

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

User handles user-related operations

func NewUser

func NewUser(queries *queries.Queries, withTxn queries.WithTxnFunc, emailMgr *email.Manager) *User

NewUser creates a new user service

func (*User) ActivateNewUser

func (s *User) ActivateNewUser(ctx context.Context, input models.ActivateNewUserInput) (*models.User, error)

func (*User) Authenticate

func (s *User) Authenticate(ctx context.Context, username string, password string) (string, error)

Authenticate validates the provided username and password. If correct, it returns the id of the user.

func (*User) ChangePassword

func (s *User) ChangePassword(ctx context.Context, input models.UserChangePasswordInput) error

func (*User) ConfirmChangeEmail

func (s *User) ConfirmChangeEmail(ctx context.Context, tokenID uuid.UUID) (models.UserChangeEmailStatus, error)

func (*User) Count

func (s *User) Count(ctx context.Context) (int, error)

func (*User) CountEditsByStatus

func (s *User) CountEditsByStatus(ctx context.Context, userID uuid.UUID) (*models.UserEditCount, error)

func (*User) CountVotesByType

func (s *User) CountVotesByType(ctx context.Context, userID uuid.UUID) (*models.UserVoteCount, error)

func (*User) Create

func (s *User) Create(ctx context.Context, input models.UserCreateInput) (*models.User, error)

func (*User) CreateSystemUsers

func (s *User) CreateSystemUsers(ctx context.Context)

func (*User) Delete

func (s *User) Delete(ctx context.Context, input models.UserDestroyInput) error

func (*User) FindByID

func (s *User) FindByID(ctx context.Context, id uuid.UUID) (*models.User, error)

func (*User) FindByName

func (s *User) FindByName(ctx context.Context, name string) (*models.User, error)

func (*User) GenerateInviteCode

func (s *User) GenerateInviteCode(ctx context.Context) (*uuid.UUID, error)

func (*User) GenerateInviteCodes

func (s *User) GenerateInviteCodes(ctx context.Context, input *models.GenerateInviteCodeInput) ([]uuid.UUID, error)

func (*User) GetNotificationSubscriptions

func (s *User) GetNotificationSubscriptions(ctx context.Context, userID uuid.UUID) ([]models.NotificationEnum, error)

func (*User) GetRoles

func (s *User) GetRoles(ctx context.Context, userID uuid.UUID) ([]models.RoleEnum, error)

func (*User) GrantInvite

func (s *User) GrantInvite(ctx context.Context, input models.GrantInviteInput) (int, error)

func (*User) NewUser

func (s *User) NewUser(ctx context.Context, emailAddr string, inviteKey *uuid.UUID) (*uuid.UUID, error)

NewUser registers a new user. It returns the activation key only if email verification is not required, otherwise it returns nil.

func (*User) Query

func (*User) RegenerateAPIKey

func (s *User) RegenerateAPIKey(ctx context.Context, userID *uuid.UUID) (string, error)

func (*User) RequestChangeEmail

func (s *User) RequestChangeEmail(ctx context.Context) (models.UserChangeEmailStatus, error)

func (*User) RescindInviteCode

func (s *User) RescindInviteCode(ctx context.Context, inviteKeyID uuid.UUID) error

func (*User) ResetPassword

func (s *User) ResetPassword(ctx context.Context, input models.ResetPasswordInput) error

func (*User) RevokeInvite

func (s *User) RevokeInvite(ctx context.Context, input models.RevokeInviteInput) (int, error)

func (*User) Update

func (s *User) Update(ctx context.Context, input models.UserUpdateInput) (*models.User, error)

func (*User) ValidateChangeEmail

func (s *User) ValidateChangeEmail(ctx context.Context, tokenID uuid.UUID, emailAddr string) (models.UserChangeEmailStatus, error)

func (*User) WithTxn

func (s *User) WithTxn(fn func(*queries.Queries) error) error

WithTxn executes a function within a transaction

Jump to

Keyboard shortcuts

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