users

package
v0.0.0-...-9265677 Latest Latest
Warning

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

Go to latest
Published: Feb 25, 2024 License: AGPL-3.0 Imports: 12 Imported by: 0

Documentation

Index

Constants

This section is empty.

Variables

View Source
var (
	ErrAuthInvalid                                       = fmt.Errorf("Authentication has been invalidated, please log in again")
	ErrEmailAddressAlreadyUsed                           = fmt.Errorf("Email address is unable to be used")
	ErrFailedToCreateUserCreationSecret                  = fmt.Errorf("Failed to create a user creation secret")
	ErrFailedToFindAccount                               = fmt.Errorf("Failed to find user account")
	ErrFailedToFindUser                                  = fmt.Errorf("Failed to find user")
	ErrFailedToListUserCreationSecrets                   = fmt.Errorf("Failed to list user creation secrets")
	ErrFailedToPatchProfile                              = fmt.Errorf("Failed to patch profile")
	ErrFailedToPatchUserAccount                          = fmt.Errorf("Failed to patch user account")
	ErrFailedToUpdateUserAccount                         = fmt.Errorf("Failed to update user account")
	ErrFailedToUpdateProfile                             = fmt.Errorf("Failed to update profile")
	ErrInvalidEmailAddress                               = fmt.Errorf("Invalid email address")
	ErrNoGroupsProvided                                  = fmt.Errorf("No groups provided; please select at least one group")
	ErrUserAccountConfirmPasswordRequiredForRegistration = fmt.Errorf("Unable to confirm account, a password must be provided to complete registration")
	ErrUserAccountConfirmSecretDoesNotMatch              = fmt.Errorf("Unable to confirm account, as the secret doesn't match")
	ErrFailedToFindSystemAuthSecret                      = fmt.Errorf("Unable to find FlatTrack system auth secret. Please contact system administrators or support")
	ErrFailedToFindAccountConfirmSecret                  = fmt.Errorf("Unable to find account confirmation secret")
	ErrFailedToFindAuthToken                             = fmt.Errorf("Unable to find authorization token")
	ErrFailedToFindAuthTokenAccountID                    = fmt.Errorf("Unable to find the user account which the authentication token belongs to")
	ErrFailedToFindUserAccount                           = fmt.Errorf("Unable to find user account")
	ErrFailedToReadJWTClaims                             = fmt.Errorf("Unable to read JWT claims")
	ErrAuthTokenExpired                                  = fmt.Errorf("Unable to use existing login token as it is invalid")
	ErrAuthTokenFailed                                   = fmt.Errorf("Unable to use login token provided, please log in again")
	ErrUserAccountNotFound                               = fmt.Errorf("Failed to find user account")
	ErrUserAccountInvalidBirthday                        = fmt.Errorf("Unable to use the provided birthday, your birthday year must not be within the last 15 years")
	ErrUserAccountInvalidEmail                           = fmt.Errorf("Unable to use the provided email, as it is either empty or not valid")
	ErrUserAccountInvalidGroup                           = fmt.Errorf("Unable to use the provided group as it is invalid")
	ErrUserAccountInvalidName                            = fmt.Errorf("Unable to use the provided name, as it is either empty or too long or too short")
	ErrUserAccountInvalidPassword                        = fmt.Errorf("Unable to use the provided password, as it is either empty of invalid")
	ErrUserAccountInvalidPhoneNumber                     = fmt.Errorf("Unable to use the provided phone number")
	ErrUserAccountMustBeInFlatmemberGroup                = fmt.Errorf("User account must be in the flatmember group")
	ErrUserAccountIsDisabled                             = fmt.Errorf("Your user account is disabled")
	ErrAuthorizationHeaderNotFound                       = fmt.Errorf("Unable to find authorization token (header doesn't exist)")
	ErrUserAccountCreationSecretNotFound                 = fmt.Errorf("Failed to find user account creation secret")
)

Functions

func GetAuthTokenFromHeader

func GetAuthTokenFromHeader(r *http.Request) (string, error)

GetAuthTokenFromHeader ... given a request, retreive the authoriation value

Types

type Manager

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

UserManager manages user accounts

func NewManager

func NewManager(db *sql.DB) *Manager

func (*Manager) CheckUserPassword

func (m *Manager) CheckUserPassword(email string, password string) (matches bool, err error)

CheckUserPassword ... given an email and password, find the user account with the email, return if the password matches

func (*Manager) ConfirmUserAccount

func (m *Manager) ConfirmUserAccount(id string, secret string, user types.UserSpec) (tokenString string, err error)

ConfirmUserAccount ... confirms the user account

func (*Manager) Create

func (m *Manager) Create(user types.UserSpec, allowEmptyPassword bool) (userInserted types.UserSpec, err error)

Create ... given a UserSpec, create a user

func (*Manager) DeleteByID

func (m *Manager) DeleteByID(id string) (err error)

DeleteByID ... given an id, remove the user account from all the groups and then delete a user account

func (*Manager) GenerateJWTauthToken

func (m *Manager) GenerateJWTauthToken(id string, authNonce string, expiresIn time.Duration) (tokenString string, err error)

GenerateJWTauthToken ... given an email, return a usable JWT token

func (*Manager) GenerateNewAuthNonce

func (m *Manager) GenerateNewAuthNonce(id string) (err error)

GenerateNewAuthNonce ... given a user account id, generates a new auth nonce to reset all logins and invalidate all issued JWTs

func (*Manager) Get

func (m *Manager) Get(userSelect types.UserSpec, includePassword bool) (user types.UserSpec, err error)

Get ... given a UserSpec and an ID or Email, return a user from the database

func (*Manager) GetByEmail

func (m *Manager) GetByEmail(email string, includePassword bool) (user types.UserSpec, err error)

GetByEmail ... given a email, return a UserSpec

func (*Manager) GetByID

func (m *Manager) GetByID(id string, includePassword bool) (user types.UserSpec, err error)

GetByID ... given an id, return a UserSpec

func (*Manager) GetIDFromJWT

func (m *Manager) GetIDFromJWT(r *http.Request) (id string, err error)

GetIDFromJWT ... return the userID in a JWT from a header in a HTTP request TODO move into internal/httpserver/common.go

func (*Manager) GetProfile

func (m *Manager) GetProfile(r *http.Request) (user types.UserSpec, err error)

GetProfile ... return user from ID in JWT from HTTP request TODO move into internal/httpserver/common.go

func (*Manager) InvalidateAllAuthTokens

func (m *Manager) InvalidateAllAuthTokens(id string) (err error)

InvalidateAllAuthTokens ... updates the authNonce to invalidate auth tokens

func (*Manager) List

func (m *Manager) List(includePassword bool, selectors types.UserSelector) (users []types.UserSpec, err error)

List ... return all users in the database

func (*Manager) Patch

func (m *Manager) Patch(id string, userAccount types.UserSpec) (userAccountPatched types.UserSpec, err error)

Patch ... patches the profile of a user account

func (*Manager) PatchAsAdmin

func (m *Manager) PatchAsAdmin(id string, userAccount types.UserSpec) (userAccountPatched types.UserSpec, err error)

PatchAsAdmin ... patches a profile with all fields

func (*Manager) PatchDisabledAsAdmin

func (m *Manager) PatchDisabledAsAdmin(id string, disabled bool) (userAccount types.UserSpec, err error)

PatchDisabledAsAdmin ... patches is user account to be disabled

func (*Manager) Update

func (m *Manager) Update(id string, userAccount types.UserSpec) (userAccountUpdated types.UserSpec, err error)

Update ... updates the profile of a user account

func (*Manager) UpdateAsAdmin

func (m *Manager) UpdateAsAdmin(id string, userAccount types.UserSpec) (userAccountUpdated types.UserSpec, err error)

UpdateAsAdmin ... updates all fields of a profile

func (*Manager) UserAccountExists

func (m *Manager) UserAccountExists(id string) (exists bool, err error)

UserAccountExists ... returns bool if user account exists

func (*Manager) UserCreationSecrets

func (m *Manager) UserCreationSecrets() *userCreationSecretManager

func (*Manager) Validate

func (m *Manager) Validate(user types.UserSpec, allowEmptyPassword bool) (valid bool, err error)

ValidateUser ... given a UserSpec, return if it's valid

func (*Manager) ValidateJWTauthToken

func (m *Manager) ValidateJWTauthToken(r *http.Request) (valid bool, tokenClaims *types.JWTclaim, err error)

ValidateJWTauthToken ... given an HTTP request and Authorization header, return if auth is valid

Jump to

Keyboard shortcuts

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