diff --git a/cmd/backend/sessions.go b/cmd/backend/sessions.go index eb55dfc..9fbf3f9 100644 --- a/cmd/backend/sessions.go +++ b/cmd/backend/sessions.go @@ -10,7 +10,10 @@ import ( "github.com/gorilla/sessions" ) -type CookieStore struct{ sessions.CookieStore } +type ( + CookieStore struct{ sessions.CookieStore } + Session struct{ sessions.Session } +) func NewKey() ([]byte, error) { key := make([]byte, 32) diff --git a/cmd/frontend/sessions.go b/cmd/frontend/sessions.go index d88e595..b2f94de 100644 --- a/cmd/frontend/sessions.go +++ b/cmd/frontend/sessions.go @@ -7,7 +7,6 @@ import ( "log" "net/http" - "github.com/gorilla/sessions" b "streifling.com/jason/cpolis/cmd/backend" ) @@ -29,16 +28,17 @@ func saveSession(w http.ResponseWriter, r *http.Request, s *b.CookieStore, u *b. } // getSession is used for verifying that the user is logged in and returns their session and an error. -func getSession(w http.ResponseWriter, r *http.Request, c *b.Config, s *b.CookieStore) (*sessions.Session, error) { +func getSession(w http.ResponseWriter, r *http.Request, c *b.Config, s *b.CookieStore) (*b.Session, error) { msg := "Keine gültige Session. Bitte erneut anmelden." tmpl, tmplErr := template.ParseFiles(c.WebDir+"/templates/index.html", c.WebDir+"/templates/login.html") - session, err := s.Get(r, "cookie") + tmpSession, err := s.Get(r, "cookie") if err != nil { template.Must(tmpl, tmplErr).ExecuteTemplate(w, "page-content", msg) return nil, err } + session := &b.Session{Session: *tmpSession} if session.IsNew { template.Must(tmpl, tmplErr).ExecuteTemplate(w, "page-content", msg) return session, errors.New("error: no existing session")