user

package
v0.1.0 Latest Latest
Warning

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

Go to latest
Published: Feb 3, 2018 License: GPL-3.0 Imports: 14 Imported by: 0

Documentation

Index

Constants

View Source
const (
	// MinPasswordLength Minimum password length
	MinPasswordLength = 12
	// HashRounds BCrypt Hash Rounds
	HashRounds = 12
	// MinZxcvbnScore Minimum password zxcvbn score
	MinZxcvbnScore = 4
)

Variables

View Source
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

func (userModule *Controller) UpdatePassword(userid string, old string, new string) (User, error)

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

type UserResp

type UserResp struct {
	ExtID     string
	Email     string
	Username  string
	Activated bool
	Enabled   bool
	Locked    bool
	LastLogin time.Time
	CreatedAt time.Time
}

UserResp sanitised user object

func (*UserResp) GetEmail

func (ur *UserResp) GetEmail() string

func (*UserResp) GetExtID

func (ur *UserResp) GetExtID() string

Jump to

Keyboard shortcuts

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