user

package
v0.0.0-...-53bd342 Latest Latest
Warning

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

Go to latest
Published: Nov 6, 2023 License: GPL-3.0 Imports: 12 Imported by: 0

Documentation

Index

Constants

This section is empty.

Variables

View Source
var (
	ErrUniqueEmail = errors.New("email is not unique")
)

Functions

func Create

func Create(ctx context.Context, db sqlx.ExtContext, user User) error

Create inserts a new user.

func HandleCreate

func HandleCreate(db *sqlx.DB) web.Handler

HandleCreate allows administrators to create new users.

func HandleShow

func HandleShow(db *sqlx.DB) web.Handler

HandleShow returns the information of a user.

func HandleShowCurrent

func HandleShowCurrent(db *sqlx.DB) web.Handler

HandleShowCurrent returns the current user's information. Current user is the one retrieved by session cookie.

Types

type User

type User struct {
	ID           string    `json:"id" db:"user_id"`
	Name         string    `json:"name" db:"name"`
	Email        string    `json:"email" db:"email"`
	Role         string    `json:"role" db:"role"`
	Active       bool      `json:"active" db:"active"`
	PasswordHash []byte    `json:"-" db:"password_hash"`
	CreatedAt    time.Time `json:"createdAt" db:"created_at"`
	UpdatedAt    time.Time `json:"updatedAt" db:"updated_at"`
	Version      int       `json:"-" db:"version"`
}

User models users. Email address is a unique field.

func Fetch

func Fetch(ctx context.Context, db sqlx.ExtContext, id string) (User, error)

Fetch returns user information.

func FetchByEmail

func FetchByEmail(ctx context.Context, db sqlx.ExtContext, email string) (User, error)

FetchByEmail returns the user corresponding to a specific email, if any.

func FetchByToken

func FetchByToken(ctx context.Context, db sqlx.ExtContext, tokenHash []byte, tokenScope string) (User, error)

FetchByToken retrieves the user corresponding to the passed token.

func Update

func Update(ctx context.Context, db sqlx.ExtContext, user User) (User, error)

Update updates an existing user with provided information. It relies on optimistic lock to deal with data races.

type UserNew

type UserNew struct {
	Name            string `json:"name" validate:"required"`
	Email           string `json:"email" validate:"required,email"`
	Role            string `json:"role" validate:"required"`
	Password        string `json:"password" validate:"required"`
	PasswordConfirm string `json:"passwordConfirm" validate:"eqfield=Password"`
}

UserNew includes the information an administrator needs to create a new user.

type UserSignup

type UserSignup struct {
	Name            string `json:"name" validate:"required"`
	Email           string `json:"email" validate:"required,email"`
	Password        string `json:"password" validate:"required,gte=8,lte=50"`
	PasswordConfirm string `json:"passwordConfirm" validate:"omitempty,eqfield=Password"`
}

UserSignup contains information needed to register a user.

type UserUp

type UserUp struct {
	Name            *string `json:"name"`
	Email           *string `json:"email" validate:"omitempty,email"`
	Role            *string `json:"role"`
	Password        *string `json:"password"`
	PasswordConfirm *string `json:"passwordConfirm" validate:"omitempty,eqfield=Password"`
}

UserUp specifies information of a user which can be updated.

Jump to

Keyboard shortcuts

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