Documentation
¶
Index ¶
- Constants
- Variables
- func BindUserContext(userModule *Controller) func(ctx *apiCtx, rw web.ResponseWriter, req *web.Request, ...)
- type Controller
- func (userModule *Controller) Activate(email string) (user User, err error)
- func (userModule *Controller) BindAPI(router *web.Router)
- func (userModule *Controller) Create(email, username, pass string) (user User, err error)
- func (userModule *Controller) GetUser(userid string) (interface{}, error)
- func (userModule *Controller) GetUserByEmail(email string) (interface{}, error)
- func (userModule *Controller) HandleToken(userid string, action api.TokenAction) (err error)
- func (userModule *Controller) Lock(email string) (user User, err error)
- func (userModule *Controller) Login(email string, pass string) (bool, interface{}, error)
- func (userModule *Controller) PostLoginFailure(u interface{}) error
- func (userModule *Controller) PostLoginSuccess(u interface{}) error
- func (userModule *Controller) PreLogin(u interface{}) (bool, error)
- func (userModule *Controller) SetPassword(userid, password string) (User, error)
- func (userModule *Controller) Unlock(email string) (user User, err error)
- func (userModule *Controller) UpdatePassword(userid string, old string, new string) (User, error)
- type Storer
- type User
- type UserResp
Constants ¶
const ( // MinPasswordLength Minimum password length MinPasswordLength = 12 // HashRounds BCrypt Hash Rounds HashRounds = 12 // MinZxcvbnScore Minimum password zxcvbn score MinZxcvbnScore = 4 )
Variables ¶
var ( ErrorPasswordTooShort = errors.New("User Controller: password does not meet complexity requirements") ErrorPasswordEntropyTooLow = errors.New("User controller: password entropy too low") ErrorPasswordHashTooShort = errors.New("User Controller: password hash too short") ErrorFindingUser = errors.New("User Controller: error checking for user account") ErrorDuplicateAccount = errors.New("User Controller: user account with email or username already exists") ErrorCreatingUser = errors.New("User Controller: error creating user") ErrorUserNotFound = errors.New("User Controller: user not found") ErrorPasswordMismatch = errors.New("User Controller: password mismatch") ErrorUpdatingUser = errors.New("User Controller: error updating user") ErrorAddingToken = errors.New("User Controller: error adding token") ErrorUpdatingToken = errors.New("User Controller: error updating token") )
User control errors
Functions ¶
func BindUserContext ¶
func BindUserContext(userModule *Controller) func(ctx *apiCtx, rw web.ResponseWriter, req *web.Request, next web.NextMiddlewareFunc)
BindUserContext Helper middleware to bind module to API context
Types ¶
type Controller ¶
type Controller struct {
// contains filtered or unexported fields
}
Controller User controller instance storage
func NewController ¶
func NewController(userStore Storer, emitter events.Emitter) *Controller
NewController Create a new user controller
func (*Controller) Activate ¶
func (userModule *Controller) Activate(email string) (user User, err error)
Activate activates the provided user account
func (*Controller) BindAPI ¶
func (userModule *Controller) BindAPI(router *web.Router)
BindAPI Binds the API for the user module to the provided router
func (*Controller) Create ¶
func (userModule *Controller) Create(email, username, pass string) (user User, err error)
Create a new user account
func (*Controller) GetUser ¶
func (userModule *Controller) GetUser(userid string) (interface{}, error)
GetUser finds a user by userID
func (*Controller) GetUserByEmail ¶
func (userModule *Controller) GetUserByEmail(email string) (interface{}, error)
GetUserByEmail finds a user by userID
func (*Controller) HandleToken ¶
func (userModule *Controller) HandleToken(userid string, action api.TokenAction) (err error)
HandleToken provides a generic method to handle an action token This executes the specified api.TokenAction on the provided user
func (*Controller) Lock ¶
func (userModule *Controller) Lock(email string) (user User, err error)
Unlock unlocks the provided user account
func (*Controller) Login ¶
func (userModule *Controller) Login(email string, pass string) (bool, interface{}, error)
Login checks user credentials and returns a login state and the associated user object (if found)
func (*Controller) PostLoginFailure ¶
func (userModule *Controller) PostLoginFailure(u interface{}) error
PostLoginFailure runs Failure actions for the user module
func (*Controller) PostLoginSuccess ¶
func (userModule *Controller) PostLoginSuccess(u interface{}) error
PostLoginSuccess runs success actions for the user module
func (*Controller) PreLogin ¶
func (userModule *Controller) PreLogin(u interface{}) (bool, error)
PreLogin checks for the user module
func (*Controller) SetPassword ¶
func (userModule *Controller) SetPassword(userid, password string) (User, error)
SetPassword sets a user password without checking the existing one
func (*Controller) Unlock ¶
func (userModule *Controller) Unlock(email string) (user User, err error)
Unlock unlocks the provided user account
func (*Controller) UpdatePassword ¶
UpdatePassword updates a user password This checks the original password prior to updating and fails on password errors
type Storer ¶
type Storer interface { AddUser(email, username, pass string) (interface{}, error) GetUserByExtID(userid string) (interface{}, error) GetUserByEmail(email string) (interface{}, error) GetUserByUsername(username string) (interface{}, error) UpdateUser(user interface{}) (interface{}, error) }
Storer Defines the required store interfaces for the user module Returned interfaces must satisfy the User interface requirements
type User ¶
type User interface { GetExtID() string GetEmail() string GetUsername() string GetPassword() string SetPassword(pass string) GetPasswordChanged() time.Time IsActivated() bool SetActivated(activated bool) IsEnabled() bool SetEnabled(locked bool) GetLoginRetries() uint SetLoginRetries(retries uint) GetLastLogin() time.Time SetLastLogin(t time.Time) GetCreatedAt() time.Time IsLocked() bool SetLocked(locked bool) IsAdmin() bool }
User Defines the User object interfaces required by this module