Change ValidateSession() to SessionIsActive() which only returns a bool

This commit is contained in:
Jason Streifling 2025-01-19 20:34:12 +01:00
parent 04283d5917
commit 5b417ef87d
2 changed files with 5 additions and 9 deletions

View File

@ -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
}

View File

@ -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