users

package
v0.0.0-...-711bb3a Latest Latest
Warning

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

Go to latest
Published: May 13, 2021 License: MIT Imports: 7 Imported by: 0

Documentation

Index

Constants

This section is empty.

Variables

View Source
var ErrUserNotFound = errors.New("user not found")

ErrUserNotFound is returned when the user can't be found

Functions

This section is empty.

Types

type Credentials

type Credentials struct {
	Email    string `json:"email"`
	Password string `json:"password"`
}

Credentials represents user sign-in credentials

type MySQLStore

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

MySQLStore represents a session store backed by MySQL

func NewMySQLStore

func NewMySQLStore(DB *sql.DB) *MySQLStore

NewMySQLStore constructs a new MySQLStore

func (*MySQLStore) Delete

func (mss *MySQLStore) Delete(id int64) error

Delete deletes the user from the MySQLStore with the given ID

func (*MySQLStore) GetByEmail

func (mss *MySQLStore) GetByEmail(email string) (*User, error)

GetByEmail returns the user with the given email

func (*MySQLStore) GetByID

func (mss *MySQLStore) GetByID(id int64) (*User, error)

GetByID with the given ID

func (*MySQLStore) GetByUserName

func (mss *MySQLStore) GetByUserName(username string) (*User, error)

GetByUserName returns the user with the given username

func (*MySQLStore) Insert

func (mss *MySQLStore) Insert(user *User) (*User, error)

Insert creates a new user in the MySQLStore and returns the created user

func (*MySQLStore) InsertLog

func (mss *MySQLStore) InsertLog(userID int64, ipAddr string) error

InsertLog inserts sign-in log to logs in the database

func (*MySQLStore) Update

func (mss *MySQLStore) Update(id int64, updates *Updates) (*User, error)

Update updates the information of the user with the given ID and returns the user with the updated information

type NewUser

type NewUser struct {
	Email        string `json:"email"`
	Password     string `json:"password"`
	PasswordConf string `json:"passwordConf"`
	UserName     string `json:"userName"`
}

NewUser represents a new user signing up for an account

func (*NewUser) ToUser

func (nu *NewUser) ToUser() (*User, error)

ToUser converts the NewUser to a User, setting the PhotoURL and PassHash fields appropriately

func (*NewUser) Validate

func (nu *NewUser) Validate() error

Validate validates the new user and returns an error if any of the validation rules fail, or nil if its valid

type Store

type Store interface {
	//GetByID returns the User with the given ID
	GetByID(id int64) (*User, error)

	//GetByEmail returns the User with the given email
	GetByEmail(email string) (*User, error)

	//GetByUserName returns the User with the given Username
	GetByUserName(username string) (*User, error)

	//Insert inserts the user into the database, and returns
	//the newly-inserted User, complete with the DBMS-assigned ID
	Insert(user *User) (*User, error)

	//Update applies UserUpdates to the given user ID
	//and returns the newly-updated user
	Update(id int64, updates *Updates) (*User, error)

	//Delete deletes the user with the given ID
	Delete(id int64) error

	//InsertLog inserts sign-in log to logs in the database
	InsertLog(userID int64, ipAddr string) error
}

Store represents a store for Users

type Updates

type Updates struct {
	FirstName string `json:"firstName"`
	LastName  string `json:"lastName"`
}

Updates represents allowed updates to a user profile

type User

type User struct {
	ID       int64  `json:"id"`
	Email    string `json:"email"`
	PassHash []byte `json:"-"` //never JSON encoded/decoded
	UserName string `json:"userName"`
}

User represents a user account in the database

func (*User) Authenticate

func (u *User) Authenticate(password string) error

Authenticate compares the plaintext password against the stored hash and returns an error if they don't match, or nil if they do

func (*User) SetPassword

func (u *User) SetPassword(password string) error

SetPassword hashes the password and stores it in the PassHash field

Jump to

Keyboard shortcuts

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