lot of new functionalities

This commit is contained in:
Arnaud Delcasse
2025-10-14 18:11:13 +02:00
parent a6f70a6e85
commit d992a7984f
164 changed files with 15113 additions and 9442 deletions

View File

@@ -0,0 +1,58 @@
package auth
import (
"context"
"net/http"
"github.com/rs/zerolog/log"
)
func (h *Handler) Groups(w http.ResponseWriter, r *http.Request) {
session, _ := h.idp.SessionsStore.Get(r, "parcoursmob_session")
if r.Method == "POST" {
r.ParseForm()
groupid := r.FormValue("group")
session.Values["organization"] = groupid
session.Save(r, w)
http.Redirect(w, r, "/app/", http.StatusFound)
return
}
tokenstring, ok := session.Values["idtoken"]
if !ok {
http.Redirect(w, r, "/app/", http.StatusFound)
return
}
idtoken, err := h.idp.TokenVerifier.Verify(context.Background(), tokenstring.(string))
if err != nil {
delete(session.Values, "idtoken")
http.Redirect(w, r, "/app/", http.StatusFound)
return
}
result, err := h.applicationHandler.GetUserGroups(idtoken)
if err != nil {
log.Error().Err(err).Msg("Failed to get user groups")
w.WriteHeader(http.StatusInternalServerError)
return
}
var groupsresponse = []any{}
for _, group := range result.Groups {
groupsresponse = append(groupsresponse, group)
}
h.renderer.AuthGroups(w, r, groupsresponse)
}
func (h *Handler) GroupSwitch(w http.ResponseWriter, r *http.Request) {
session, _ := h.idp.SessionsStore.Get(r, "parcoursmob_session")
delete(session.Values, "organization")
session.Save(r, w)
http.Redirect(w, r, "/app/", http.StatusFound)
}