user

package
v0.0.0-...-55af573 Latest Latest
Warning

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

Go to latest
Published: Sep 18, 2020 License: MIT Imports: 10 Imported by: 0

Documentation

Index

Constants

This section is empty.

Variables

View Source
var (
	ErrNoAffect       = errors.New("No rows affected")
	ErrBadCredentials = errors.New("Invalid username or password")
	ErrNoUserFound    = errors.New("No user found")
)
View Source
var (
	ErrBasicAuth      = errors.New("Basic auth requires a username and password")
	ErrInvalidID      = errors.New("ID is not in the correct form")
	ErrUsernameExists = errors.New("username is already taken")
	ErrEmailExists    = errors.New("email is already taken")
)

Functions

This section is empty.

Types

type NewUser

type NewUser struct {
	Username string   `json:"username" validate:"required"`
	Email    string   `json:"email" validate:"required,email"`
	Roles    []string `json:"roles"`
	Password string   `json:"password" validate:"required,password"`
}

type Repository

type Repository interface {
	GetById(id string) (*User, error)
	Create(u *User) error
	Update(u *User) error
	Destroy(id string) error
	GetByUsername(username string) (*User, error)
	UsernameAvailable(username, cuurentID string) bool
	EmailAvailable(username, cuurentID string) bool
}

func NewRepository

func NewRepository(db *sql.DB) Repository

type Service

type Service interface {
	GetById(id string) (*User, error)
	Create(nu *NewUser) (*User, error)
	Update(id string, uu UpdateUser) error
	Destroy(id string) error
	Authenticate(username, password string) (auth.Claims, error)
}

func NewService

func NewService(ur Repository) Service

type UpdateUser

type UpdateUser struct {
	Username string   `json:"username"`
	Email    string   `json:"email" validate:"omitempty,email"`
	Roles    []string `json:"roles"`
	Password string   `json:"password" validate:"omitempty,password"`
}

type User

type User struct {
	ID           string         `db:"id" json:"id"`
	Username     string         `db:"username" json:"username"`
	Email        string         `db:"email" json:"email"`
	Roles        pq.StringArray `db:"roles" json:"roles"`
	PasswordHash []byte         `db:"password" json:"-"`
}

Jump to

Keyboard shortcuts

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