Browse Source

Avoid cycle-redirecting user/login page (#28636) (#28658)

Backport #28636

Fix #28231, and remove some unused code.
tags/v1.21.4
wxiaoguang 5 months ago
parent
commit
2165729d16
No account linked to committer's email address
5 changed files with 6 additions and 14 deletions
  1. 0
    3
      models/auth/source.go
  2. 0
    3
      models/db/engine.go
  3. 1
    2
      modules/setting/server.go
  4. 0
    1
      routers/common/db.go
  5. 5
    5
      routers/web/auth/auth.go

+ 0
- 3
models/auth/source.go View 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)

+ 0
- 3
models/db/engine.go View File

@@ -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.

+ 1
- 2
modules/setting/server.go View 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)

+ 0
- 1
routers/common/db.go View 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
}

+ 5
- 5
routers/web/auth/auth.go View 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
}


Loading…
Cancel
Save