user

package
v0.0.0-...-f3f7782 Latest Latest
Warning

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

Go to latest
Published: May 7, 2020 License: MIT Imports: 7 Imported by: 0

Documentation

Index

Constants

This section is empty.

Variables

View Source
var (
	// ErrNotFound abstracts the postgres not found error.
	ErrNotFound = errors.New("entity not found")

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

	// ErrValidateConfirmPassword occurs when password doesn't match
	ErrValidateConfirmPassword = errors.New("password confirmation failed")

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

Functions

func Authenticate

func Authenticate(db *sqlx.DB, now time.Time, email, password string) (auth.Claims, error)

Authenticate finds a user by their email and verifies their password. On success it returns a Claims value representing this user. The claims can be used to generate a token for future authentication.

func Delete

func Delete(db *sqlx.DB, id string) error

Delete removes a user from the database.

Types

type NewUser

type NewUser struct {
	Name            string `json:"name"`
	Email           string `json:"email"`
	Password        string `json:"password"`
	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"`
	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 {
	ID           string    `db:"id" json:"id"`
	Name         string    `db:"name" json:"name"`
	Email        string    `db:"email" json:"email"`
	PasswordHash []byte    `db:"password" json:"-"`
	DateCreated  time.Time `db:"date_created" json:"date_created"`
	DateUpdated  time.Time `db:"date_updated" json:"date_updated"`
}

User represents user in database

func Create

func Create(db *sqlx.DB, nu *NewUser) (*User, error)

Create inserts a new user into the database.

func List

func List(db *sqlx.DB) ([]User, error)

List retrieves a list of existing users from the database.

func Retrieve

func Retrieve(db *sqlx.DB, id string) (*User, error)

Retrieve gets the specified user from the database.

func Update

func Update(db *sqlx.DB, id string, upd UpdateUser) (*User, error)

Update replaces a user document in the database.

Jump to

Keyboard shortcuts

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