Documentation
¶
Overview ¶
Package users handles interacting with users of the app.
Index ¶
- Constants
- func Add(w http.ResponseWriter, r *http.Request)
- func ChangePassword(w http.ResponseWriter, r *http.Request)
- func ClearLoginHistory(w http.ResponseWriter, r *http.Request)
- func Deactivate2FA(w http.ResponseWriter, r *http.Request)
- func Delete2FABrowserIDCookie(w http.ResponseWriter)
- func DeleteSessionIDCookie(w http.ResponseWriter)
- func ForceLogout(w http.ResponseWriter, r *http.Request)
- func Get2FABarcode(w http.ResponseWriter, r *http.Request)
- func Get2FABrowserIDFromCookie(r *http.Request) (browserID string, err error)
- func GetAll(w http.ResponseWriter, r *http.Request)
- func GetOne(w http.ResponseWriter, r *http.Request)
- func GetUserDataFromRequest(r *http.Request) (u db.User, err error)
- func GetUserIDFromRequest(r *http.Request) (userID int64, err error)
- func GetUserSessionIDFromCookie(r *http.Request) (sessionID string, err error)
- func LatestLogins(w http.ResponseWriter, r *http.Request)
- func Login(w http.ResponseWriter, r *http.Request)
- func Logout(w http.ResponseWriter, r *http.Request)
- func Set2FABrowserIDCookie(w http.ResponseWriter, browserID string, expiration time.Time) (err error)
- func SetUserSessionIDCookie(w http.ResponseWriter, sessionID string, expiration time.Time) (err error)
- func Update(w http.ResponseWriter, r *http.Request)
- func Validate2FACode(w http.ResponseWriter, r *http.Request)
Constants ¶
const UserIDContextKey userIDContextKeyType = "user-id"
UserIDContextKey is the name of the key that stores a user's ID in the request context. This is used to save the user ID in middleware-authentication.go and is used to get the user ID via context.Value() (or via a helper function below).
Variables ¶
This section is empty.
Functions ¶
func ChangePassword ¶
func ChangePassword(w http.ResponseWriter, r *http.Request)
ChangePassword sets a new password for a user
func ClearLoginHistory ¶
func ClearLoginHistory(w http.ResponseWriter, r *http.Request)
ClearLoginHistory deletes rows in the user logins table before a certain date. This is only done from the admin tools page and is done to clean up the database since the user login history table can get very big if you have a lot of users and/or a short session timeout.
This also clears the user authorized browsers table up to the same data since this is tightly related to user logins. This is just easier then making an admin clear both tables separately.
The user provides a starting date to delete from, this way you can delete very old activity log rows but keep newer history.
func Deactivate2FA ¶
func Deactivate2FA(w http.ResponseWriter, r *http.Request)
Deactivate2FA turns 2FA off for a user.
func Delete2FABrowserIDCookie ¶
func Delete2FABrowserIDCookie(w http.ResponseWriter)
Delete2FABrowserIDCookie removes a browser ID cookie from a request/response by marking it as expired.
func DeleteSessionIDCookie ¶
func DeleteSessionIDCookie(w http.ResponseWriter)
DeleteSessionIDCookie removes a session ID cookie from a request/response by marking it as expired.
func ForceLogout ¶
func ForceLogout(w http.ResponseWriter, r *http.Request)
ForceLogout handles requests to force a user to log out of the app. This invalidates all non-expired, active user logins causing all subsequent requests (page views or api requests) to fail.
func Get2FABarcode ¶
func Get2FABarcode(w http.ResponseWriter, r *http.Request)
Get2FABarcode generates a QR code for enrolling a user in 2FA. This returns the QR code as a base64 string that will be embedded into an <img> tag using "data:" type in src. This only returns a QR code if user is not currently enrolled in 2FA.
func Get2FABrowserIDFromCookie ¶
Get2FABrowserIDFromCookie retrieves the browser ID from a cookie.
This is used whenever a user is logging in to check if the user provided their 2FA token recently.
func GetAll ¶
func GetAll(w http.ResponseWriter, r *http.Request)
GetAll gets a list of all users optionally filtered by users that are active.
func GetOne ¶
func GetOne(w http.ResponseWriter, r *http.Request)
GetOne gets user data for a single user. If no user ID is provided, the data is returned for the currently logged in user. This was added to support the user profile page.
func GetUserDataFromRequest ¶
GetUserDataFromRequest returns the user's data based on the login cookie from the http request.
func GetUserIDFromRequest ¶
GetUserIDFromRequest returns the user's ID based on the login ID cookie from the http request.
func GetUserSessionIDFromCookie ¶
GetUserSessionIDFromCookie retrieves the user session ID from a cookie.
This is used whenever user authorization in the app is needed, specifically in middleware to validate that a user session is currently active.
func LatestLogins ¶
func LatestLogins(w http.ResponseWriter, r *http.Request)
LatestLogins retrieves the list of the latest user logins.
func Login ¶
func Login(w http.ResponseWriter, r *http.Request)
Login handles authentication a user logging in to the app. This handles password login and 2fa login.
func Logout ¶
func Logout(w http.ResponseWriter, r *http.Request)
Logout handles logging a user out. Remove the session info so users isn't automatically logged back in to the app. Remove the 2FA token if config requires 2FA upon each login.
func Set2FABrowserIDCookie ¶
func Set2FABrowserIDCookie(w http.ResponseWriter, browserID string, expiration time.Time) (err error)
Set2FABrowserIDCookie saves the browser identifier to a cookie.
This is used when a user is logging in to check if the user provided a 2FA token recently and therefore prevent users from having to provide their 2FA token overly- frequently.
func SetUserSessionIDCookie ¶
func SetUserSessionIDCookie(w http.ResponseWriter, sessionID string, expiration time.Time) (err error)
SetUserSessionIDCookie saves the user session identifier to a cookie.
This is used when a user is logging in, when extending a user's session (see middleware, and indirectly when logging a user out by marking the cookie as expired).
This cookie identifies a user's session and is used to keep the user logged in. The identifier in this cookie references the user session saved to our database. The expiration should match the value saved to the database.
func Update ¶
func Update(w http.ResponseWriter, r *http.Request)
Update saves changes to a user. This does not handle password changes nor 2 Factor Auth stuff since those actions are bit more specialized.
func Validate2FACode ¶
func Validate2FACode(w http.ResponseWriter, r *http.Request)
Validate2FACode takes the 6 character 1-time code provided by a user and checks if it is valid given the 2FA info we have saved for the user. This is used to make sure that enrollment in 2FA is successful.
Types ¶
This section is empty.
Directories
¶
| Path | Synopsis |
|---|---|
|
Package cookieutils handles setting and getting cookies.
|
Package cookieutils handles setting and getting cookies. |
|
Package pwds implements functionality for creating a secure hash of a password and for verifying a password matches a stored hash.
|
Package pwds implements functionality for creating a secure hash of a password and for verifying a password matches a stored hash. |