user

package
v0.0.0-...-e100621 Latest Latest
Warning

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

Go to latest
Published: May 31, 2021 License: MIT Imports: 11 Imported by: 0

Documentation

Overview

Package user contains user related CRUD functionality.

Index

Constants

This section is empty.

Variables

View Source
var (
	// ErrNotFound is used when a specific User is requested but does not exist.
	ErrNotFound = errors.New("not found")

	// ErrInvalidID occurs when an ID is not in a valid form.
	ErrInvalidID = errors.New("ID is not in its proper form")

	// ErrAuthenticationFailure occurs when a user attempts to authenticate but
	// anything goes wrong.
	ErrAuthenticationFailure = errors.New("authentication failed")

	// ErrForbidden occurs when a user tries to do something that is forbidden to them according to our access control policies.
	ErrForbidden = errors.New("attempted action is not allowed")
)

Functions

This section is empty.

Types

type NewUser

type NewUser struct {
	Name            string   `json:"name" validate:"required"`
	Email           string   `json:"email" validate:"required,email"`
	Phone           string   `json:"phone" validate:"required"`
	Roles           []string `json:"roles" validate:"required"`
	Password        string   `json:"password" validate:"required"`
	PasswordConfirm string   `json:"password_confirm" validate:"eqfield=Password"`
}

NewUser contains information needed to create a new User.

type UpdateUser

type UpdateUser struct {
	Name            *string  `json:"name"`
	Email           *string  `json:"email" validate:"omitempty,email"`
	Phone           *string  `json:"phone" validate:"omitempty,phone"`
	Roles           []string `json:"roles"`
	Password        *string  `json:"password"`
	PasswordConfirm *string  `json:"password_confirm" validate:"omitempty,eqfield=Password"`
}

UpdateUser defines what information may be provided to modify an existing User. All fields are optional so clients can send just the fields they want changed. It uses pointer fields so we can differentiate between a field that was not provided and a field that was provided as explicitly blank. Normally we do not want to use pointers to basic types but we make exceptions around marshalling/unmarshalling.

type User

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

User manages the set of API's for user access.

func New

func New(log *log.Logger, db *sqlx.DB) User

New constructs a User for api access.

func (User) Create

func (u User) Create(ctx context.Context, traceID string, nu NewUser, now time.Time) (UserInfo, error)

Create inserts a new user into the database.

func (User) Query

func (u User) Query(ctx context.Context, traceID string) ([]UserInfo, error)

Query retrieves a list of existing users from the database.

func (User) QueryByID

func (u User) QueryByID(ctx context.Context, traceID string, userID string) (UserInfo, error)

QueryByID gets the specified user from the database.

type UserInfo

type UserInfo struct {
	ID           string         `db:"uuid" json:"id"`
	Name         string         `db:"name" json:"name"`
	Email        string         `db:"email" json:"email"`
	Phone        string         `db:"phone" json:"phone"`
	Roles        pq.StringArray `db:"roles" json:"roles"`
	PasswordHash []byte         `db:"password_hash" json:"-"`
	Created      time.Time      `db:"created" json:"created"`
	Updated      time.Time      `db:"updated" json:"updated"`
}

UserInfo represents an individual user.

Jump to

Keyboard shortcuts

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