user

package
v0.0.0-...-fdd12d1 Latest Latest
Warning

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

Go to latest
Published: Jan 4, 2020 License: Apache-2.0 Imports: 9 Imported by: 0

Documentation

Overview

Package users implements all business logic regarding users.

Index

Constants

This section is empty.

Variables

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

Functions

func Authenticate

func Authenticate(ctx context.Context, 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.

Types

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 User

type User struct {
	ID           string         `db:"user_id" json:"id"`
	Name         string         `db:"name" json:"name"`
	Email        string         `db:"email" json:"email"`
	Roles        pq.StringArray `db:"roles" json:"roles"`
	PasswordHash []byte         `db:"password_hash" json:"-"`
	DateCreated  time.Time      `db:"date_created" json:"dateCreated"`
	DateUpdated  time.Time      `db:"date_updated" json:"dateUpdated"`
}

User represents someone with access to our system.

func Create

func Create(ctx context.Context, db *sqlx.DB, n NewUser, now time.Time) (*User, error)

Create inserts a new user into the database.

Jump to

Keyboard shortcuts

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