Albirew/nyaa-pantsu
Archivé
1
0
Bifurcation 0
Ce dépôt a été archivé le 2022-05-07. Vous pouvez voir ses fichiers ou le cloner, mais pas ouvrir de ticket ou de demandes d'ajout, ni soumettre de changements.
nyaa-pantsu/controllers/settings/settings.go
kilo 5a184bfb50 "Alternating Colors" option in settings (#1440)
* Non-bold torrent name when using alternating background colors

* Add alternating colors for g.css

* Add alternating colors for classic.css

* Add alternating colors for tomorreuw

* Update classic.css

* Add alternating colors to settings page

* Add alt-colors class to tbody if enabled

* Add GetAltColorsFromRequest() function to get AltColors cookie value

* Create AltColors variable for usage in listing

* Make settings handle altColors input

* Add AltColors in user struct

* Returned the wrong variable here

* Turn function return value into bool

* Condition checks variable like a bool

* ditto

* better color for g.css

* even better color

* better

* Last change for g.css

* Improvement for tomorrow

* Update classic.css

* add alt-colors class to upload preview

* Add alt-colors to user profile

* more vivid color for g

* Fix typo

* Remove browser outline for refine when clicked on

* remove browser outline

* Fix rules that didn't apply and category icon being way too small on user profile thanks to usage of percentage

* Remove show-xs class for search inputs

* Turn refine button back into position: absolute to pin at very bottom of refine

* Alternating colors for g's trusted, remake & aplus

* Update tomorrow.css

* attempt at fixing travis

* test (will have to rollback that change)

* rollback

* will have to rollback

* will have to rollback

* will have to rollback

* will have to rollback

* add AltColors variable to template test

* rollback

* rollback

* rollback

* rollback
2017-08-30 15:21:45 +10:00

81 lignes
3 Kio
Go

package settingsController
import (
"net/http"
"net/url"
"github.com/NyaaPantsu/nyaa/config"
"github.com/NyaaPantsu/nyaa/controllers/router"
"github.com/NyaaPantsu/nyaa/templates"
msg "github.com/NyaaPantsu/nyaa/utils/messages"
"github.com/NyaaPantsu/nyaa/utils/publicSettings"
"github.com/NyaaPantsu/nyaa/utils/timeHelper"
"github.com/gin-gonic/gin"
)
// SeePublicSettingsHandler : Controller to view the languages and themes
func SeePublicSettingsHandler(c *gin.Context) {
_, Tlang := publicSettings.GetTfuncAndLanguageFromRequest(c)
availableLanguages := publicSettings.GetAvailableLanguages()
languagesJSON := templates.LanguagesJSONResponse{Tlang.Tag, availableLanguages}
contentType := c.Request.Header.Get("Content-Type")
if contentType == "application/json" {
c.Header("Content-Type", "application/json")
c.JSON(http.StatusOK, languagesJSON)
} else {
templates.Form(c, "site/user/public/settings.jet.html", languagesJSON)
}
}
// ChangePublicSettingsHandler : Controller for changing the current language and theme
func ChangePublicSettingsHandler(c *gin.Context) {
theme := c.PostForm("theme")
lang := c.PostForm("language")
mascot := c.PostForm("mascot")
mascotURL := c.PostForm("mascot_url")
altColors := c.PostForm("altColors")
messages := msg.GetMessages(c)
availableLanguages := publicSettings.GetAvailableLanguages()
if !availableLanguages.Exist(lang) {
messages.AddErrorT("errors", "language_not_available")
}
// FIXME Are the settings actually sanitized?
// Limit the mascot URL, so base64-encoded images aren't valid
if len(mascotURL) > 256 {
messages.AddErrorT("errors", "mascot_url_too_long")
}
_, err := url.Parse(mascotURL)
if err != nil {
messages.AddErrorTf("errors", "mascor_url_parse_error", err.Error())
}
// If logged in, update user settings.
user := router.GetUser(c)
if user.ID > 0 {
user.Language = lang
user.Theme = theme
user.Mascot = mascot
user.MascotURL = mascotURL
user.AltColors = altColors
user.UpdateRaw()
}
// Set cookie with http and not gin for expires (maxage not supported in <IE8)
http.SetCookie(c.Writer, &http.Cookie{Name: "lang", Value: lang, Domain: getDomainName(), Path: "/", Expires: timeHelper.FewDaysLater(365)})
http.SetCookie(c.Writer, &http.Cookie{Name: "theme", Value: theme, Domain: getDomainName(), Path: "/", Expires: timeHelper.FewDaysLater(365)})
http.SetCookie(c.Writer, &http.Cookie{Name: "mascot", Value: mascot, Domain: getDomainName(), Path: "/", Expires: timeHelper.FewDaysLater(365)})
http.SetCookie(c.Writer, &http.Cookie{Name: "mascot_url", Value: mascotURL, Domain: getDomainName(), Path: "/", Expires: timeHelper.FewDaysLater(365)})
http.SetCookie(c.Writer, &http.Cookie{Name: "altColors", Value: altColors, Domain: getDomainName(), Path: "/", Expires: timeHelper.FewDaysLater(365)})
c.Redirect(http.StatusSeeOther, "/")
}
func getDomainName() string {
domain := config.Get().Cookies.DomainName
if config.Get().Environment == "DEVELOPMENT" {
domain = ""
}
return domain
}