Skip to content

Commit d25ff0d

Browse files
authored
Reset locale on login (#17734) (#18100)
Backport #17734 When logging in reset the user's locale to ensure that it matches their preferred locale. Fix #15612 Signed-off-by: Andrew Thornton <[email protected]>
1 parent 6eaebda commit d25ff0d

File tree

3 files changed

+10
-0
lines changed

3 files changed

+10
-0
lines changed

modules/context/api.go

Lines changed: 3 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -223,6 +223,9 @@ func APIAuth(authMethod auth.Auth) func(*APIContext) {
223223
// Get user from session if logged in.
224224
ctx.User = authMethod.Verify(ctx.Req, ctx.Resp, ctx, ctx.Session)
225225
if ctx.User != nil {
226+
if ctx.Locale.Language() != ctx.User.Language {
227+
ctx.Locale = middleware.Locale(ctx.Resp, ctx.Req)
228+
}
226229
ctx.IsBasicAuth = ctx.Data["AuthedMethod"].(string) == new(auth.Basic).Name()
227230
ctx.IsSigned = true
228231
ctx.Data["IsSigned"] = ctx.IsSigned

modules/context/context.go

Lines changed: 3 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -642,6 +642,9 @@ func Auth(authMethod auth.Auth) func(*Context) {
642642
return func(ctx *Context) {
643643
ctx.User = authMethod.Verify(ctx.Req, ctx.Resp, ctx, ctx.Session)
644644
if ctx.User != nil {
645+
if ctx.Locale.Language() != ctx.User.Language {
646+
ctx.Locale = middleware.Locale(ctx.Resp, ctx.Req)
647+
}
645648
ctx.IsBasicAuth = ctx.Data["AuthedMethod"].(string) == new(auth.Basic).Name()
646649
ctx.IsSigned = true
647650
ctx.Data["IsSigned"] = ctx.IsSigned

routers/web/user/auth.go

Lines changed: 4 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -584,6 +584,10 @@ func handleSignInFull(ctx *context.Context, u *models.User, remember bool, obeyR
584584

585585
middleware.SetLocaleCookie(ctx.Resp, u.Language, 0)
586586

587+
if ctx.Locale.Language() != u.Language {
588+
ctx.Locale = middleware.Locale(ctx.Resp, ctx.Req)
589+
}
590+
587591
// Clear whatever CSRF has right now, force to generate a new one
588592
middleware.DeleteCSRFCookie(ctx.Resp)
589593

0 commit comments

Comments
 (0)