probo/cmd/serve/sessions.go

40 lines
790 B
Go
Raw Permalink Normal View History

package serve
import (
"net/http"
"git.andreafazzi.eu/andrea/probo/pkg/models"
"github.com/golang-jwt/jwt"
)
var SessionsHandler = func(c *Controller, w http.ResponseWriter, r *http.Request) {
token, err := ValidateJwtCookie(r)
if err != nil {
panic(err)
}
claims := token.Claims.(jwt.MapClaims)
var participantSessions []struct {
2024-05-25 18:09:31 +02:00
ParticipantID string
*models.Session
}
for _, session := range c.sStore.ReadAll() {
for _, exam := range session.Exams {
if exam.Participant.Token == claims["token"] {
s := struct {
2024-05-25 18:09:31 +02:00
ParticipantID string
*models.Session
2024-05-25 18:09:31 +02:00
}{exam.Participant.ID, session}
participantSessions = append(participantSessions, s)
break
}
}
}
err = c.ExecuteTemplate(w, participantSessions)
if err != nil {
panic(err)
}
}