Avoid cycle-redirecting user/login page (#28636)
Fix #28231, and remove some unused code. The `db.HasEngine` doesn't seem useful because the db engine is always initialized before web route.
This commit is contained in:
parent
3d474110c1
commit
e5d8c4b8d4
5 changed files with 7 additions and 16 deletions
|
@ -261,16 +261,12 @@ func (opts FindSourcesOptions) ToConds() builder.Cond {
|
||||||
// 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(ctx context.Context) bool {
|
func IsSSPIEnabled(ctx context.Context) bool {
|
||||||
if !db.HasEngine {
|
|
||||||
return false
|
|
||||||
}
|
|
||||||
|
|
||||||
exist, err := db.Exist[Source](ctx, FindSourcesOptions{
|
exist, err := db.Exist[Source](ctx, FindSourcesOptions{
|
||||||
IsActive: util.OptionalBoolTrue,
|
IsActive: util.OptionalBoolTrue,
|
||||||
LoginType: SSPI,
|
LoginType: SSPI,
|
||||||
}.ToConds())
|
}.ToConds())
|
||||||
if err != nil {
|
if err != nil {
|
||||||
log.Error("Active SSPI Sources: %v", err)
|
log.Error("IsSSPIEnabled: failed to query active SSPI sources: %v", err)
|
||||||
return false
|
return false
|
||||||
}
|
}
|
||||||
return exist
|
return exist
|
||||||
|
|
|
@ -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.
|
||||||
|
|
|
@ -341,8 +341,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)
|
||||||
|
|
|
@ -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
|
||||||
}
|
}
|
||||||
|
|
|
@ -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
|
|
||||||
}
|
|
||||||
|
|
||||||
isSucceed := false
|
isSucceed := false
|
||||||
defer func() {
|
defer func() {
|
||||||
if !isSucceed {
|
if !isSucceed {
|
||||||
|
@ -145,7 +141,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
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
Loading…
Reference in a new issue