mirror of
https://github.com/thomiceli/opengist.git
synced 2025-06-13 05:47:12 +02:00
Use filesystem session store (#240)
This commit is contained in:
@ -35,10 +35,11 @@ import (
|
||||
)
|
||||
|
||||
var (
|
||||
dev bool
|
||||
store *sessions.CookieStore
|
||||
re = regexp.MustCompile("[^a-z0-9]+")
|
||||
fm = template.FuncMap{
|
||||
dev bool
|
||||
flashStore *sessions.CookieStore // session store for flash messages
|
||||
userStore *sessions.FilesystemStore // session store for user sessions
|
||||
re = regexp.MustCompile("[^a-z0-9]+")
|
||||
fm = template.FuncMap{
|
||||
"split": strings.Split,
|
||||
"indexByte": strings.IndexByte,
|
||||
"toInt": func(i string) int {
|
||||
@ -160,8 +161,13 @@ type Server struct {
|
||||
|
||||
func NewServer(isDev bool) *Server {
|
||||
dev = isDev
|
||||
store = sessions.NewCookieStore([]byte("opengist"))
|
||||
gothic.Store = store
|
||||
flashStore = sessions.NewCookieStore([]byte("opengist"))
|
||||
userStore = sessions.NewFilesystemStore(path.Join(config.GetHomeDir(), "sessions"),
|
||||
utils.ReadKey(path.Join(config.GetHomeDir(), "sessions", "session-auth.key")),
|
||||
utils.ReadKey(path.Join(config.GetHomeDir(), "sessions", "session-encrypt.key")),
|
||||
)
|
||||
userStore.MaxLength(10 * 1024)
|
||||
gothic.Store = userStore
|
||||
|
||||
e := echo.New()
|
||||
e.HideBanner = true
|
||||
|
@ -142,6 +142,9 @@ func setup(t *testing.T) {
|
||||
homePath := config.GetHomeDir()
|
||||
log.Info().Msg("Data directory: " + homePath)
|
||||
|
||||
err = os.MkdirAll(filepath.Join(homePath, "sessions"), 0755)
|
||||
require.NoError(t, err, "Could not create sessions directory")
|
||||
|
||||
err = os.MkdirAll(filepath.Join(homePath, "tmp", "repos"), 0755)
|
||||
require.NoError(t, err, "Could not create tmp repos directory")
|
||||
|
||||
|
@ -68,7 +68,7 @@ func getUserLogged(ctx echo.Context) *db.User {
|
||||
}
|
||||
|
||||
func setErrorFlashes(ctx echo.Context) {
|
||||
sess, _ := store.Get(ctx.Request(), "flash")
|
||||
sess, _ := flashStore.Get(ctx.Request(), "flash")
|
||||
|
||||
setData(ctx, "flashErrors", sess.Flashes("error"))
|
||||
setData(ctx, "flashSuccess", sess.Flashes("success"))
|
||||
@ -77,13 +77,13 @@ func setErrorFlashes(ctx echo.Context) {
|
||||
}
|
||||
|
||||
func addFlash(ctx echo.Context, flashMessage string, flashType string) {
|
||||
sess, _ := store.Get(ctx.Request(), "flash")
|
||||
sess, _ := flashStore.Get(ctx.Request(), "flash")
|
||||
sess.AddFlash(flashMessage, flashType)
|
||||
_ = sess.Save(ctx.Request(), ctx.Response())
|
||||
}
|
||||
|
||||
func getSession(ctx echo.Context) *sessions.Session {
|
||||
sess, _ := store.Get(ctx.Request(), "session")
|
||||
sess, _ := userStore.Get(ctx.Request(), "session")
|
||||
return sess
|
||||
}
|
||||
|
||||
|
Reference in New Issue
Block a user