user

package
v0.1.4 Latest Latest
Warning

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

Go to latest
Published: Nov 15, 2022 License: Unlicense Imports: 10 Imported by: 0

Documentation

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("User 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")

	// ErrInvalidCredentials occurs when a user  tries to login with
	// an incorrect email address or password.
	ErrInvalidCredentials = errors.New("models: invalid credentials")

	// ErrDuplicateEmail occurs when a user tries to signup with an
	// email address that's already in use
	ErrDuplicateEmail = errors.New("models: duplicate email")
)

Functions

This section is empty.

Types

type Info

type Info struct {
	ID           string    `db:"user_id" json:"id"`
	Name         string    `db:"name" json:"name"`
	Email        string    `db:"email" json:"email"`
	Active       bool      `db:"active" json:"active"`
	Roles        []string  `db:"roles" json:"roles"`
	PasswordHash string    `db:"password_hash" json:"-"`
	DateCreated  time.Time `db:"date_created" json:"date_created"`
	DateUpdated  time.Time `db:"date_updated" json:"date_updated"`
}

Info represents information about an individual user.

type NewUser

type NewUser struct {
	Name            string   `json:"name" validate:"required"`
	Email           string   `json:"email" 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 Store added in v0.1.2

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

Store manages the set of API's for user access. It wraps a pgxpool.Pool and Argon2 parameters.

func NewStore added in v0.1.4

func NewStore(db *pgxpool.Pool, hp *argon2id.Params) Store

NewStore constructs a Store for api access.

func (Store) Authenticate added in v0.1.2

func (s Store) Authenticate(ctx context.Context, 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 (Store) ChangePassword added in v0.1.2

func (s Store) ChangePassword(ctx context.Context, id string, currentPassword, newPassword string) error

ChangePassword generates a hash based on the new password and saves it to the db.

func (Store) Create added in v0.1.2

func (s Store) Create(ctx context.Context, n NewUser, now time.Time) (*Info, error)

Create inserts a new user into the database.

func (Store) Delete added in v0.1.2

func (s Store) Delete(ctx context.Context, id string) error

Delete removes a user from the database.

func (Store) List added in v0.1.2

func (s Store) List(ctx context.Context) ([]Info, error)

List retrieves a list of existing users from the database.

func (Store) QueryByID added in v0.1.2

func (s Store) QueryByID(ctx context.Context, id string) (*Info, error)

QueryByID gets the specified user from the database.

func (Store) Update added in v0.1.2

func (s Store) Update(ctx context.Context, id string, upd UpdateUser, now time.Time) error

Update replaces a user document in the database.

type UpdateUser

type UpdateUser struct {
	Name            *string  `json:"name"`
	Email           *string  `json:"email"`
	Active          bool     `json:"active"`
	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.

Jump to

Keyboard shortcuts

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