Documentation ¶
Index ¶
- Variables
- type Credentials
- type MySQLStore
- func (ms *MySQLStore) Delete(id int64) error
- func (ms *MySQLStore) GetByEmail(email string) (*User, error)
- func (ms *MySQLStore) GetByID(id int64) (*User, error)
- func (ms *MySQLStore) GetByUserName(username string) (*User, error)
- func (ms *MySQLStore) Insert(user *User) (*User, error)
- func (ms *MySQLStore) LogUser(id int64, time time.Time, clientIP string) error
- func (ms *MySQLStore) Update(id int64, updates *Updates) (*User, error)
- type NewUser
- type Store
- type TestUserStore
- func (client *TestUserStore) Delete(id int64) error
- func (client *TestUserStore) GetByEmail(email string) (*User, error)
- func (client *TestUserStore) GetByID(id int64) (*User, error)
- func (client *TestUserStore) GetByUserName(username string) (*User, error)
- func (client *TestUserStore) Insert(user *User) (*User, error)
- func (client *TestUserStore) LogUser(id int64, time time.Time, clientIP string) error
- func (client *TestUserStore) Update(id int64, updates *Updates) (*User, error)
- 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 MySQLStore ¶
MySQLStore represents a users.Store backed by MySQL.
func NewMySQLStore ¶
func NewMySQLStore(client *sql.DB) *MySQLStore
NewMySQLStore constructs a new MySQLStore
func (*MySQLStore) Delete ¶
func (ms *MySQLStore) Delete(id int64) error
Delete deletes the user with the given ID
func (*MySQLStore) GetByEmail ¶
func (ms *MySQLStore) GetByEmail(email string) (*User, error)
GetByEmail returns the User with the given email
func (*MySQLStore) GetByID ¶
func (ms *MySQLStore) GetByID(id int64) (*User, error)
GetByID returns the User with the given ID
func (*MySQLStore) GetByUserName ¶
func (ms *MySQLStore) GetByUserName(username string) (*User, error)
GetByUserName returns the User with the given Username
func (*MySQLStore) Insert ¶
func (ms *MySQLStore) Insert(user *User) (*User, error)
Insert inserts the user into the database, and returns the newly-inserted User, complete with the DBMS-assigned ID
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 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 // LogUser logs a successful sign-in by a user with the user ID, curent time, // and user IP address LogUser(id int64, time time.Time, clientIP string) error }
Store represents a store for Users
type TestUserStore ¶
type TestUserStore struct {
Client string
}
TestUserStore represents a UserStore with mock data
func NewTestUserStore ¶
func NewTestUserStore(client string) *TestUserStore
NewTestUserStore creates a NewTestUserStore
func (*TestUserStore) Delete ¶
func (client *TestUserStore) Delete(id int64) error
Delete deletes the user with the given ID
func (*TestUserStore) GetByEmail ¶
func (client *TestUserStore) GetByEmail(email string) (*User, error)
GetByEmail returns the User with the given email
func (*TestUserStore) GetByID ¶
func (client *TestUserStore) GetByID(id int64) (*User, error)
GetByID returns the User with the given ID
func (*TestUserStore) GetByUserName ¶
func (client *TestUserStore) GetByUserName(username string) (*User, error)
GetByUserName returns the User with the given Username
func (*TestUserStore) Insert ¶
func (client *TestUserStore) Insert(user *User) (*User, error)
Insert inserts the user into the database, and returns the newly-inserted User, complete with the DBMS-assigned ID
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