users

package
v0.0.4 Latest Latest
Warning

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

Go to latest
Published: Jun 23, 2021 License: Apache-2.0 Imports: 12 Imported by: 0

Documentation

Index

Constants

View Source
const (
	// The database table name for users.
	TableName = "users"
	// The database table name for the user-roles pivot.
	PivotTableName = "user_roles"
)

Variables

View Source
var (
	// ErrUserExists is returned by validate when
	// a user already exists.
	ErrUserExists = errors.New("user already exists")
	// ErrDeleteOwner is returned by delete when
	// the owner id has been passed.
	ErrDeleteOwner = errors.New("owner cannot be deleted")
	// ErrSessionExpired is returned by check session
	// when the user session has gone passed the
	// inactive session time.
	ErrSessionExpired = errors.New("session expired")
)

Functions

This section is empty.

Types

type Repository

type Repository interface {
	List(meta params.Params, role string) (domain.Users, int, error)
	Find(id int) (domain.User, error)
	FindByToken(token string) (domain.User, error)
	FindByEmail(email string) (domain.User, error)
	Owner() domain.User
	Create(u domain.UserCreate) (domain.User, error)
	Update(u domain.User) (domain.User, error)
	Delete(id int) error
	CheckSession(token string) error
	ResetPassword(id int, reset domain.UserPasswordReset) error
	UpdateToken(token string) error
	Exists(id int) bool
	ExistsByEmail(email string) bool
}

Repository defines methods for users to interact with the database.

type Store

type Store struct {
	*config.Config
	// contains filtered or unexported fields
}

Store defines the data layer for users.

func New

func New(cfg *config.Config) *Store

New

Creates a new users store.

func (*Store) CheckSession

func (s *Store) CheckSession(token string) error

CheckSession

Returns nil if the session is valid. Returns errors.NOTFOUND if the user was not found. Returns errors.CONFLICT if the user session expired. Returns errors.INTERNAL if the SQL query was invalid.

func (*Store) Create

func (s *Store) Create(u domain.UserCreate) (domain.User, error)

Create

Returns a new category upon creation. Returns errors.CONFLICT if the the category (name) already exists. Returns errors.INTERNAL if the SQL query was invalid or the function could not get the newly created ID.

func (*Store) Delete

func (s *Store) Delete(id int) error

Delete

Returns nil if the user was successfully deleted. Returns errors.INTERNAL if the SQL query was invalid. Returns errors.NOTFOUND if the category was not found.

func (*Store) Exists

func (s *Store) Exists(id int) bool

Exists

Returns a bool indicating if the user exists by ID. Logs errors.INTERNAL if there was an error executing the query.

func (*Store) ExistsByEmail

func (s *Store) ExistsByEmail(email string) bool

ExistsByEmail

Returns a bool indicating if the user exists by email. Logs errors.INTERNAL if there was an error executing the query.

func (*Store) Find

func (s *Store) Find(id int) (domain.User, error)

Find

Returns a user by searching with the given ID. Returns errors.INTERNAL if there was an error executing the query. Returns errors.NOTFOUND if the category was not found by the given ID.

func (*Store) FindByEmail

func (s *Store) FindByEmail(email string) (domain.User, error)

FindByEmail

Returns a user by searching with the given email. Returns errors.INTERNAL if there was an error executing the query. Returns errors.NOTFOUND if the category was not found by the given ID.

func (*Store) FindByToken

func (s *Store) FindByToken(token string) (domain.User, error)

FindByToken

Returns a user by searching with the given token. Returns errors.INTERNAL if there was an error executing the query. Returns errors.NOTFOUND if the category was not found by the given ID.

func (*Store) List

func (s *Store) List(meta params.Params, role string) (domain.Users, int, error)

List

Returns a slice of users with the total amount. Returns errors.INTERNAL if the SQL query was invalid. Returns errors.NOTFOUND if there are no categories available.

func (*Store) Owner

func (s *Store) Owner() domain.User

Owner

Returns a the owner of the installation. Logs errors.INTERNAL if there was an error executing the query. Logs errors.NOTFOUND if the category was not found by the given ID.

func (*Store) ResetPassword

func (s *Store) ResetPassword(id int, reset domain.UserPasswordReset) error

ResetPassword

Returns nil if the password as reset successfully. Returns errors.INTERNAL if the SQL query was invalid. Returns errors.INVALID if the user could not be updated.

func (*Store) Update

func (s *Store) Update(u domain.User) (domain.User, error)

Update

Returns an updated user. Returns errors.CONFLICT if the validation failed. Returns errors.INTERNAL if the SQL query was invalid or the function could not obtain the newly created ID.

func (*Store) UpdateToken

func (s *Store) UpdateToken(token string) error

UpdateToken

Returns nil if the token last used column was successfully updated. Returns errors.INTERNAL if the sql query failed to execute or the token does not exist.

Jump to

Keyboard shortcuts

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