lot of new functionalities
This commit is contained in:
58
servers/web/auth/groups.go
Normal file
58
servers/web/auth/groups.go
Normal 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)
|
||||
}
|
||||
Reference in New Issue
Block a user