Skip to content

Commit

Permalink
fix display dashboard even if require to change password (#6214)
Browse files Browse the repository at this point in the history
* fix display dashboard even if require to change password

* fix comments
  • Loading branch information
lunny authored Feb 28, 2019
1 parent 48c101a commit c812ba7
Show file tree
Hide file tree
Showing 2 changed files with 16 additions and 14 deletions.
24 changes: 10 additions & 14 deletions modules/context/auth.go
Original file line number Diff line number Diff line change
Expand Up @@ -44,21 +44,17 @@ func Toggle(options *ToggleOptions) macaron.Handler {
return
}

// prevent infinite redirection
// also make sure that the form cannot be accessed by
// users who don't need this
if ctx.Req.URL.Path == "/user/settings/change_password" {
if !ctx.User.MustChangePassword {
ctx.Redirect(setting.AppSubURL + "/")
}
return
}

if ctx.User.MustChangePassword {
ctx.Data["Title"] = ctx.Tr("auth.must_change_password")
ctx.Data["ChangePasscodeLink"] = setting.AppSubURL + "/user/change_password"
ctx.SetCookie("redirect_to", url.QueryEscape(setting.AppSubURL+ctx.Req.RequestURI), 0, setting.AppSubURL)
ctx.Redirect(setting.AppSubURL + "/user/settings/change_password")
if ctx.Req.URL.Path != "/user/settings/change_password" {
ctx.Data["Title"] = ctx.Tr("auth.must_change_password")
ctx.Data["ChangePasscodeLink"] = setting.AppSubURL + "/user/change_password"
ctx.SetCookie("redirect_to", url.QueryEscape(setting.AppSubURL+ctx.Req.RequestURI), 0, setting.AppSubURL)
ctx.Redirect(setting.AppSubURL + "/user/settings/change_password")
return
}
} else if ctx.Req.URL.Path == "/user/settings/change_password" {
// make sure that the form cannot be accessed by users who don't need this
ctx.Redirect(setting.AppSubURL + "/")
return
}
}
Expand Down
6 changes: 6 additions & 0 deletions routers/home.go
Original file line number Diff line number Diff line change
Expand Up @@ -7,6 +7,7 @@ package routers

import (
"bytes"
"net/url"
"strings"

"code.gitea.io/gitea/models"
Expand Down Expand Up @@ -44,6 +45,11 @@ func Home(ctx *context.Context) {
log.Info("Failed authentication attempt for %s from %s", ctx.User.Name, ctx.RemoteAddr())
ctx.Data["Title"] = ctx.Tr("auth.prohibit_login")
ctx.HTML(200, "user/auth/prohibit_login")
} else if ctx.User.MustChangePassword {
ctx.Data["Title"] = ctx.Tr("auth.must_change_password")
ctx.Data["ChangePasscodeLink"] = setting.AppSubURL + "/user/change_password"
ctx.SetCookie("redirect_to", url.QueryEscape(setting.AppSubURL+ctx.Req.RequestURI), 0, setting.AppSubURL)
ctx.Redirect(setting.AppSubURL + "/user/settings/change_password")
} else {
user.Dashboard(ctx)
}
Expand Down

0 comments on commit c812ba7

Please sign in to comment.