mirror of
https://github.com/go-gitea/gitea
synced 2025-07-23 10:48:37 +00:00
Make "/user/login" page redirect if the current user has signed in (#29583)
Fix #29582 and maybe more. Maybe fix #29116
This commit is contained in:
@@ -123,9 +123,21 @@ func resetLocale(ctx *context.Context, u *user_model.User) error {
|
||||
return nil
|
||||
}
|
||||
|
||||
func RedirectAfterLogin(ctx *context.Context) {
|
||||
redirectTo := ctx.FormString("redirect_to")
|
||||
if redirectTo == "" {
|
||||
redirectTo = ctx.GetSiteCookie("redirect_to")
|
||||
}
|
||||
middleware.DeleteRedirectToCookie(ctx.Resp)
|
||||
nextRedirectTo := setting.AppSubURL + string(setting.LandingPageURL)
|
||||
if setting.LandingPageURL == setting.LandingPageLogin {
|
||||
nextRedirectTo = setting.AppSubURL + "/" // do not cycle-redirect to the login page
|
||||
}
|
||||
ctx.RedirectToFirst(redirectTo, nextRedirectTo)
|
||||
}
|
||||
|
||||
func CheckAutoLogin(ctx *context.Context) bool {
|
||||
// Check auto-login
|
||||
isSucceed, err := autoSignIn(ctx)
|
||||
isSucceed, err := autoSignIn(ctx) // try to auto-login
|
||||
if err != nil {
|
||||
if errors.Is(err, auth_service.ErrAuthTokenInvalidHash) {
|
||||
ctx.Flash.Error(ctx.Tr("auth.remember_me.compromised"), true)
|
||||
@@ -138,17 +150,10 @@ func CheckAutoLogin(ctx *context.Context) bool {
|
||||
redirectTo := ctx.FormString("redirect_to")
|
||||
if len(redirectTo) > 0 {
|
||||
middleware.SetRedirectToCookie(ctx.Resp, redirectTo)
|
||||
} else {
|
||||
redirectTo = ctx.GetSiteCookie("redirect_to")
|
||||
}
|
||||
|
||||
if isSucceed {
|
||||
middleware.DeleteRedirectToCookie(ctx.Resp)
|
||||
nextRedirectTo := setting.AppSubURL + string(setting.LandingPageURL)
|
||||
if setting.LandingPageURL == setting.LandingPageLogin {
|
||||
nextRedirectTo = setting.AppSubURL + "/" // do not cycle-redirect to the login page
|
||||
}
|
||||
ctx.RedirectToFirst(redirectTo, nextRedirectTo)
|
||||
RedirectAfterLogin(ctx)
|
||||
return true
|
||||
}
|
||||
|
||||
@@ -163,6 +168,11 @@ func SignIn(ctx *context.Context) {
|
||||
return
|
||||
}
|
||||
|
||||
if ctx.IsSigned {
|
||||
RedirectAfterLogin(ctx)
|
||||
return
|
||||
}
|
||||
|
||||
oauth2Providers, err := oauth2.GetOAuth2Providers(ctx, optional.Some(true))
|
||||
if err != nil {
|
||||
ctx.ServerError("UserSignIn", err)
|
||||
|
Reference in New Issue
Block a user