fix user setting expiring immediately
This commit is contained in:
parent
238bad7dca
commit
ad0f68d705
1 changed files with 6 additions and 0 deletions
|
@ -3,6 +3,7 @@ package main
|
||||||
import (
|
import (
|
||||||
"html/template"
|
"html/template"
|
||||||
"net/http"
|
"net/http"
|
||||||
|
"time"
|
||||||
)
|
)
|
||||||
|
|
||||||
type UserSettings struct {
|
type UserSettings struct {
|
||||||
|
@ -39,10 +40,13 @@ func loadUserSettings(r *http.Request) UserSettings {
|
||||||
}
|
}
|
||||||
|
|
||||||
func saveUserSettings(w http.ResponseWriter, settings UserSettings) {
|
func saveUserSettings(w http.ResponseWriter, settings UserSettings) {
|
||||||
|
expiration := time.Now().Add(90 * 24 * time.Hour) // 90 days from now
|
||||||
|
|
||||||
http.SetCookie(w, &http.Cookie{
|
http.SetCookie(w, &http.Cookie{
|
||||||
Name: "theme",
|
Name: "theme",
|
||||||
Value: settings.Theme,
|
Value: settings.Theme,
|
||||||
Path: "/",
|
Path: "/",
|
||||||
|
Expires: expiration, // Expiration time needs to be set otherwise it will expire immediately
|
||||||
Secure: true, // Ensure cookie is sent over HTTPS only
|
Secure: true, // Ensure cookie is sent over HTTPS only
|
||||||
SameSite: http.SameSiteNoneMode, // Set SameSite to None
|
SameSite: http.SameSiteNoneMode, // Set SameSite to None
|
||||||
})
|
})
|
||||||
|
@ -50,6 +54,7 @@ func saveUserSettings(w http.ResponseWriter, settings UserSettings) {
|
||||||
Name: "language",
|
Name: "language",
|
||||||
Value: settings.Language,
|
Value: settings.Language,
|
||||||
Path: "/",
|
Path: "/",
|
||||||
|
Expires: expiration,
|
||||||
Secure: true, // Ensure cookie is sent over HTTPS only
|
Secure: true, // Ensure cookie is sent over HTTPS only
|
||||||
SameSite: http.SameSiteNoneMode, // Set SameSite to None
|
SameSite: http.SameSiteNoneMode, // Set SameSite to None
|
||||||
})
|
})
|
||||||
|
@ -57,6 +62,7 @@ func saveUserSettings(w http.ResponseWriter, settings UserSettings) {
|
||||||
Name: "safe",
|
Name: "safe",
|
||||||
Value: settings.SafeSearch,
|
Value: settings.SafeSearch,
|
||||||
Path: "/",
|
Path: "/",
|
||||||
|
Expires: expiration,
|
||||||
Secure: true, // Ensure cookie is sent over HTTPS only
|
Secure: true, // Ensure cookie is sent over HTTPS only
|
||||||
SameSite: http.SameSiteNoneMode, // Set SameSite to None
|
SameSite: http.SameSiteNoneMode, // Set SameSite to None
|
||||||
})
|
})
|
||||||
|
|
Loading…
Add table
Reference in a new issue