enhance(admin): show impersonation banner and keep password change with the user (#38924)

Follow-up to https://github.com/go-gitea/gitea/pull/38614

---------

Co-authored-by: wxiaoguang <wxiaoguang@gmail.com>
This commit is contained in:
bircni
2026-08-14 22:23:30 +08:00
committed by GitHub
co-authored by wxiaoguang
parent b6368965fb
commit dbe311197c
15 changed files with 73 additions and 22 deletions
+1 -1
View File
@@ -38,7 +38,7 @@ func Home(ctx *context.Context) {
log.Info("Failed authentication attempt for %s from %s", ctx.Doer.Name, ctx.RemoteAddr())
ctx.Data["Title"] = ctx.Tr("auth.prohibit_login")
ctx.HTML(http.StatusOK, "user/auth/prohibit_login")
} else if ctx.Doer.MustChangePassword {
} else if doerMustChangePassword(ctx) {
ctx.Data["Title"] = ctx.Tr("auth.must_change_password")
ctx.Data["ChangePasscodeLink"] = setting.AppSubURL + "/user/change_password"
middleware.SetRedirectToCookie(ctx.Resp, setting.AppSubURL+ctx.Req.URL.RequestURI())
+6 -1
View File
@@ -166,6 +166,11 @@ func newWebAuthMiddleware() *AuthMiddleware {
return webAuth
}
func doerMustChangePassword(ctx *context.Context) bool {
// an impersonating admin must not be forced to set the impersonated user's password
return ctx.Doer != nil && ctx.Doer.MustChangePassword && !ctx.DoerIsImpersonated()
}
// verifyAuthWithOptions checks authentication according to options
func verifyAuthWithOptions(options *common.VerifyOptions) func(ctx *context.Context) {
crossOriginProtection := http.NewCrossOriginProtection()
@@ -185,7 +190,7 @@ func verifyAuthWithOptions(options *common.VerifyOptions) func(ctx *context.Cont
return
}
if ctx.Doer.MustChangePassword {
if doerMustChangePassword(ctx) {
if ctx.Req.URL.Path != "/user/settings/change_password" {
if strings.HasPrefix(ctx.Req.UserAgent(), "git") {
ctx.HTTPError(http.StatusUnauthorized, ctx.Locale.TrString("auth.must_change_password"))