user

package
v1.0.0 Latest Latest
Warning

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

Go to latest
Published: Feb 24, 2024 License: GPL-3.0 Imports: 9 Imported by: 0

Documentation

Index

Constants

This section is empty.

Variables

View Source
var (
	ErrInvalidFields = errors.New("contains invalid fields")
	ErrWrongPassword = errors.New("wrong password")
)

Functions

func NewCreateHandler

func NewCreateHandler(l *slog.Logger, users Storer) http.Handler

func NewLoginHandler

func NewLoginHandler(l *slog.Logger, users Retreiver) http.Handler

func WriteUnauthorizedError

func WriteUnauthorizedError(l *slog.Logger, w http.ResponseWriter, err error)

Types

type BcryptHash

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

func NewBcryptHash

func NewBcryptHash(password string) (BcryptHash, error)

type Retreiver

type Retreiver interface {
	// ByUsername returns the User given a username
	// it returns an ErrNotFound if user does not exists
	// includeWorkouts and includeExercises include
	// the user's workouts and workout exercises as well
	ByUsername(username string) (User, error)

	// Authenticate returns the user after checking the
	// credentials. It returns an ErrWrongPassword if
	// username/password pair doesn't match
	Authenticate(username string, password []byte) (User, error)
}

Retreiver implementations can query data

type SQLUserStore

type SQLUserStore struct {
	*storage.SqliteDatastore
}

func (*SQLUserStore) Authenticate

func (us *SQLUserStore) Authenticate(username string, password []byte) (User, error)

func (*SQLUserStore) ByUsername

func (us *SQLUserStore) ByUsername(username string) (User, error)

func (*SQLUserStore) New

func (us *SQLUserStore) New(username string, email string, password []byte) (User, error)

type Storer

type Storer interface {
	// New is responsible for validating the email and
	// encrypting the password before storing. A new userID will
	// be returned on success otherwise an error is thrown
	New(username string, email string, password []byte) (User, error)
}

Storer allow for new users to be created

type User

type User struct {
	Username string `json:"username"`
	Email    string `json:"email"`
	Password []byte `json:"password"`
}

User is a registered person that can login to the application. Password is the encrypted password.

type UserStore

type UserStore interface {
	Storer
	Retreiver
}

UserStore represents the user repository

func NewSQLUserStore

func NewSQLUserStore(ds *storage.SqliteDatastore) UserStore

Jump to

Keyboard shortcuts

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