aboutsummaryrefslogtreecommitdiffstats
diff options
context:
space:
mode:
authorwxiaoguang <wxiaoguang@gmail.com>2023-12-30 20:50:08 +0800
committerGitHub <noreply@github.com>2023-12-30 20:50:08 +0800
commit2165729d16cbb56087f38c9c04f8ffb5ccf6fdc0 (patch)
treede97a70814b8c9b6204d5e85f37ce9b16d8fd687
parent683b95f0da44bfbda94ba778c2b4625b143974f1 (diff)
downloadgitea-2165729d16cbb56087f38c9c04f8ffb5ccf6fdc0.tar.gz
gitea-2165729d16cbb56087f38c9c04f8ffb5ccf6fdc0.zip
Avoid cycle-redirecting user/login page (#28636) (#28658)
Backport #28636 Fix #28231, and remove some unused code.
-rw-r--r--models/auth/source.go3
-rwxr-xr-xmodels/db/engine.go3
-rw-r--r--modules/setting/server.go3
-rw-r--r--routers/common/db.go1
-rw-r--r--routers/web/auth/auth.go10
5 files changed, 6 insertions, 14 deletions
diff --git a/models/auth/source.go b/models/auth/source.go
index 6fdd2006fe..88253a4b39 100644
--- a/models/auth/source.go
+++ b/models/auth/source.go
@@ -275,9 +275,6 @@ func ActiveSources(tp Type) ([]*Source, error) {
// IsSSPIEnabled returns true if there is at least one activated login
// source of type LoginSSPI
func IsSSPIEnabled() bool {
- if !db.HasEngine {
- return false
- }
sources, err := ActiveSources(SSPI)
if err != nil {
log.Error("ActiveSources: %v", err)
diff --git a/models/db/engine.go b/models/db/engine.go
index 182d8cd993..99906813ca 100755
--- a/models/db/engine.go
+++ b/models/db/engine.go
@@ -27,9 +27,6 @@ var (
x *xorm.Engine
tables []any
initFuncs []func() error
-
- // HasEngine specifies if we have a xorm.Engine
- HasEngine bool
)
// Engine represents a xorm engine or session.
diff --git a/modules/setting/server.go b/modules/setting/server.go
index 08eb82fb3d..6c65fc1b9e 100644
--- a/modules/setting/server.go
+++ b/modules/setting/server.go
@@ -343,8 +343,7 @@ func loadServerFrom(rootCfg ConfigProvider) {
LandingPageURL = LandingPageOrganizations
case "login":
LandingPageURL = LandingPageLogin
- case "":
- case "home":
+ case "", "home":
LandingPageURL = LandingPageHome
default:
LandingPageURL = LandingPage(landingPage)
diff --git a/routers/common/db.go b/routers/common/db.go
index 547f727ce2..a67c9582fa 100644
--- a/routers/common/db.go
+++ b/routers/common/db.go
@@ -37,7 +37,6 @@ func InitDBEngine(ctx context.Context) (err error) {
log.Info("Backing off for %d seconds", int64(setting.Database.DBConnectBackoff/time.Second))
time.Sleep(setting.Database.DBConnectBackoff)
}
- db.HasEngine = true
config.SetDynGetter(system_model.NewDatabaseDynKeyGetter())
return nil
}
diff --git a/routers/web/auth/auth.go b/routers/web/auth/auth.go
index 8017602d99..007e790b8e 100644
--- a/routers/web/auth/auth.go
+++ b/routers/web/auth/auth.go
@@ -45,10 +45,6 @@ const (
// AutoSignIn reads cookie and try to auto-login.
func AutoSignIn(ctx *context.Context) (bool, error) {
- if !db.HasEngine {
- return false, nil
- }
-
uname := ctx.GetSiteCookie(setting.CookieUserName)
if len(uname) == 0 {
return false, nil
@@ -130,7 +126,11 @@ func checkAutoLogin(ctx *context.Context) bool {
if isSucceed {
middleware.DeleteRedirectToCookie(ctx.Resp)
- ctx.RedirectToFirst(redirectTo, setting.AppSubURL+string(setting.LandingPageURL))
+ 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)
return true
}