repos

package
v0.0.0-...-9c9e09e Latest Latest
Warning

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

Go to latest
Published: Feb 18, 2022 License: BSD-3-Clause Imports: 7 Imported by: 0

Documentation

Index

Constants

View Source
const (
	UserRepositoryListMaxLimit = 100
	UserPasswordMinLen         = 6
)

Variables

View Source
var (
	ErrUserNotFound     = errors.New("queried user could not be not found")
	ErrUserAlreadyExist = errors.New("user with same email already exist in database")
	ErrInvalidEmail     = errors.New("invalid user email field")
	ErrInvalidPassword  = errors.New("invalid password")
)

Functions

func CreatePasswordHash

func CreatePasswordHash(password string) (string, error)

Types

type User

type User struct {
	Email             string `db:"email"`
	Name              string `db:"name"`
	Picture           string `db:"picture"`
	PasswordHash      string `db:"password"`
	CreatedAt         int64  `db:"created_at"`
	ProfileUpdatedAt  int64  `db:"profile_updated_at"`
	PasswordUpdatedAt int64  `db:"password_updated_at"`
	LastSeenAt        int64  `db:"last_seen_at"`
}

func (*User) PasswordMatch

func (u *User) PasswordMatch(password string) bool

type UserRepository

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

UserRepository stores and access data in a sqlite database.

func NewUserRepository

func NewUserRepository(db *sqlx.DB) (*UserRepository, error)

NewUserRepository returns a ready to use UserRepository with a new database connexion.

func (*UserRepository) AllUsers

func (r *UserRepository) AllUsers(limit int, page int) ([]User, error)

AllUsers Return list of users sorted by email. Passing 0 as the limit will use UserRepositoryListMaxLimit as the limit. Page 0 and 1 are seen as the same page number essentially: `offset = (page - 1) * limit`.

func (*UserRepository) Authenticate

func (r *UserRepository) Authenticate(email string, password string) (bool, error)

Authenticate validates if the email and password combination matches an existing user in the database with a password resulting in the same password hash. Updates last_seen_at if user is authenticated.

func (*UserRepository) Create

func (r *UserRepository) Create(email string, name string, picture string, password string) (*User, error)

Create INSERT a new user record with email and argon2id password hash from the provided password. If the user already exists returns the record from the Database, otherwise return the newly created User.

func (*UserRepository) Delete

func (r *UserRepository) Delete(email string) error

Delete delete user record for given email.

func (*UserRepository) Exists

func (r *UserRepository) Exists(email string) bool

func (*UserRepository) FindAllMatching

func (r *UserRepository) FindAllMatching(searchQuery string, limit int, page int) ([]User, error)

func (*UserRepository) FindByEmail

func (r *UserRepository) FindByEmail(email string) (*User, error)

FindByEmail Looks for a user record that matches the provided email and returns a pointer to User stuck if found or nil if not.

func (*UserRepository) Seen

func (r *UserRepository) Seen(email string) error

Seen updates user's last_seen_at value with current Unix time.

func (*UserRepository) UpdatePassword

func (r *UserRepository) UpdatePassword(email string, password string) (updated bool, err error)

UpdatePassword replaces the specified user's (found by email address) by the password provided. The password is not stored as is. It is hashed with argon2id.

func (*UserRepository) UpdateProfile

func (r *UserRepository) UpdateProfile(email string, name string, picture string) (bool, error)

Jump to

Keyboard shortcuts

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