aboutsummaryrefslogtreecommitdiffstats
diff options
context:
space:
mode:
authorzeripath <art27@cantab.net>2021-11-20 21:32:37 +0000
committerGitHub <noreply@github.com>2021-11-20 21:32:37 +0000
commit0fa41b6dc412ad7bea97099981b6508d36cc811e (patch)
tree2302d5757c920dd6ad959a8c7fb7fdbdbbea6e73
parentf8ec43dbc7ca10e456ddf0cf739d2f5035dea879 (diff)
downloadgitea-0fa41b6dc412ad7bea97099981b6508d36cc811e.tar.gz
gitea-0fa41b6dc412ad7bea97099981b6508d36cc811e.zip
Reset locale on login (#17734)
When logging in reset the user's locale to ensure that it matches their preferred locale. Fix #15612 Signed-off-by: Andrew Thornton <art27@cantab.net>
-rw-r--r--modules/context/api.go3
-rw-r--r--modules/context/context.go3
-rw-r--r--routers/web/user/auth.go4
3 files changed, 10 insertions, 0 deletions
diff --git a/modules/context/api.go b/modules/context/api.go
index 07ceeeea15..4a2d5d1665 100644
--- a/modules/context/api.go
+++ b/modules/context/api.go
@@ -245,6 +245,9 @@ func APIAuth(authMethod auth.Method) func(*APIContext) {
// Get user from session if logged in.
ctx.User = authMethod.Verify(ctx.Req, ctx.Resp, ctx, ctx.Session)
if ctx.User != nil {
+ if ctx.Locale.Language() != ctx.User.Language {
+ ctx.Locale = middleware.Locale(ctx.Resp, ctx.Req)
+ }
ctx.IsBasicAuth = ctx.Data["AuthedMethod"].(string) == auth.BasicMethodName
ctx.IsSigned = true
ctx.Data["IsSigned"] = ctx.IsSigned
diff --git a/modules/context/context.go b/modules/context/context.go
index 1ea53c7d3b..6fc4c7261a 100644
--- a/modules/context/context.go
+++ b/modules/context/context.go
@@ -614,6 +614,9 @@ func Auth(authMethod auth.Method) func(*Context) {
return func(ctx *Context) {
ctx.User = authMethod.Verify(ctx.Req, ctx.Resp, ctx, ctx.Session)
if ctx.User != nil {
+ if ctx.Locale.Language() != ctx.User.Language {
+ ctx.Locale = middleware.Locale(ctx.Resp, ctx.Req)
+ }
ctx.IsBasicAuth = ctx.Data["AuthedMethod"].(string) == auth.BasicMethodName
ctx.IsSigned = true
ctx.Data["IsSigned"] = ctx.IsSigned
diff --git a/routers/web/user/auth.go b/routers/web/user/auth.go
index ba37c8e3ed..1b1c70c8fe 100644
--- a/routers/web/user/auth.go
+++ b/routers/web/user/auth.go
@@ -572,6 +572,10 @@ func handleSignInFull(ctx *context.Context, u *models.User, remember bool, obeyR
middleware.SetLocaleCookie(ctx.Resp, u.Language, 0)
+ if ctx.Locale.Language() != u.Language {
+ ctx.Locale = middleware.Locale(ctx.Resp, ctx.Req)
+ }
+
// Clear whatever CSRF has right now, force to generate a new one
middleware.DeleteCSRFCookie(ctx.Resp)