Skip to content

Commit 6a86a82

Browse files
authored
fix display dashboard even if require to change password (#6214) (#6215)
* fix display dashboard even if require to change password * fix comments
1 parent 8ab107c commit 6a86a82

File tree

2 files changed

+16
-14
lines changed

2 files changed

+16
-14
lines changed

modules/context/auth.go

Lines changed: 10 additions & 14 deletions
Original file line numberDiff line numberDiff line change
@@ -44,21 +44,17 @@ func Toggle(options *ToggleOptions) macaron.Handler {
4444
return
4545
}
4646

47-
// prevent infinite redirection
48-
// also make sure that the form cannot be accessed by
49-
// users who don't need this
50-
if ctx.Req.URL.Path == "/user/settings/change_password" {
51-
if !ctx.User.MustChangePassword {
52-
ctx.Redirect(setting.AppSubURL + "/")
53-
}
54-
return
55-
}
56-
5747
if ctx.User.MustChangePassword {
58-
ctx.Data["Title"] = ctx.Tr("auth.must_change_password")
59-
ctx.Data["ChangePasscodeLink"] = setting.AppSubURL + "/user/change_password"
60-
ctx.SetCookie("redirect_to", url.QueryEscape(setting.AppSubURL+ctx.Req.RequestURI), 0, setting.AppSubURL)
61-
ctx.Redirect(setting.AppSubURL + "/user/settings/change_password")
48+
if ctx.Req.URL.Path != "/user/settings/change_password" {
49+
ctx.Data["Title"] = ctx.Tr("auth.must_change_password")
50+
ctx.Data["ChangePasscodeLink"] = setting.AppSubURL + "/user/change_password"
51+
ctx.SetCookie("redirect_to", url.QueryEscape(setting.AppSubURL+ctx.Req.RequestURI), 0, setting.AppSubURL)
52+
ctx.Redirect(setting.AppSubURL + "/user/settings/change_password")
53+
return
54+
}
55+
} else if ctx.Req.URL.Path == "/user/settings/change_password" {
56+
// make sure that the form cannot be accessed by users who don't need this
57+
ctx.Redirect(setting.AppSubURL + "/")
6258
return
6359
}
6460
}

routers/home.go

Lines changed: 6 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -6,6 +6,7 @@ package routers
66

77
import (
88
"bytes"
9+
"net/url"
910
"strings"
1011

1112
"code.gitea.io/gitea/models"
@@ -43,6 +44,11 @@ func Home(ctx *context.Context) {
4344
log.Info("Failed authentication attempt for %s from %s", ctx.User.Name, ctx.RemoteAddr())
4445
ctx.Data["Title"] = ctx.Tr("auth.prohibit_login")
4546
ctx.HTML(200, "user/auth/prohibit_login")
47+
} else if ctx.User.MustChangePassword {
48+
ctx.Data["Title"] = ctx.Tr("auth.must_change_password")
49+
ctx.Data["ChangePasscodeLink"] = setting.AppSubURL + "/user/change_password"
50+
ctx.SetCookie("redirect_to", url.QueryEscape(setting.AppSubURL+ctx.Req.RequestURI), 0, setting.AppSubURL)
51+
ctx.Redirect(setting.AppSubURL + "/user/settings/change_password")
4652
} else {
4753
user.Dashboard(ctx)
4854
}

0 commit comments

Comments
 (0)