From 3c438b0ee28f13f30e022adeb1d284eaf54432ae Mon Sep 17 00:00:00 2001 From: Jocadbz Date: Tue, 15 Apr 2025 21:22:15 -0300 Subject: [PATCH] Fix cookie banner --- handlers/about.go | 3 ++- handlers/board.go | 3 ++- handlers/boards.go | 3 ++- handlers/home.go | 2 +- handlers/news.go | 3 ++- handlers/signup.go | 5 +++-- handlers/thread.go | 3 ++- 7 files changed, 14 insertions(+), 8 deletions(-) diff --git a/handlers/about.go b/handlers/about.go index 52875d8..856761b 100644 --- a/handlers/about.go +++ b/handlers/about.go @@ -12,6 +12,7 @@ func AboutHandler(app *App) http.HandlerFunc { return func(w http.ResponseWriter, r *http.Request) { session := r.Context().Value("session").(*sessions.Session) loggedIn := session.Values["user_id"] != nil + cookie, _ := r.Cookie("threadr_cookie_banner") aboutContent, err := ioutil.ReadFile("config/about.template") if err != nil { @@ -28,7 +29,7 @@ func AboutHandler(app *App) http.HandlerFunc { Title: "ThreadR - About", Navbar: "about", LoggedIn: loggedIn, - ShowCookieBanner: true, + ShowCookieBanner: cookie == nil || cookie.Value != "accepted", BasePath: app.Config.ThreadrDir, StaticPath: app.Config.ThreadrDir + "/static", CurrentURL: r.URL.Path, diff --git a/handlers/board.go b/handlers/board.go index ee9c958..2fb8ce3 100644 --- a/handlers/board.go +++ b/handlers/board.go @@ -13,6 +13,7 @@ func BoardHandler(app *App) http.HandlerFunc { session := r.Context().Value("session").(*sessions.Session) loggedIn := session.Values["user_id"] != nil userID, _ := session.Values["user_id"].(int) + cookie, _ := r.Cookie("threadr_cookie_banner") boardIDStr := r.URL.Query().Get("id") boardID, err := strconv.Atoi(boardIDStr) @@ -110,7 +111,7 @@ func BoardHandler(app *App) http.HandlerFunc { Title: "ThreadR - " + board.Name, Navbar: "boards", LoggedIn: loggedIn, - ShowCookieBanner: true, + ShowCookieBanner: cookie == nil || cookie.Value != "accepted", BasePath: app.Config.ThreadrDir, StaticPath: app.Config.ThreadrDir + "/static", CurrentURL: r.URL.Path, diff --git a/handlers/boards.go b/handlers/boards.go index 78ac299..f6aaf34 100644 --- a/handlers/boards.go +++ b/handlers/boards.go @@ -12,6 +12,7 @@ func BoardsHandler(app *App) http.HandlerFunc { session := r.Context().Value("session").(*sessions.Session) loggedIn := session.Values["user_id"] != nil userID, _ := session.Values["user_id"].(int) + cookie, _ := r.Cookie("threadr_cookie_banner") publicBoards, err := models.GetAllBoards(app.DB, false) if err != nil { @@ -50,7 +51,7 @@ func BoardsHandler(app *App) http.HandlerFunc { Title: "ThreadR - Boards", Navbar: "boards", LoggedIn: loggedIn, - ShowCookieBanner: true, + ShowCookieBanner: cookie == nil || cookie.Value != "accepted", BasePath: app.Config.ThreadrDir, StaticPath: app.Config.ThreadrDir + "/static", CurrentURL: r.URL.Path, diff --git a/handlers/home.go b/handlers/home.go index a9c9714..0ddfcd3 100644 --- a/handlers/home.go +++ b/handlers/home.go @@ -19,7 +19,7 @@ func HomeHandler(app *App) http.HandlerFunc { Title: "ThreadR - Home", Navbar: "home", LoggedIn: loggedIn, - ShowCookieBanner: cookie == nil || cookie.Value == "", + ShowCookieBanner: cookie == nil || cookie.Value != "accepted", BasePath: app.Config.ThreadrDir, StaticPath: filepath.Join(app.Config.ThreadrDir, "static"), CurrentURL: r.URL.String(), diff --git a/handlers/news.go b/handlers/news.go index 8bf8699..32cc172 100644 --- a/handlers/news.go +++ b/handlers/news.go @@ -10,6 +10,7 @@ func NewsHandler(app *App) http.HandlerFunc { return func(w http.ResponseWriter, r *http.Request) { session := r.Context().Value("session").(*sessions.Session) loggedIn := session.Values["user_id"] != nil + cookie, _ := r.Cookie("threadr_cookie_banner") newsItems := []string{ "2020-02-21 Whole Website updated: Homepage, News, Boards, About, Log In, Userhome, Log Out", "2020-01-06 First Steps done", @@ -22,7 +23,7 @@ func NewsHandler(app *App) http.HandlerFunc { Title: "ThreadR - News", Navbar: "news", LoggedIn: loggedIn, - ShowCookieBanner: true, + ShowCookieBanner: cookie == nil || cookie.Value != "accepted", BasePath: app.Config.ThreadrDir, StaticPath: app.Config.ThreadrDir + "/static", CurrentURL: r.URL.Path, diff --git a/handlers/signup.go b/handlers/signup.go index bcb9980..5e52cf3 100644 --- a/handlers/signup.go +++ b/handlers/signup.go @@ -10,6 +10,7 @@ import ( func SignupHandler(app *App) http.HandlerFunc { return func(w http.ResponseWriter, r *http.Request) { session := r.Context().Value("session").(*sessions.Session) + cookie, _ := r.Cookie("threadr_cookie_banner") if r.Method == http.MethodPost { username := r.FormValue("username") password := r.FormValue("password") @@ -24,7 +25,7 @@ func SignupHandler(app *App) http.HandlerFunc { Title: "ThreadR - Sign Up", Navbar: "signup", LoggedIn: false, - ShowCookieBanner: true, + ShowCookieBanner: cookie == nil || cookie.Value != "accepted", BasePath: app.Config.ThreadrDir, StaticPath: app.Config.ThreadrDir + "/static", CurrentURL: r.URL.Path, @@ -49,7 +50,7 @@ func SignupHandler(app *App) http.HandlerFunc { Title: "ThreadR - Sign Up", Navbar: "signup", LoggedIn: session.Values["user_id"] != nil, - ShowCookieBanner: true, + ShowCookieBanner: cookie == nil || cookie.Value != "accepted", BasePath: app.Config.ThreadrDir, StaticPath: app.Config.ThreadrDir + "/static", CurrentURL: r.URL.Path, diff --git a/handlers/thread.go b/handlers/thread.go index 76bc122..8cfa1fa 100644 --- a/handlers/thread.go +++ b/handlers/thread.go @@ -13,6 +13,7 @@ func ThreadHandler(app *App) http.HandlerFunc { session := r.Context().Value("session").(*sessions.Session) loggedIn := session.Values["user_id"] != nil userID, _ := session.Values["user_id"].(int) + cookie, _ := r.Cookie("threadr_cookie_banner") threadIDStr := r.URL.Query().Get("id") threadID, err := strconv.Atoi(threadIDStr) @@ -123,7 +124,7 @@ func ThreadHandler(app *App) http.HandlerFunc { Title: "ThreadR - " + thread.Title, Navbar: "boards", LoggedIn: loggedIn, - ShowCookieBanner: true, + ShowCookieBanner: cookie == nil || cookie.Value != "accepted", BasePath: app.Config.ThreadrDir, StaticPath: app.Config.ThreadrDir + "/static", CurrentURL: r.URL.Path,