Albirew/nyaa-pantsu
Archivé
1
0
Bifurcation 0

Better to check user.ID, to be sure not anon

Cette révision appartient à :
akuma06 2017-05-21 02:12:29 +02:00
Parent 3d81f6081b
révision 354e7aaea0
2 fichiers modifiés avec 6 ajouts et 5 suppressions

Voir le fichier

@ -6,6 +6,7 @@ import (
"github.com/NyaaPantsu/nyaa/service/user"
"github.com/NyaaPantsu/nyaa/util/languages"
"github.com/NyaaPantsu/nyaa/util/timeHelper"
"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.
user, err := userService.CurrentUser(r)
if err == nil {
user, _ := userService.CurrentUser(r)
if user.ID > 0 {
user.Language = lang
// I don't know if I should use this...
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()
http.Redirect(w, r, url.String(), http.StatusSeeOther)

Voir le fichier

@ -103,8 +103,8 @@ func GetDefaultTfunc() (i18n.TranslateFunc, error) {
func GetTfuncAndLanguageFromRequest(r *http.Request) (T i18n.TranslateFunc, Tlang *language.Language) {
userLanguage := ""
user, err := getCurrentUser(r)
if err == nil {
user, _ := getCurrentUser(r)
if user.ID > 0 {
userLanguage = user.Language
}