user

package
v0.6.8 Latest Latest
Warning

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

Go to latest
Published: Jan 12, 2025 License: MIT Imports: 17 Imported by: 0

Documentation

Index

Constants

View Source
const (
	ContextUser key = iota
	ContextRoles
)
View Source
const APIKeyHeader = "ApiKey"
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")
View Source
var ErrUnauthorized = errors.New("Not authorized")

Functions

func ActivateNewUser

func ActivateNewUser(fac models.Repo, name string, id uuid.UUID, password string) (*models.User, error)

func ActivateResetPassword

func ActivateResetPassword(fac models.Repo, id uuid.UUID, newPassword string) error

func Authenticate

func Authenticate(fac models.Repo, username string, password string) (string, error)

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

func ChangeEmail added in v0.6.0

func ChangeEmail(fac models.Repo, token models.ChangeEmailTokenData) error

func ChangePassword

func ChangePassword(fac models.Repo, userID string, currentPassword string, newPassword string) error

func ConfirmNewEmail added in v0.6.0

func ConfirmNewEmail(fac models.Repo, em *email.Manager, user models.User, email string) error

func ConfirmOldEmail added in v0.6.0

func ConfirmOldEmail(fac models.Repo, em *email.Manager, user models.User) error

func Create

func Create(fac models.Repo, input models.UserCreateInput) (*models.User, error)

func CreateSystemUsers added in v0.1.0

func CreateSystemUsers(fac models.Repo)

CreateSystemUsers creates mandatory system users if they do not exist

func Destroy

func Destroy(fac models.Repo, input models.UserDestroyInput) (bool, error)

func GenerateAPIKey

func GenerateAPIKey(userID string) (string, error)

func GenerateInviteKeys added in v0.5.1

func GenerateInviteKeys(uf FinderUpdater, ic models.InviteKeyCreator, userID uuid.UUID, input *models.GenerateInviteCodeInput, useToken bool) ([]*models.InviteKey, error)

GenerateInviteKeys creates and returns an invite key, using a token if required. If useToken is true and the user has no invite tokens, then an error is returned.

func Get

func Get(fac models.Repo, id string) (*models.User, error)

func GetCurrentUser added in v0.1.0

func GetCurrentUser(ctx context.Context) *models.User

func GetModUser added in v0.1.0

func GetModUser(fac models.Repo) *models.User

func GetRoles

func GetRoles(fac models.Repo, id string) ([]models.RoleEnum, error)

func GetUserIDFromAPIKey

func GetUserIDFromAPIKey(apiKey string) (string, error)

GetUserIDFromAPIKey validates the provided api key and returns the user ID

func GrantInviteTokens

func GrantInviteTokens(uf FinderUpdater, userID uuid.UUID, tokens int) (int, error)

GrantInviteTokens increments the invite token count for a user by up to 10.

func IsRole added in v0.1.0

func IsRole(ctx context.Context, requiredRole models.RoleEnum) bool

func NewUser

func NewUser(fac models.Repo, em *email.Manager, email 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 PromoteUserVoteRights added in v0.1.0

func PromoteUserVoteRights(fac models.Repo, userID uuid.UUID, threshold int) error

func RegenerateAPIKey

func RegenerateAPIKey(fac models.Repo, userID uuid.UUID) (string, error)

func RepealInviteTokens

func RepealInviteTokens(uf FinderUpdater, userID uuid.UUID, tokens int) (int, error)

RepealInviteTokens decrements a user's invite token count by the provided amount. Invite tokens are constrained to a minimum of 0.

func RescindInviteKey

func RescindInviteKey(uf FinderUpdater, ikd models.InviteKeyDestroyer, key uuid.UUID, userID uuid.UUID, refundToken bool) error

RescindInviteKey makes an invite key invalid, refunding the invite token if required. Returns an error if the invite key is already in use.

func ResetPassword

func ResetPassword(fac models.Repo, em *email.Manager, email string) error

ResetPassword generates an email to reset a users password.

func Update

func Update(fac models.Repo, input models.UserUpdateInput) (*models.User, error)

func ValidateAdmin added in v0.1.0

func ValidateAdmin(ctx context.Context) error

func ValidateCreate

func ValidateCreate(input models.UserCreateInput) error

func ValidateDestroy

func ValidateDestroy(user *models.User) error

func ValidateEdit added in v0.1.0

func ValidateEdit(ctx context.Context) error

func ValidateInvite added in v0.1.0

func ValidateInvite(ctx context.Context) error

func ValidateManageInvites added in v0.1.0

func ValidateManageInvites(ctx context.Context) error

func ValidateModify added in v0.1.0

func ValidateModify(ctx context.Context) error

func ValidateOwner added in v0.1.0

func ValidateOwner(ctx context.Context, userID uuid.UUID) error

func ValidateRead added in v0.1.0

func ValidateRead(ctx context.Context) error

func ValidateRole added in v0.1.0

func ValidateRole(ctx context.Context, requiredRole models.RoleEnum) error

func ValidateUpdate

func ValidateUpdate(input models.UserUpdateInput, current models.User) error

Types

type APIKeyClaims

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

type Finder added in v0.1.0

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

type FinderUpdater added in v0.1.0

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

Jump to

Keyboard shortcuts

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