39 lines
790 B
Go
39 lines
790 B
Go
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 {
|
|
ParticipantID string
|
|
*models.Session
|
|
}
|
|
|
|
for _, session := range c.sStore.ReadAll() {
|
|
for _, exam := range session.Exams {
|
|
if exam.Participant.Token == claims["token"] {
|
|
s := struct {
|
|
ParticipantID string
|
|
*models.Session
|
|
}{exam.Participant.ID, session}
|
|
participantSessions = append(participantSessions, s)
|
|
break
|
|
}
|
|
}
|
|
}
|
|
|
|
err = c.ExecuteTemplate(w, participantSessions)
|
|
if err != nil {
|
|
panic(err)
|
|
}
|
|
}
|