lot of new functionalities
This commit is contained in:
60
servers/web/application/handler.go
Normal file
60
servers/web/application/handler.go
Normal file
@@ -0,0 +1,60 @@
|
||||
package application
|
||||
|
||||
import (
|
||||
"errors"
|
||||
"net/http"
|
||||
|
||||
"git.coopgo.io/coopgo-apps/parcoursmob/core/application"
|
||||
"git.coopgo.io/coopgo-apps/parcoursmob/renderer"
|
||||
"git.coopgo.io/coopgo-apps/parcoursmob/services"
|
||||
"git.coopgo.io/coopgo-apps/parcoursmob/core/utils/identification"
|
||||
"git.coopgo.io/coopgo-platform/groups-management/storage"
|
||||
"github.com/coreos/go-oidc/v3/oidc"
|
||||
"github.com/spf13/viper"
|
||||
)
|
||||
|
||||
type Handler struct {
|
||||
cfg *viper.Viper
|
||||
renderer *renderer.Renderer
|
||||
applicationHandler *application.ApplicationHandler
|
||||
idp *identification.IdentificationProvider
|
||||
services *services.ServicesHandler
|
||||
}
|
||||
|
||||
func NewHandler(cfg *viper.Viper, renderer *renderer.Renderer, applicationHandler *application.ApplicationHandler, idp *identification.IdentificationProvider, services *services.ServicesHandler) *Handler {
|
||||
return &Handler{
|
||||
cfg: cfg,
|
||||
renderer: renderer,
|
||||
applicationHandler: applicationHandler,
|
||||
idp: idp,
|
||||
services: services,
|
||||
}
|
||||
}
|
||||
|
||||
func (h *Handler) currentGroup(r *http.Request) (current_group storage.Group, err error) {
|
||||
g := r.Context().Value(identification.GroupKey)
|
||||
if g == nil {
|
||||
return storage.Group{}, errors.New("current group not found")
|
||||
}
|
||||
current_group = g.(storage.Group)
|
||||
|
||||
return current_group, nil
|
||||
}
|
||||
|
||||
func (h *Handler) currentUser(r *http.Request) (current_user_token *oidc.IDToken, current_user_claims map[string]any, err error) {
|
||||
// Get current user ID
|
||||
u := r.Context().Value(identification.IdtokenKey)
|
||||
if u == nil {
|
||||
return nil, nil, errors.New("current user not found")
|
||||
}
|
||||
current_user_token = u.(*oidc.IDToken)
|
||||
|
||||
// Get current user claims
|
||||
c := r.Context().Value(identification.ClaimsKey)
|
||||
if c == nil {
|
||||
return nil, nil, errors.New("current user claims not found")
|
||||
}
|
||||
current_user_claims = c.(map[string]any)
|
||||
|
||||
return current_user_token, current_user_claims, nil
|
||||
}
|
||||
Reference in New Issue
Block a user