Skip to content

Commit c812ba7

Browse files
authored
fix display dashboard even if require to change password (#6214)
* fix display dashboard even if require to change password * fix comments
1 parent 48c101a commit c812ba7

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
@@ -7,6 +7,7 @@ package routers
77

88
import (
99
"bytes"
10+
"net/url"
1011
"strings"
1112

1213
"code.gitea.io/gitea/models"
@@ -44,6 +45,11 @@ func Home(ctx *context.Context) {
4445
log.Info("Failed authentication attempt for %s from %s", ctx.User.Name, ctx.RemoteAddr())
4546
ctx.Data["Title"] = ctx.Tr("auth.prohibit_login")
4647
ctx.HTML(200, "user/auth/prohibit_login")
48+
} else if ctx.User.MustChangePassword {
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")
4753
} else {
4854
user.Dashboard(ctx)
4955
}

0 commit comments

Comments
 (0)