Вы не можете выбрать более 25 тем Темы должны начинаться с буквы или цифры, могут содержать дефисы(-) и должны содержать не более 35 символов.

12345678910111213141516171819202122232425262728293031323334353637383940414243444546
  1. // Copyright 2019 The Gitea Authors. All rights reserved.
  2. // Use of this source code is governed by a MIT-style
  3. // license that can be found in the LICENSE file.
  4. package setting
  5. import (
  6. "encoding/json"
  7. "path"
  8. "path/filepath"
  9. "strings"
  10. "code.gitea.io/gitea/modules/log"
  11. // This ensures that VirtualSessionProvider is available
  12. _ "code.gitea.io/gitea/modules/session"
  13. "github.com/go-macaron/session"
  14. )
  15. var (
  16. // SessionConfig difines Session settings
  17. SessionConfig session.Options
  18. )
  19. func newSessionService() {
  20. SessionConfig.Provider = Cfg.Section("session").Key("PROVIDER").In("memory",
  21. []string{"memory", "file", "redis", "mysql", "postgres", "couchbase", "memcache", "nodb"})
  22. SessionConfig.ProviderConfig = strings.Trim(Cfg.Section("session").Key("PROVIDER_CONFIG").MustString(path.Join(AppDataPath, "sessions")), "\" ")
  23. if SessionConfig.Provider == "file" && !filepath.IsAbs(SessionConfig.ProviderConfig) {
  24. SessionConfig.ProviderConfig = path.Join(AppWorkPath, SessionConfig.ProviderConfig)
  25. }
  26. SessionConfig.CookieName = Cfg.Section("session").Key("COOKIE_NAME").MustString("i_like_gitea")
  27. SessionConfig.CookiePath = AppSubURL
  28. SessionConfig.Secure = Cfg.Section("session").Key("COOKIE_SECURE").MustBool(false)
  29. SessionConfig.Gclifetime = Cfg.Section("session").Key("GC_INTERVAL_TIME").MustInt64(86400)
  30. SessionConfig.Maxlifetime = Cfg.Section("session").Key("SESSION_LIFE_TIME").MustInt64(86400)
  31. shadowConfig, err := json.Marshal(SessionConfig)
  32. if err != nil {
  33. log.Fatal("Can't shadow session config: %v", err)
  34. }
  35. SessionConfig.ProviderConfig = string(shadowConfig)
  36. SessionConfig.Provider = "VirtualSession"
  37. log.Info("Session Service Enabled")
  38. }