Documentation
¶
Index ¶
- Constants
- Variables
- func CreatePasswordHash(password string) (string, error)
- type User
- type UserRepository
- func (r *UserRepository) AllUsers(limit int, page int) ([]User, error)
- func (r *UserRepository) Authenticate(email string, password string) (bool, error)
- func (r *UserRepository) Create(email string, name string, picture string, password string) (*User, error)
- func (r *UserRepository) Delete(email string) error
- func (r *UserRepository) Exists(email string) bool
- func (r *UserRepository) FindAllMatching(searchQuery string, limit int, page int) ([]User, error)
- func (r *UserRepository) FindByEmail(email string) (*User, error)
- func (r *UserRepository) Seen(email string) error
- func (r *UserRepository) UpdatePassword(email string, password string) (updated bool, err error)
- func (r *UserRepository) UpdateProfile(email string, name string, picture string) (bool, error)
Constants ¶
const ( UserRepositoryListMaxLimit = 100 UserPasswordMinLen = 6 )
Variables ¶
Functions ¶
func CreatePasswordHash ¶
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 ¶
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 (*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.