users

package
v0.0.0-...-1518e3e Latest Latest
Warning

This package is not in the latest version of its module.

Go to latest
Published: Jul 8, 2022 License: MIT Imports: 21 Imported by: 0

Documentation

Overview

Package users handles interacting with users of the app.

This file handles enrolling a user in 2 Factor Authentication (TOTP) using a Google Authenticator type app.

Package users handles interacting with users of the app.

This file specifically deals with a user logging in or maintaining a logged in session.

Package users handles interacting with users of the app.

Index

Constants

This section is empty.

Variables

This section is empty.

Functions

func Add

func Add(w http.ResponseWriter, r *http.Request)

Add saves a new user.

func ChangePassword

func ChangePassword(w http.ResponseWriter, r *http.Request)

ChangePassword sets a new password for a user

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 can be embedded into an <img> tag using data attribute 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

func GetLoginCookieValue(r *http.Request) (cv string, err error)

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 GetUserDataByRequest

func GetUserDataByRequest(r *http.Request) (u db.User, err error)

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

func GetUserIDByRequest(r *http.Request) (userID int64, err error)

GetUserIDByRequest returns the user's ID based on the login ID cookie from the http request.

func GetUsernameByRequest

func GetUsernameByRequest(r *http.Request) (username string, err error)

GetUsernameByRequest returns the user's username based on the login ID cookie from the http request.

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

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 during the 2fa enrollment process to make sure the user scanned the QR Code right and codes are being generated correctly.

Types

This section is empty.

Jump to

Keyboard shortcuts

? : This menu
/ : Search site
f or F : Jump to
y or Y : Canonical URL