user

package
v0.0.0-...-9790b92 Latest Latest
Warning

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

Go to latest
Published: Jan 28, 2024 License: Apache-2.0 Imports: 8 Imported by: 0

Documentation

Index

Constants

This section is empty.

Variables

View Source
var (
	// ErrNotFound is used when a specific Product 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")

	// ErrDuplicateEmail occus when the email exists in the database.
	ErrDuplicateEmail = errors.New("email already in use")

	// 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 access control policies.
	ErrForbidden = errors.New("attempted action is not allowed")
)

Functions

This section is empty.

Types

type Info

type Info struct {
	ID           string `db:"user_id"`
	Name         string `db:"name"`
	Email        string `db:"email"`
	PasswordHash []byte `db:"password_hash"`
	Active       bool   `db:"active"`
	DateCreated  string `db:"created_at"`
	DateUpdated  string `db:"updated_at"`
}

Info is the model for a user.

type NewUser

type NewUser struct {
	Name            string
	Email           string
	Password        string
	PasswordConfirm string
}

NewUser contains information needed to create a new user.

type RepositoryDb

type RepositoryDb struct {
	Db *sqlx.DB
}

RepositoryDb defines the repository for the user service.

func New

func New(db *sqlx.DB) RepositoryDb

New returns a pointer to a user repo.

func (RepositoryDb) Authenticate

func (r RepositoryDb) Authenticate(email, password string) (string, error)

Authenticate queries the database for a user with a matching pasword.

func (RepositoryDb) ChangePassword

func (r RepositoryDb) ChangePassword(currentPassword, newPassword, userID string) error

func (RepositoryDb) Create

func (r RepositoryDb) Create(user NewUser) (Info, error)

Create inserts a new user into the database.

func (RepositoryDb) QueryByID

func (r RepositoryDb) QueryByID(userID string) (Info, error)

QueryByID gets the specified user from the database.

Jump to

Keyboard shortcuts

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