Documentation ¶
Index ¶
- Constants
- Variables
- func ActivateNewUser(fac models.Repo, name string, id uuid.UUID, password string) (*models.User, error)
- func ActivateResetPassword(fac models.Repo, id uuid.UUID, newPassword string) error
- func Authenticate(fac models.Repo, username string, password string) (string, error)
- func ChangeEmail(fac models.Repo, token models.ChangeEmailTokenData) error
- func ChangePassword(fac models.Repo, userID string, currentPassword string, newPassword string) error
- func ConfirmNewEmail(fac models.Repo, em *email.Manager, user models.User, email string) error
- func ConfirmOldEmail(fac models.Repo, em *email.Manager, user models.User) error
- func Create(fac models.Repo, input models.UserCreateInput) (*models.User, error)
- func CreateSystemUsers(fac models.Repo)
- func Destroy(fac models.Repo, input models.UserDestroyInput) (bool, error)
- func GenerateAPIKey(userID string) (string, error)
- func GenerateInviteKeys(uf FinderUpdater, ic models.InviteKeyCreator, userID uuid.UUID, ...) ([]*models.InviteKey, error)
- func Get(fac models.Repo, id string) (*models.User, error)
- func GetCurrentUser(ctx context.Context) *models.User
- func GetModUser(fac models.Repo) *models.User
- func GetRoles(fac models.Repo, id string) ([]models.RoleEnum, error)
- func GetUserIDFromAPIKey(apiKey string) (string, error)
- func GrantInviteTokens(uf FinderUpdater, userID uuid.UUID, tokens int) (int, error)
- func IsRole(ctx context.Context, requiredRole models.RoleEnum) bool
- func NewUser(fac models.Repo, em *email.Manager, email string, inviteKey *uuid.UUID) (*uuid.UUID, error)
- func PromoteUserVoteRights(fac models.Repo, userID uuid.UUID, threshold int) error
- func RegenerateAPIKey(fac models.Repo, userID uuid.UUID) (string, error)
- func RepealInviteTokens(uf FinderUpdater, userID uuid.UUID, tokens int) (int, error)
- func RescindInviteKey(uf FinderUpdater, ikd models.InviteKeyDestroyer, key uuid.UUID, ...) error
- func ResetPassword(fac models.Repo, em *email.Manager, email string) error
- func Update(fac models.Repo, input models.UserUpdateInput) (*models.User, error)
- func ValidateAdmin(ctx context.Context) error
- func ValidateCreate(input models.UserCreateInput) error
- func ValidateDestroy(user *models.User) error
- func ValidateEdit(ctx context.Context) error
- func ValidateInvite(ctx context.Context) error
- func ValidateManageInvites(ctx context.Context) error
- func ValidateModify(ctx context.Context) error
- func ValidateOwner(ctx context.Context, userID uuid.UUID) error
- func ValidateRead(ctx context.Context) error
- func ValidateRole(ctx context.Context, requiredRole models.RoleEnum) error
- func ValidateUpdate(input models.UserUpdateInput, current models.User) error
- type APIKeyClaims
- type Finder
- type FinderUpdater
Constants ¶
const ( ContextUser key = iota ContextRoles )
const APIKeyHeader = "ApiKey"
const APIKeySubject = "APIKey"
Variables ¶
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") )
var ErrInvalidActivationKey = errors.New("invalid activation key")
var ErrInvalidToken = errors.New("invalid apikey")
var ErrNoInviteTokens = errors.New("no invite tokens available")
Functions ¶
func ActivateNewUser ¶
func ActivateResetPassword ¶
func Authenticate ¶
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 ConfirmNewEmail ¶ added in v0.6.0
func ConfirmOldEmail ¶ added in v0.6.0
func CreateSystemUsers ¶ added in v0.1.0
CreateSystemUsers creates mandatory system users if they do not exist
func GenerateAPIKey ¶
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 GetUserIDFromAPIKey ¶
GetUserIDFromAPIKey validates the provided api key and returns the user ID
func GrantInviteTokens ¶
GrantInviteTokens increments the invite token count for a user by up to 10.
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 RepealInviteTokens ¶
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 ¶
ResetPassword generates an email to reset a users password.
func ValidateAdmin ¶ added in v0.1.0
func ValidateCreate ¶
func ValidateCreate(input models.UserCreateInput) error
func ValidateDestroy ¶
func ValidateEdit ¶ added in v0.1.0
func ValidateInvite ¶ added in v0.1.0
func ValidateManageInvites ¶ added in v0.1.0
func ValidateModify ¶ added in v0.1.0
func ValidateOwner ¶ added in v0.1.0
func ValidateRead ¶ added in v0.1.0
func ValidateRole ¶ added in v0.1.0
func ValidateUpdate ¶
func ValidateUpdate(input models.UserUpdateInput, current models.User) error
Types ¶
type APIKeyClaims ¶
type APIKeyClaims struct { UserID string `json:"uid"` jwt.RegisteredClaims }