mirror of
https://github.com/go-gitea/gitea.git
synced 2025-07-21 09:31:19 +02:00
@@ -11,7 +11,6 @@ import (
|
||||
"code.gitea.io/gitea/modules/log"
|
||||
session_module "code.gitea.io/gitea/modules/session"
|
||||
|
||||
chiSession "gitea.com/go-chi/session"
|
||||
"github.com/gorilla/sessions"
|
||||
)
|
||||
|
||||
@@ -35,11 +34,11 @@ func (st *SessionsStore) New(r *http.Request, name string) (*sessions.Session, e
|
||||
|
||||
// getOrNew gets the session from the chi-session if it exists. Override permits the overriding of an unexpected object.
|
||||
func (st *SessionsStore) getOrNew(r *http.Request, name string, override bool) (*sessions.Session, error) {
|
||||
chiStore := chiSession.GetSession(r)
|
||||
store := session_module.GetContextSession(r)
|
||||
|
||||
session := sessions.NewSession(st, name)
|
||||
|
||||
rawData := chiStore.Get(name)
|
||||
rawData := store.Get(name)
|
||||
if rawData != nil {
|
||||
oldSession, ok := rawData.(*sessions.Session)
|
||||
if ok {
|
||||
@@ -56,21 +55,21 @@ func (st *SessionsStore) getOrNew(r *http.Request, name string, override bool) (
|
||||
}
|
||||
|
||||
session.IsNew = override
|
||||
session.ID = chiStore.ID() // Simply copy the session id from the chi store
|
||||
session.ID = store.ID() // Simply copy the session id from the chi store
|
||||
|
||||
return session, chiStore.Set(name, session)
|
||||
return session, store.Set(name, session)
|
||||
}
|
||||
|
||||
// Save should persist session to the underlying store implementation.
|
||||
func (st *SessionsStore) Save(r *http.Request, w http.ResponseWriter, session *sessions.Session) error {
|
||||
chiStore := chiSession.GetSession(r)
|
||||
store := session_module.GetContextSession(r)
|
||||
|
||||
if session.IsNew {
|
||||
_, _ = session_module.RegenerateSession(w, r)
|
||||
session.IsNew = false
|
||||
}
|
||||
|
||||
if err := chiStore.Set(session.Name(), session); err != nil {
|
||||
if err := store.Set(session.Name(), session); err != nil {
|
||||
return err
|
||||
}
|
||||
|
||||
@@ -83,7 +82,7 @@ func (st *SessionsStore) Save(r *http.Request, w http.ResponseWriter, session *s
|
||||
}
|
||||
}
|
||||
|
||||
return chiStore.Release()
|
||||
return store.Release()
|
||||
}
|
||||
|
||||
type sizeWriter struct {
|
||||
|
@@ -49,7 +49,7 @@ func mockRequest(t *testing.T, reqPath string) *http.Request {
|
||||
|
||||
type MockContextOption struct {
|
||||
Render context.Render
|
||||
SessionStore *session.MockStore
|
||||
SessionStore session.Store
|
||||
}
|
||||
|
||||
// MockContext mock context for unit tests
|
||||
|
Reference in New Issue
Block a user