user

package
v0.0.0-...-2cbf9d5 Latest Latest
Warning

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

Go to latest
Published: Nov 17, 2020 License: AGPL-3.0 Imports: 16 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")

	// PasswordSalt is the salt value which will be addedd to passwords during the hashing process for extra security.
	PasswordSalt = "joireu98ytu98grHROIHGWJREOIJOIJroJ5Y09JRATHJOIHJj5y09aeoirjroiejjrtjhJROIJIJyjHJroisjh509e5e0jte0jhreoijtkjrtrej9yg"

	// EmailSalt is the salt value which will be addedd to emails during the hashing process for extra security.
	// Emails are hashed for GDPR compliance.
	EmailSalt = "nbkjvnKJNBKJNFNKFbnkfnte80bnfdb5e5090hetaoijknbnjvNKSFBfnkjneinF8I*H$%IHIGRiuhgIUNGEibus8b8s9rnbnrwengiubi4w9898U8H"
)
View Source
var Issuer = "MB Appiness Solutions"

Functions

This section is empty.

Types

type Info

type Info struct {
	ID           string         `db:"user_id" json:"id"`
	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:"date_created"`
	DateUpdated  time.Time      `db:"date_updated" json:"date_updated"`
}

Info represents an individual user.

type NewUser

type NewUser struct {
	Email           string   `json:"email" validate:"required,email"`
	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 {
	Email           *string  `json:"email" validate:"omitempty,email"`
	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) Authenticate

func (u User) Authenticate(ctx context.Context, traceID string, 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 Info representing this user. The claims can be used to generate a token for future authentication.

func (User) Create

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

Create inserts a new user into the database.

func (User) Delete

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

Delete removes a user from the database.

func (User) Query

func (u User) Query(ctx context.Context, traceID string, pageNumber int, rowsPerPage int) ([]Info, error)

Query retrieves a list of existing users from the database.

func (User) QueryByEmail

func (u User) QueryByEmail(ctx context.Context, traceID string, claims auth.Claims, email string) (Info, error)

QueryByEmail gets the specified user from the database by email.

func (User) QueryByID

func (u User) QueryByID(ctx context.Context, traceID string, claims auth.Claims, userID string) (Info, error)

QueryByID gets the specified user from the database.

func (User) Update

func (u User) Update(ctx context.Context, traceID string, claims auth.Claims, userID string, uu UpdateUser, now time.Time) 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