user

package
v0.1.0 Latest Latest
Warning

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

Go to latest
Published: Jun 16, 2022 License: GPL-3.0 Imports: 14 Imported by: 0

Documentation

Overview

Package users provides an example of a core business API. Right now these calls are just wrapping the data/data layer. But at some point you will want auditing or something that isn't specific to the data/store layer.

Index

Constants

This section is empty.

Variables

View Source
var (
	ErrNotFound              = errors.New("user not found")
	ErrInvalidID             = errors.New("ID is not in its proper form")
	ErrInvalidEmail          = errors.New("email is not valid")
	ErrUniqueEmail           = errors.New("email is not unique")
	ErrAuthenticationFailure = errors.New("authentication failed")
	ErrInvalidPassword       = errors.New("password is not valid")
)

Set of error variables for CRUD operations.

Functions

This section is empty.

Types

type ChangePassword

type ChangePassword struct {
	OldPassword string  `json:"old_password" validate:"required,min=6,max=64"`
	Password    *string `json:"Password" validate:"required,min=6,max=64"`
}

ChangePassword defines what information may be provided to change an existing user's password.

type Core

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

Core manages the set of APIs for user access.

func NewCore

func NewCore(log *zap.SugaredLogger, sqlxDB *sqlx.DB) Core

NewCore constructs a core for user api access.

func (Core) Authenticate

func (c Core) Authenticate(ctx context.Context, email, password string) (auth.Claims, error)

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

func (Core) ChangePassword

func (c Core) ChangePassword(ctx context.Context, userID string, cp ChangePassword, now time.Time) error

ChangePassword replaces a user document in the database.

func (Core) Create

func (c Core) Create(ctx context.Context, nu NewUser, now time.Time, inviteDate ...string) (User, error)

Create inserts a new user into the database.

func (Core) QueryByEmail

func (c Core) QueryByEmail(ctx context.Context, email string) (User, error)

QueryByEmail gets the specified user from the database by email.

func (Core) QueryByID

func (c Core) QueryByID(ctx context.Context, userID string) (User, error)

QueryByID gets the specified user from the database.

func (Core) Update

func (c Core) Update(ctx context.Context, userID string, uu UpdateUser, now time.Time) error

Update replaces a user document in the database.

func (Core) UpdateImage

func (c Core) UpdateImage(ctx context.Context, userID string, ui UpdateImage, now time.Time) error

UpdateImage replaces a user document in the database.

type NewUser

type NewUser struct {
	Email    string `json:"email" validate:"required,email"`
	Password string `json:"password" validate:"required,min=6,max=64"`
}

NewUser contains information needed to create a new user.

type UpdateImage

type UpdateImage struct {
	ImageName string `json:"image_name" validate:"required,omitempty"`
}

UpdateImage defines what information may be provided to update an existing user's image.

type UpdateUser

type UpdateUser struct {
	DefaultWid      *string    `json:"default_wid"`
	Email           *string    `json:"email" validate:"omitempty,email"`
	FullName        *string    `json:"full_name"`
	TimeOfDayFormat *string    `json:"time_of_day_format" validate:"omitempty,eq=H:mm|eq=h:mm"`
	DateFormat      *string    `json:"date_format" validate:"omitempty,eq=YYYY-MM-DD|eq=DD.MM.YYYY|eq=DD-MM-YYYY|eq=MM/DD/YYYY|eq=DD/MM/YYYY|eq=MM-DD-YYYY"`
	BeginningOfWeek *int       `json:"beginning_of_week" validate:"omitempty,min=0|max=6"`
	Language        *string    `json:"language"`
	DateCreated     *time.Time `json:"date_created"`
	DateUpdated     *time.Time `json:"date_updated"`
	TimeZone        *string    `json:"timezone"`
	Invitation      []string   `json:"invitation"`
	DurationFormat  *string    `json:"duration_format"`
}

UpdateUser defines what information may be provided to modify an existing user. All fields are optional so user 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    `json:"id"`
	DefaultWid      string    `json:"default_wid"`
	Email           string    `json:"email"`
	PasswordHash    []byte    `json:"password_hash"`
	FullName        string    `json:"full_name"`
	TimeOfDayFormat string    `json:"time_of_day_format"`
	DateFormat      string    `json:"date_format"`
	BeginningOfWeek int       `json:"beginning_of_week"`
	Language        string    `json:"language"`
	ImageURL        string    `json:"image_url"`
	DateCreated     time.Time `json:"date_created"`
	DateUpdated     time.Time `json:"date_updated"`
	TimeZone        string    `json:"timezone"`
	Invitation      []string  `json:"invitation"`
	DurationFormat  string    `json:"duration_format"`
}

User represents an individual user.

Directories

Path Synopsis
Package db contains user related CRUD functionality.
Package db contains user related CRUD functionality.

Jump to

Keyboard shortcuts

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