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

Backport #28636

Fix #28231, and remove some unused code.
This commit is contained in:
wxiaoguang 2023-12-30 20:50:08 +08:00 committed by GitHub
parent 683b95f0da
commit 2165729d16
No known key found for this signature in database
GPG key ID: 4AEE18F83AFDEB23
5 changed files with 6 additions and 14 deletions

View file

@ -275,9 +275,6 @@ func ActiveSources(tp Type) ([]*Source, error) {
// IsSSPIEnabled returns true if there is at least one activated login // IsSSPIEnabled returns true if there is at least one activated login
// source of type LoginSSPI // source of type LoginSSPI
func IsSSPIEnabled() bool { func IsSSPIEnabled() bool {
if !db.HasEngine {
return false
}
sources, err := ActiveSources(SSPI) sources, err := ActiveSources(SSPI)
if err != nil { if err != nil {
log.Error("ActiveSources: %v", err) log.Error("ActiveSources: %v", err)

View file

@ -27,9 +27,6 @@ var (
x *xorm.Engine x *xorm.Engine
tables []any tables []any
initFuncs []func() error initFuncs []func() error
// HasEngine specifies if we have a xorm.Engine
HasEngine bool
) )
// Engine represents a xorm engine or session. // Engine represents a xorm engine or session.

View file

@ -343,8 +343,7 @@ func loadServerFrom(rootCfg ConfigProvider) {
LandingPageURL = LandingPageOrganizations LandingPageURL = LandingPageOrganizations
case "login": case "login":
LandingPageURL = LandingPageLogin LandingPageURL = LandingPageLogin
case "": case "", "home":
case "home":
LandingPageURL = LandingPageHome LandingPageURL = LandingPageHome
default: default:
LandingPageURL = LandingPage(landingPage) LandingPageURL = LandingPage(landingPage)

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)) log.Info("Backing off for %d seconds", int64(setting.Database.DBConnectBackoff/time.Second))
time.Sleep(setting.Database.DBConnectBackoff) time.Sleep(setting.Database.DBConnectBackoff)
} }
db.HasEngine = true
config.SetDynGetter(system_model.NewDatabaseDynKeyGetter()) config.SetDynGetter(system_model.NewDatabaseDynKeyGetter())
return nil return nil
} }

View file

@ -45,10 +45,6 @@ const (
// AutoSignIn reads cookie and try to auto-login. // AutoSignIn reads cookie and try to auto-login.
func AutoSignIn(ctx *context.Context) (bool, error) { func AutoSignIn(ctx *context.Context) (bool, error) {
if !db.HasEngine {
return false, nil
}
uname := ctx.GetSiteCookie(setting.CookieUserName) uname := ctx.GetSiteCookie(setting.CookieUserName)
if len(uname) == 0 { if len(uname) == 0 {
return false, nil return false, nil
@ -130,7 +126,11 @@ func checkAutoLogin(ctx *context.Context) bool {
if isSucceed { if isSucceed {
middleware.DeleteRedirectToCookie(ctx.Resp) 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 return true
} }