Fix theme toggle not working for logged-in users (#1390)
* Update user theme too in themeToggle.go * Forgot a "
Cette révision appartient à :
Parent
c6168be8b1
révision
36b3920ef4
1 fichiers modifiés avec 9 ajouts et 1 suppressions
|
@ -4,6 +4,7 @@ import (
|
||||||
"net/http"
|
"net/http"
|
||||||
|
|
||||||
"github.com/NyaaPantsu/nyaa/config"
|
"github.com/NyaaPantsu/nyaa/config"
|
||||||
|
"github.com/NyaaPantsu/nyaa/controllers/router"
|
||||||
"github.com/NyaaPantsu/nyaa/utils/timeHelper"
|
"github.com/NyaaPantsu/nyaa/utils/timeHelper"
|
||||||
"github.com/gin-gonic/gin"
|
"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
|
//Get theme1 & theme2 value, set g.css & tomorrow.css by default
|
||||||
//Also check if both theme are identical which can happen at time
|
//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
|
//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: "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)})
|
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")
|
c.Redirect(http.StatusSeeOther, c.Param("redirect") + "#footer")
|
||||||
return
|
return
|
||||||
}
|
}
|
||||||
|
|
Référencer dans un nouveau ticket