From 5b417ef87dda37eba086293f727381ae5b75c0da Mon Sep 17 00:00:00 2001 From: Jason Streifling Date: Sun, 19 Jan 2025 20:34:12 +0100 Subject: [PATCH] Change ValidateSession() to SessionIsActive() which only returns a bool --- cmd/calls/images.go | 2 +- cmd/frontend/sessions.go | 12 ++++-------- 2 files changed, 5 insertions(+), 9 deletions(-) diff --git a/cmd/calls/images.go b/cmd/calls/images.go index ea0504a..a2113dc 100644 --- a/cmd/calls/images.go +++ b/cmd/calls/images.go @@ -10,7 +10,7 @@ import ( func ServeImage(c *b.Config, s map[string]*f.Session) http.HandlerFunc { return func(w http.ResponseWriter, r *http.Request) { - if _, err := f.ValidateSession(w, r, c, s); err != nil { + if !f.SessionIsActive(r, s) { if !tokenIsVerified(w, r, c) { return } diff --git a/cmd/frontend/sessions.go b/cmd/frontend/sessions.go index 153a439..7aacbe8 100644 --- a/cmd/frontend/sessions.go +++ b/cmd/frontend/sessions.go @@ -66,18 +66,14 @@ func StartSessions() (map[string]*Session, chan string) { // ValidateSession is used for verifying that the user is logged in and returns // their session and an error. -func ValidateSession(w http.ResponseWriter, r *http.Request, c *b.Config, s map[string]*Session) (*Session, error) { +func SessionIsActive(r *http.Request, s map[string]*Session) bool { cookie, err := r.Cookie("cpolis_session") if err != nil { - return nil, errors.New("no cookie set") + return false } - session, ok := s[cookie.Value] - if !ok { - return nil, errors.New("session does not exist") - } - - return session, nil + _, ok := s[cookie.Value] + return ok } // ManageSession is used for verifying that the user is logged in and returns