Add login/register logic

Signed-off-by: gearnode <bryan@frimin.fr>
This commit is contained in:
gearnode
2025-02-25 17:32:26 +01:00
parent 49c3807b4f
commit e9ae77a4a0
28 changed files with 2075 additions and 419 deletions

View File

@@ -0,0 +1,35 @@
package console_v1
import (
"net/http"
)
// setSessionCookie sets a session cookie in the response
func setSessionCookie(w http.ResponseWriter, sessionID string, cfg AuthConfig) {
cookie := &http.Cookie{
Name: cfg.CookieName,
Value: sessionID,
Path: cfg.CookiePath,
Domain: cfg.CookieDomain,
Secure: cfg.CookieSecure,
HttpOnly: cfg.CookieHTTPOnly,
MaxAge: int(cfg.SessionDuration.Seconds()),
SameSite: http.SameSiteLaxMode,
}
http.SetCookie(w, cookie)
}
// clearSessionCookie clears the session cookie
func clearSessionCookie(w http.ResponseWriter, cfg AuthConfig) {
cookie := &http.Cookie{
Name: cfg.CookieName,
Value: "",
Path: cfg.CookiePath,
Domain: cfg.CookieDomain,
Secure: cfg.CookieSecure,
HttpOnly: cfg.CookieHTTPOnly,
MaxAge: -1,
SameSite: http.SameSiteLaxMode,
}
http.SetCookie(w, cookie)
}