aboutsummaryrefslogtreecommitdiff
diff options
context:
space:
mode:
authorArthur Zamarin <arthurzam@gentoo.org>2024-07-08 22:04:35 +0300
committerArthur Zamarin <arthurzam@gentoo.org>2024-07-08 22:04:35 +0300
commitf0659106d611b12be14655c9533bee3766dfaca2 (patch)
tree1a65ca19a8cb211cb1d96a7d3b1034f79d1a1fdf
parentapp/preferences: remove general (diff)
downloadsoko-f0659106d611b12be14655c9533bee3766dfaca2.tar.gz
soko-f0659106d611b12be14655c9533bee3766dfaca2.tar.bz2
soko-f0659106d611b12be14655c9533bee3766dfaca2.zip
app/preferences: remove previously created cookies
Signed-off-by: Arthur Zamarin <arthurzam@gentoo.org>
-rw-r--r--pkg/app/handler/index/index.templ16
-rw-r--r--pkg/app/utils/userdata.go6
-rw-r--r--pkg/models/userpreferences.go1
3 files changed, 17 insertions, 6 deletions
diff --git a/pkg/app/handler/index/index.templ b/pkg/app/handler/index/index.templ
index 3da465b..14b380e 100644
--- a/pkg/app/handler/index/index.templ
+++ b/pkg/app/handler/index/index.templ
@@ -89,8 +89,24 @@ templ page(packageCount int) {
<script src="assets/index.js"></script>
}
+func deleteCookie(w http.ResponseWriter, r *http.Request, name string) {
+ if _, err := r.Cookie(name); err != http.ErrNoCookie {
+ cookie := http.Cookie{
+ Name: name,
+ Value: "",
+ Path: "/",
+ MaxAge: -1,
+ HttpOnly: true,
+ }
+ http.SetCookie(w, &cookie)
+ }
+}
+
// Show renders a template to show the landing page of the application
func Show(w http.ResponseWriter, r *http.Request) {
+ for _, cookie := range models.OldCookieNames {
+ deleteCookie(w, r, cookie)
+ }
count, _ := database.DBCon.Model((*models.Package)(nil)).Count()
layout.Layout("", layout.Home, page(count)).Render(r.Context(), w)
}
diff --git a/pkg/app/utils/userdata.go b/pkg/app/utils/userdata.go
index 13f9973..20624e0 100644
--- a/pkg/app/utils/userdata.go
+++ b/pkg/app/utils/userdata.go
@@ -22,11 +22,5 @@ func GetUserPreferences(r *http.Request) models.UserPreferences {
}
}
- // old cookie: search_history
- // old cookie: userpref_general
- // old cookie: userpref_packages
- // old cookie: userpref_useflags
- // old cookie: userpref_arches
-
return userPreferences
}
diff --git a/pkg/models/userpreferences.go b/pkg/models/userpreferences.go
index ed133c7..773b8eb 100644
--- a/pkg/models/userpreferences.go
+++ b/pkg/models/userpreferences.go
@@ -13,6 +13,7 @@ type MaintainersPreferences struct {
var ArchesToShow = [...]string{"amd64", "x86", "alpha", "arm", "arm64", "hppa", "ia64", "ppc", "ppc64", "riscv", "sparc"}
var AllArches = [...]string{"alpha", "amd64", "arm", "arm64", "hppa", "ia64", "mips", "ppc", "ppc64", "riscv", "s390", "sparc", "x86"}
+var OldCookieNames = [...]string{"search_history", "userpref_general", "userpref_packages", "userpref_useflags", "userpref_arches"}
func GetDefaultUserPreferences() UserPreferences {
userPreferences := UserPreferences{}