Better to check user.ID, to be sure not anon
Cette révision appartient à :
Parent
3d81f6081b
révision
354e7aaea0
2 fichiers modifiés avec 6 ajouts et 5 suppressions
|
@ -6,6 +6,7 @@ import (
|
||||||
|
|
||||||
"github.com/NyaaPantsu/nyaa/service/user"
|
"github.com/NyaaPantsu/nyaa/service/user"
|
||||||
"github.com/NyaaPantsu/nyaa/util/languages"
|
"github.com/NyaaPantsu/nyaa/util/languages"
|
||||||
|
"github.com/NyaaPantsu/nyaa/util/timeHelper"
|
||||||
"github.com/gorilla/mux"
|
"github.com/gorilla/mux"
|
||||||
)
|
)
|
||||||
|
|
||||||
|
@ -55,13 +56,13 @@ func ChangeLanguageHandler(w http.ResponseWriter, r *http.Request) {
|
||||||
}
|
}
|
||||||
|
|
||||||
// If logged in, update user language; if not, set cookie.
|
// If logged in, update user language; if not, set cookie.
|
||||||
user, err := userService.CurrentUser(r)
|
user, _ := userService.CurrentUser(r)
|
||||||
if err == nil {
|
if user.ID > 0 {
|
||||||
user.Language = lang
|
user.Language = lang
|
||||||
// I don't know if I should use this...
|
// I don't know if I should use this...
|
||||||
userService.UpdateUserCore(&user)
|
userService.UpdateUserCore(&user)
|
||||||
}
|
}
|
||||||
http.SetCookie(w, &http.Cookie{Name: "lang", Value: lang})
|
http.SetCookie(w, &http.Cookie{Name: "lang", Value: lang, Expires: timeHelper.FewDaysLater(365)})
|
||||||
|
|
||||||
url, _ := Router.Get("home").URL()
|
url, _ := Router.Get("home").URL()
|
||||||
http.Redirect(w, r, url.String(), http.StatusSeeOther)
|
http.Redirect(w, r, url.String(), http.StatusSeeOther)
|
||||||
|
|
|
@ -103,8 +103,8 @@ func GetDefaultTfunc() (i18n.TranslateFunc, error) {
|
||||||
|
|
||||||
func GetTfuncAndLanguageFromRequest(r *http.Request) (T i18n.TranslateFunc, Tlang *language.Language) {
|
func GetTfuncAndLanguageFromRequest(r *http.Request) (T i18n.TranslateFunc, Tlang *language.Language) {
|
||||||
userLanguage := ""
|
userLanguage := ""
|
||||||
user, err := getCurrentUser(r)
|
user, _ := getCurrentUser(r)
|
||||||
if err == nil {
|
if user.ID > 0 {
|
||||||
userLanguage = user.Language
|
userLanguage = user.Language
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
Référencer dans un nouveau ticket