本站源代码
選択できるのは25トピックまでです。 トピックは、先頭が英数字で、英数字とダッシュ('-')を使用した35文字以内のものにしてください。

46 行
1.6KB

  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. "gitea.com/macaron/session"
  12. )
  13. var (
  14. // SessionConfig difines Session settings
  15. SessionConfig session.Options
  16. )
  17. func newSessionService() {
  18. SessionConfig.Provider = Cfg.Section("session").Key("PROVIDER").In("memory",
  19. []string{"memory", "file", "redis", "mysql", "postgres", "couchbase", "memcache", "nodb"})
  20. SessionConfig.ProviderConfig = strings.Trim(Cfg.Section("session").Key("PROVIDER_CONFIG").MustString(path.Join(AppDataPath, "sessions")), "\" ")
  21. if SessionConfig.Provider == "file" && !filepath.IsAbs(SessionConfig.ProviderConfig) {
  22. SessionConfig.ProviderConfig = path.Join(AppWorkPath, SessionConfig.ProviderConfig)
  23. }
  24. SessionConfig.CookieName = Cfg.Section("session").Key("COOKIE_NAME").MustString("i_like_gitea")
  25. SessionConfig.CookiePath = AppSubURL
  26. SessionConfig.Secure = Cfg.Section("session").Key("COOKIE_SECURE").MustBool(false)
  27. SessionConfig.Gclifetime = Cfg.Section("session").Key("GC_INTERVAL_TIME").MustInt64(86400)
  28. SessionConfig.Maxlifetime = Cfg.Section("session").Key("SESSION_LIFE_TIME").MustInt64(86400)
  29. SessionConfig.Domain = Cfg.Section("session").Key("DOMAIN").String()
  30. shadowConfig, err := json.Marshal(SessionConfig)
  31. if err != nil {
  32. log.Fatal("Can't shadow session config: %v", err)
  33. }
  34. SessionConfig.ProviderConfig = string(shadowConfig)
  35. SessionConfig.Provider = "VirtualSession"
  36. log.Info("Session Service Enabled")
  37. }
上海开阖软件有限公司 沪ICP备12045867号-1