]> source.dussan.org Git - gitea.git/commitdiff
Avoid cycle-redirecting user/login page (#28636) (#28658)
authorwxiaoguang <wxiaoguang@gmail.com>
Sat, 30 Dec 2023 12:50:08 +0000 (20:50 +0800)
committerGitHub <noreply@github.com>
Sat, 30 Dec 2023 12:50:08 +0000 (20:50 +0800)
Backport #28636

Fix #28231, and remove some unused code.

models/auth/source.go
models/db/engine.go
modules/setting/server.go
routers/common/db.go
routers/web/auth/auth.go

index 6fdd2006fe4421ec21090d3bcf1226f7f6deea19..88253a4b39b15eaf0131cd13bb577e8e29609cae 100644 (file)
@@ -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)
index 182d8cd9936963f0eff4676c8750ddbb6aacfa99..99906813ca8707af74667f5c1ce0ddf2b929a408 100755 (executable)
@@ -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.
index 08eb82fb3dece4e3bc305aa214221f01feefd0a3..6c65fc1b9e694c006b6764d407504d865ca00b7e 100644 (file)
@@ -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)
index 547f727ce24783fe0b357f4e3b60af1000aa3d9c..a67c9582fa3872047eabccf5ad8631376717b7b8 100644 (file)
@@ -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
 }
index 8017602d9902654fb74641dd7bf7905a4f3b304d..007e790b8edda485d8306159172598c8c134cc78 100644 (file)
@@ -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
        }