Refactor session code

This commit is contained in:
2024-05-05 14:50:51 +07:00
parent 19856c328d
commit dce11e3569
5 changed files with 18 additions and 35 deletions

View File

@ -4,25 +4,18 @@ import (
"errors"
"net/http"
"github.com/fossyy/filekeeper/logger"
"github.com/fossyy/filekeeper/session"
"github.com/fossyy/filekeeper/types"
"github.com/fossyy/filekeeper/utils"
)
var log *logger.AggregatedLogger
func init() {
log = logger.Logger()
}
func GET(w http.ResponseWriter, r *http.Request) {
cookie, err := r.Cookie("Session")
if err != nil {
return
}
storeSession, err := session.GlobalSessionStore.Get(cookie.Value)
storeSession, err := session.Get(cookie.Value)
if err != nil {
if errors.Is(err, &session.SessionNotFoundError{}) {
storeSession.Destroy(w)
@ -31,7 +24,7 @@ func GET(w http.ResponseWriter, r *http.Request) {
return
}
session.GlobalSessionStore.Delete(cookie.Value)
storeSession.Delete()
session.RemoveSessionInfo(storeSession.Values["user"].(types.User).Email, cookie.Value)
http.SetCookie(w, &http.Cookie{