Fix cookie banner

master
Joca 2025-04-15 21:22:15 -03:00
parent adf485bb46
commit 3c438b0ee2
Signed by: jocadbz
GPG Key ID: B1836DCE2F50BDF7
7 changed files with 14 additions and 8 deletions

View File

@ -12,6 +12,7 @@ func AboutHandler(app *App) http.HandlerFunc {
return func(w http.ResponseWriter, r *http.Request) { return func(w http.ResponseWriter, r *http.Request) {
session := r.Context().Value("session").(*sessions.Session) session := r.Context().Value("session").(*sessions.Session)
loggedIn := session.Values["user_id"] != nil loggedIn := session.Values["user_id"] != nil
cookie, _ := r.Cookie("threadr_cookie_banner")
aboutContent, err := ioutil.ReadFile("config/about.template") aboutContent, err := ioutil.ReadFile("config/about.template")
if err != nil { if err != nil {
@ -28,7 +29,7 @@ func AboutHandler(app *App) http.HandlerFunc {
Title: "ThreadR - About", Title: "ThreadR - About",
Navbar: "about", Navbar: "about",
LoggedIn: loggedIn, LoggedIn: loggedIn,
ShowCookieBanner: true, ShowCookieBanner: cookie == nil || cookie.Value != "accepted",
BasePath: app.Config.ThreadrDir, BasePath: app.Config.ThreadrDir,
StaticPath: app.Config.ThreadrDir + "/static", StaticPath: app.Config.ThreadrDir + "/static",
CurrentURL: r.URL.Path, CurrentURL: r.URL.Path,

View File

@ -13,6 +13,7 @@ func BoardHandler(app *App) http.HandlerFunc {
session := r.Context().Value("session").(*sessions.Session) session := r.Context().Value("session").(*sessions.Session)
loggedIn := session.Values["user_id"] != nil loggedIn := session.Values["user_id"] != nil
userID, _ := session.Values["user_id"].(int) userID, _ := session.Values["user_id"].(int)
cookie, _ := r.Cookie("threadr_cookie_banner")
boardIDStr := r.URL.Query().Get("id") boardIDStr := r.URL.Query().Get("id")
boardID, err := strconv.Atoi(boardIDStr) boardID, err := strconv.Atoi(boardIDStr)
@ -110,7 +111,7 @@ func BoardHandler(app *App) http.HandlerFunc {
Title: "ThreadR - " + board.Name, Title: "ThreadR - " + board.Name,
Navbar: "boards", Navbar: "boards",
LoggedIn: loggedIn, LoggedIn: loggedIn,
ShowCookieBanner: true, ShowCookieBanner: cookie == nil || cookie.Value != "accepted",
BasePath: app.Config.ThreadrDir, BasePath: app.Config.ThreadrDir,
StaticPath: app.Config.ThreadrDir + "/static", StaticPath: app.Config.ThreadrDir + "/static",
CurrentURL: r.URL.Path, CurrentURL: r.URL.Path,

View File

@ -12,6 +12,7 @@ func BoardsHandler(app *App) http.HandlerFunc {
session := r.Context().Value("session").(*sessions.Session) session := r.Context().Value("session").(*sessions.Session)
loggedIn := session.Values["user_id"] != nil loggedIn := session.Values["user_id"] != nil
userID, _ := session.Values["user_id"].(int) userID, _ := session.Values["user_id"].(int)
cookie, _ := r.Cookie("threadr_cookie_banner")
publicBoards, err := models.GetAllBoards(app.DB, false) publicBoards, err := models.GetAllBoards(app.DB, false)
if err != nil { if err != nil {
@ -50,7 +51,7 @@ func BoardsHandler(app *App) http.HandlerFunc {
Title: "ThreadR - Boards", Title: "ThreadR - Boards",
Navbar: "boards", Navbar: "boards",
LoggedIn: loggedIn, LoggedIn: loggedIn,
ShowCookieBanner: true, ShowCookieBanner: cookie == nil || cookie.Value != "accepted",
BasePath: app.Config.ThreadrDir, BasePath: app.Config.ThreadrDir,
StaticPath: app.Config.ThreadrDir + "/static", StaticPath: app.Config.ThreadrDir + "/static",
CurrentURL: r.URL.Path, CurrentURL: r.URL.Path,

View File

@ -19,7 +19,7 @@ func HomeHandler(app *App) http.HandlerFunc {
Title: "ThreadR - Home", Title: "ThreadR - Home",
Navbar: "home", Navbar: "home",
LoggedIn: loggedIn, LoggedIn: loggedIn,
ShowCookieBanner: cookie == nil || cookie.Value == "", ShowCookieBanner: cookie == nil || cookie.Value != "accepted",
BasePath: app.Config.ThreadrDir, BasePath: app.Config.ThreadrDir,
StaticPath: filepath.Join(app.Config.ThreadrDir, "static"), StaticPath: filepath.Join(app.Config.ThreadrDir, "static"),
CurrentURL: r.URL.String(), CurrentURL: r.URL.String(),

View File

@ -10,6 +10,7 @@ func NewsHandler(app *App) http.HandlerFunc {
return func(w http.ResponseWriter, r *http.Request) { return func(w http.ResponseWriter, r *http.Request) {
session := r.Context().Value("session").(*sessions.Session) session := r.Context().Value("session").(*sessions.Session)
loggedIn := session.Values["user_id"] != nil loggedIn := session.Values["user_id"] != nil
cookie, _ := r.Cookie("threadr_cookie_banner")
newsItems := []string{ newsItems := []string{
"2020-02-21 Whole Website updated: Homepage, News, Boards, About, Log In, Userhome, Log Out", "2020-02-21 Whole Website updated: Homepage, News, Boards, About, Log In, Userhome, Log Out",
"2020-01-06 First Steps done", "2020-01-06 First Steps done",
@ -22,7 +23,7 @@ func NewsHandler(app *App) http.HandlerFunc {
Title: "ThreadR - News", Title: "ThreadR - News",
Navbar: "news", Navbar: "news",
LoggedIn: loggedIn, LoggedIn: loggedIn,
ShowCookieBanner: true, ShowCookieBanner: cookie == nil || cookie.Value != "accepted",
BasePath: app.Config.ThreadrDir, BasePath: app.Config.ThreadrDir,
StaticPath: app.Config.ThreadrDir + "/static", StaticPath: app.Config.ThreadrDir + "/static",
CurrentURL: r.URL.Path, CurrentURL: r.URL.Path,

View File

@ -10,6 +10,7 @@ import (
func SignupHandler(app *App) http.HandlerFunc { func SignupHandler(app *App) http.HandlerFunc {
return func(w http.ResponseWriter, r *http.Request) { return func(w http.ResponseWriter, r *http.Request) {
session := r.Context().Value("session").(*sessions.Session) session := r.Context().Value("session").(*sessions.Session)
cookie, _ := r.Cookie("threadr_cookie_banner")
if r.Method == http.MethodPost { if r.Method == http.MethodPost {
username := r.FormValue("username") username := r.FormValue("username")
password := r.FormValue("password") password := r.FormValue("password")
@ -24,7 +25,7 @@ func SignupHandler(app *App) http.HandlerFunc {
Title: "ThreadR - Sign Up", Title: "ThreadR - Sign Up",
Navbar: "signup", Navbar: "signup",
LoggedIn: false, LoggedIn: false,
ShowCookieBanner: true, ShowCookieBanner: cookie == nil || cookie.Value != "accepted",
BasePath: app.Config.ThreadrDir, BasePath: app.Config.ThreadrDir,
StaticPath: app.Config.ThreadrDir + "/static", StaticPath: app.Config.ThreadrDir + "/static",
CurrentURL: r.URL.Path, CurrentURL: r.URL.Path,
@ -49,7 +50,7 @@ func SignupHandler(app *App) http.HandlerFunc {
Title: "ThreadR - Sign Up", Title: "ThreadR - Sign Up",
Navbar: "signup", Navbar: "signup",
LoggedIn: session.Values["user_id"] != nil, LoggedIn: session.Values["user_id"] != nil,
ShowCookieBanner: true, ShowCookieBanner: cookie == nil || cookie.Value != "accepted",
BasePath: app.Config.ThreadrDir, BasePath: app.Config.ThreadrDir,
StaticPath: app.Config.ThreadrDir + "/static", StaticPath: app.Config.ThreadrDir + "/static",
CurrentURL: r.URL.Path, CurrentURL: r.URL.Path,

View File

@ -13,6 +13,7 @@ func ThreadHandler(app *App) http.HandlerFunc {
session := r.Context().Value("session").(*sessions.Session) session := r.Context().Value("session").(*sessions.Session)
loggedIn := session.Values["user_id"] != nil loggedIn := session.Values["user_id"] != nil
userID, _ := session.Values["user_id"].(int) userID, _ := session.Values["user_id"].(int)
cookie, _ := r.Cookie("threadr_cookie_banner")
threadIDStr := r.URL.Query().Get("id") threadIDStr := r.URL.Query().Get("id")
threadID, err := strconv.Atoi(threadIDStr) threadID, err := strconv.Atoi(threadIDStr)
@ -123,7 +124,7 @@ func ThreadHandler(app *App) http.HandlerFunc {
Title: "ThreadR - " + thread.Title, Title: "ThreadR - " + thread.Title,
Navbar: "boards", Navbar: "boards",
LoggedIn: loggedIn, LoggedIn: loggedIn,
ShowCookieBanner: true, ShowCookieBanner: cookie == nil || cookie.Value != "accepted",
BasePath: app.Config.ThreadrDir, BasePath: app.Config.ThreadrDir,
StaticPath: app.Config.ThreadrDir + "/static", StaticPath: app.Config.ThreadrDir + "/static",
CurrentURL: r.URL.Path, CurrentURL: r.URL.Path,