From 36b3920ef49a32cebe2f82bac09a59e6061e30de Mon Sep 17 00:00:00 2001 From: kilo Date: Wed, 23 Aug 2017 00:25:40 +0200 Subject: [PATCH] Fix theme toggle not working for logged-in users (#1390) * Update user theme too in themeToggle.go * Forgot a " --- controllers/themeToggle/themeToggle.go | 10 +++++++++- 1 file changed, 9 insertions(+), 1 deletion(-) diff --git a/controllers/themeToggle/themeToggle.go b/controllers/themeToggle/themeToggle.go index a154d9a2..5079d833 100644 --- a/controllers/themeToggle/themeToggle.go +++ b/controllers/themeToggle/themeToggle.go @@ -4,6 +4,7 @@ import ( "net/http" "github.com/NyaaPantsu/nyaa/config" + "github.com/NyaaPantsu/nyaa/controllers/router" "github.com/NyaaPantsu/nyaa/utils/timeHelper" "github.com/gin-gonic/gin" @@ -31,11 +32,18 @@ func toggleThemeHandler(c *gin.Context) { //Get theme1 & theme2 value, set g.css & tomorrow.css by default //Also check if both theme are identical which can happen at time + // If logged in, update user theme (will not work otherwise) + user := router.GetUser(c) + if user.ID > 0 { + user.Theme = theme2 + user.UpdateRaw() + } + //Switch theme & theme2 value http.SetCookie(c.Writer, &http.Cookie{Name: "theme", Value: theme2, Domain: getDomainName(), Path: "/", Expires: timeHelper.FewDaysLater(365)}) http.SetCookie(c.Writer, &http.Cookie{Name: "theme2", Value: theme, Domain: getDomainName(), Path: "/", Expires: timeHelper.FewDaysLater(365)}) - //Redirect user to page he was beforehand + //Redirect user to page he was in beforehand c.Redirect(http.StatusSeeOther, c.Param("redirect") + "#footer") return }