Documentation ¶
Index ¶
- Variables
- type Credentials
- type NewUser
- type SQLStore
- func (ss *SQLStore) Delete(id int64) error
- func (ss *SQLStore) GetByEmail(email string) (*User, error)
- func (ss *SQLStore) GetByID(id int64) (*User, error)
- func (ss *SQLStore) GetByUserName(username string) (*User, error)
- func (ss *SQLStore) Insert(user *User) (*User, error)
- func (ss *SQLStore) Log(userid int64, dt time.Time, ip string) error
- func (ss *SQLStore) Update(id int64, updates *Updates) (*User, error)
- type Store
- type Updates
- type User
Constants ¶
This section is empty.
Variables ¶
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 ¶
Credentials represents user sign-in credentials
type NewUser ¶
type NewUser struct { Email string `json:"email"` Password string `json:"password"` PasswordConf string `json:"passwordConf"` UserName string `json:"userName"` FirstName string `json:"firstName"` LastName string `json:"lastName"` }
NewUser represents a new user signing up for an account
type SQLStore ¶
SQLStore is db used for updating sql database
func (*SQLStore) GetByEmail ¶
GetByEmail returns the User with the given email
func (*SQLStore) GetByUserName ¶
GetByUserName returns the User with the given Username
func (*SQLStore) Insert ¶
Insert inserts the user into the database, and returns the newly-inserted User, complete with the DBMS-assigned ID
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 //Logs user Log(userid int64, dt time.Time, ip string) error }
Store represents a store for Users
type User ¶
type User struct { ID int64 `json:"id"` Email string `json:"-"` //never JSON encoded/decoded PassHash []byte `json:"-"` //never JSON encoded/decoded UserName string `json:"userName"` FirstName string `json:"firstName"` LastName string `json:"lastName"` PhotoURL string `json:"photoURL"` }
User represents a user account in the database
func (*User) ApplyUpdates ¶
ApplyUpdates applies the updates to the user. An error is returned if the updates are invalid
func (*User) Authenticate ¶
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) FullName ¶
FullName returns the user's full name, in the form: "<FirstName> <LastName>" If either first or last name is an empty string, no space is put between the names. If both are missing, this returns an empty string
func (*User) SetPassword ¶
SetPassword hashes the password and stores it in the PassHash field