Documentation
¶
Overview ¶
Package users handles interacting with users of the app.
Index ¶
- 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 DeleteLoginCookie(w http.ResponseWriter)
- func ForceLogout(w http.ResponseWriter, r *http.Request)
- func Get2FABarcode(w http.ResponseWriter, r *http.Request)
- func GetAll(w http.ResponseWriter, r *http.Request)
- func GetLoginCookieValue(r *http.Request) (cv string, err error)
- func GetOne(w http.ResponseWriter, r *http.Request)
- func GetUserDataByRequest(r *http.Request) (u db.User, err error)
- func GetUserIDByRequest(r *http.Request) (userID int64, err error)
- func GetUsernameByRequest(r *http.Request) (username 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 SetLoginCookieValue(w http.ResponseWriter, cv string, expiration time.Time)
- func Update(w http.ResponseWriter, r *http.Request)
- func Validate2FACode(w http.ResponseWriter, r *http.Request)
Constants ¶
This section is empty.
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 ¶ added in v2.1.0
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 DeleteLoginCookie ¶
func DeleteLoginCookie(w http.ResponseWriter)
DeleteLoginCookie removes a session cookie from a request/response by making it 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 GetAll ¶
func GetAll(w http.ResponseWriter, r *http.Request)
GetAll gets a list of all users optionally filtered by users that are active.
func GetLoginCookieValue ¶
GetLoginCookieValue looks up the cookie value set to identify this login. This is used to validate a user in middleware or elsewhere, or look up session to get user details or permissions. This is a unique value generated and saved when the user logged into the app.
func GetOne ¶ added in v2.1.0
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 GetUserDataByRequest ¶
GetUserDataByRequest returns the user's data based on the login cookie from the http request. This is a wrapper around GetLoginCookieValue + db.GetLoginByCookieValue + db.GetUserByID since this pattern is used frequently.
func GetUserIDByRequest ¶
GetUserIDByRequest returns the user's ID based on the login ID cookie from the http request.
func GetUsernameByRequest ¶
GetUsernameByRequest returns the user's username based on the login ID cookie from the http request.
func LatestLogins ¶ added in v2.1.0
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 SetLoginCookieValue ¶
func SetLoginCookieValue(w http.ResponseWriter, cv string, expiration time.Time)
SetLoginCookieValue saves the login identifier to a cookie. This is used to identify the user's session and user when needed in middleware or elsewhere in the app. The expiration timestamp of the cookie SHOULD match the expiration saved to the database although we only rely on the database value for validity. There is no need to encrypt the value stored in the cookie since it is just a random identifier with no other useful information.
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.