Documentation
¶
Overview ¶
Handles the user account page
Libuser contains functionality for user management ¶
Handles the login functionality for users.
Handles the user loggout functionality ¶
Handles the registration functionality for users ¶
Handles the password reset functionality for users ¶
Contains various utility functions ¶
Handles the verification of email address for users.
Index ¶
Constants ¶
This section is empty.
Variables ¶
This section is empty.
Functions ¶
func HandleError ¶
func HandleError(w http.ResponseWriter, err error)
func VerifyEmail ¶
Types ¶
type Registration ¶
type User ¶
type User struct {
UUID string `db:"uid"`
Username string
Email string
// @TODO: Ensure this is never sent in a response.
Password []byte `json:"-"`
Verified bool
Enabled bool
Created time.Time
Updated time.Time
LastLogin time.Time `db:"last_login"`
}
Define user type
type UserAccount ¶
type UserAccount struct {
Storage UserStorage
TemplateConfig libtmpl.HTMLTemplateConfig
//@TODO: Should just pass in a session instead of the session store.
SessionStore sessions.Store
}
func (UserAccount) AccountPage ¶
func (ua UserAccount) AccountPage(w http.ResponseWriter, r *http.Request, _ httprouter.Params)
type UserLogin ¶
type UserLogin struct {
Storage UserStorage
TemplateConfig libtmpl.HTMLTemplateConfig
//@TODO: Should just pass in a session instead of the session store.
SessionStore sessions.Store
}
Login functionality. Should handle checking the user's username and password. Should be able to easily take a username or email address to improve the user experience.
func (UserLogin) HandleError ¶
func (ul UserLogin) HandleError(w http.ResponseWriter, err error)
func (UserLogin) LoginForm ¶
func (ul UserLogin) LoginForm(w http.ResponseWriter, r *http.Request, _ httprouter.Params)
func (UserLogin) LoginSubmission ¶
func (ul UserLogin) LoginSubmission(w http.ResponseWriter, r *http.Request, _ httprouter.Params)
type UserLogout ¶
type UserLogout struct {
Storage UserStorage
TemplateConfig libtmpl.HTMLTemplateConfig
//@TODO: Should just pass in a session instead of the session store.
SessionStore sessions.Store
}
func (UserLogout) Logout ¶
func (ul UserLogout) Logout(w http.ResponseWriter, r *http.Request, _ httprouter.Params)
type UserRegistration ¶
type UserRegistration struct {
Storage UserStorage
TemplateConfig libtmpl.HTMLTemplateConfig
//@TODO: Should just pass in a session instead of the session store.
SessionStore sessions.Store
}
Registration should be simple as we are only collecting a user's username, email address, and password. We should ensure the uniqueness checks (for username and email) are fast.
func (UserRegistration) GetRegistrationForm ¶
func (ur UserRegistration) GetRegistrationForm(w http.ResponseWriter, r *http.Request, _ httprouter.Params)
func (UserRegistration) HandleError ¶
func (ur UserRegistration) HandleError(w http.ResponseWriter, err error)
func (UserRegistration) HandleRegistrationSubmission ¶
func (ur UserRegistration) HandleRegistrationSubmission(w http.ResponseWriter, r *http.Request, _ httprouter.Params)
type UserStorage ¶
type UserStorage interface {
// Retrieve a user.
// @TODO: Potentially use a paratially filled in user object to retrieve the
// full user object. This would allow retrieval via usernam, email, or UUID
RetrieveUser(username string) (User, error)
CreateUser(user User) (bool, error)
UpdateUser(user User) (bool, error)
DeleteUser(user User) (bool, error)
// Checks if the username has already been used
// Returns true if it has and false if it hasn't
CheckUsername(username string) (bool, error)
// Checks if the email address has already been used
// Returns true if it has and false if it hasn't
CheckEmail(email string) (bool, error)
CheckPassword(username, password string) (bool, error)
}
Click to show internal directories.
Click to hide internal directories.