Added documentation to functions and basic JWT generation

This commit is contained in:
2025-02-09 00:48:30 +11:00
parent 597fc6f072
commit 25868becf3
29 changed files with 254 additions and 58 deletions

View File

@@ -6,6 +6,7 @@ import (
"time"
)
// Check the value of "pagefrom" cookie, delete the cookie, and return the value
func CheckPageFrom(w http.ResponseWriter, r *http.Request) string {
pageFromCookie, err := r.Cookie("pagefrom")
if err != nil {
@@ -17,12 +18,17 @@ func CheckPageFrom(w http.ResponseWriter, r *http.Request) string {
return pageFrom
}
// Check the referer of the request, and if it matches the trustedHost, set
// the "pagefrom" cookie as the Path of the referer
func SetPageFrom(w http.ResponseWriter, r *http.Request, trustedHost string) {
referer := r.Referer()
parsedURL, err := url.Parse(referer)
if err != nil {
return
}
// NOTE: its possible this could cause an infinite redirect
// if that happens, will need to add a way to 'blacklist' certain paths
// from being set here
var pageFrom string
if parsedURL.Path == "" || parsedURL.Host != trustedHost {
pageFrom = "/"