users

package
v0.0.0-...-0fda810 Latest Latest
Warning

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

Go to latest
Published: Jul 11, 2022 License: Apache-2.0 Imports: 10 Imported by: 0

Documentation

Index

Constants

This section is empty.

Variables

This section is empty.

Functions

func Create

func Create(u UserDB) func(ctx context.Context, author string, data io.Reader) (interface{}, error)

Create is used to add a new app user

func Get

func Get(u UserDB) func(ctx context.Context, username string) (interface{}, error)

Get returns a user from the DB

func IsPasswordCorrect

func IsPasswordCorrect(u UserDB) func(ctx context.Context, username, password string) error

IsPasswordCorrect checks if the username and password match the ones in the DB

Types

type Email

type Email string

Email is used to match a valid email address

func (Email) IsValid

func (e Email) IsValid() bool

IsValid is the validation function for the email

type Password

type Password string

Password is used to match a valid password

func (Password) IsValid

func (p Password) IsValid() bool

IsValid is the validation function for the password The password constraints are: Must be at least 7 long Must include a number Must include a lower case letter Must inslude an upper case letter Must contain a symbol Cannot contain spaces

type User

type User struct {
	Username Username `json:"username"`
	Name     string   `json:"name"`
	Email    Email    `json:"email"`
	Password Password `json:"password,omitempty"`
}

User represents a used of the application

func (*User) Validate

func (u *User) Validate() error

Validate checks that all user constraints are met

type UserDB

type UserDB interface {
	GetUser(ctx context.Context, username string) (*User, error)
	CreateUser(ctx context.Context, user *User) error
	GetPasswordForUser(ctx context.Context, username string) (string, error)
}

UserDB encapsulates user queries

func NewUserDB

func NewUserDB(db *sql.DB) (UserDB, error)

NewUserDB creates a wrapper around the queries used to perform user operations

type Username

type Username string

Username is used to match a valid username

func (Username) IsValid

func (u Username) IsValid() bool

IsValid is used to check is a username is valid

Directories

Path Synopsis

Jump to

Keyboard shortcuts

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