Emailing management, administration improvement, Carpooling in multimodal search
This commit is contained in:
29
handlers/auth/auth.go
Normal file
29
handlers/auth/auth.go
Normal file
@@ -0,0 +1,29 @@
|
||||
package auth
|
||||
|
||||
import (
|
||||
"git.coopgo.io/coopgo-apps/parcoursmob/renderer"
|
||||
"git.coopgo.io/coopgo-apps/parcoursmob/services"
|
||||
"git.coopgo.io/coopgo-apps/parcoursmob/utils/cache"
|
||||
"git.coopgo.io/coopgo-apps/parcoursmob/utils/identification"
|
||||
"github.com/spf13/viper"
|
||||
)
|
||||
|
||||
type AuthHandler struct {
|
||||
idp *identification.IdentificationProvider
|
||||
config *viper.Viper
|
||||
services *services.ServicesHandler
|
||||
Renderer *renderer.Renderer
|
||||
cache *cache.CacheHandler
|
||||
}
|
||||
|
||||
func NewAuthHandler(cfg *viper.Viper, idp *identification.IdentificationProvider, svc *services.ServicesHandler, cache *cache.CacheHandler) (*AuthHandler, error) {
|
||||
templates_root := cfg.GetString("templates.root")
|
||||
renderer := renderer.NewRenderer(cfg, templates_root)
|
||||
return &AuthHandler{
|
||||
idp: idp,
|
||||
config: cfg,
|
||||
services: svc,
|
||||
Renderer: renderer,
|
||||
cache: cache,
|
||||
}, nil
|
||||
}
|
||||
@@ -5,34 +5,9 @@ import (
|
||||
"fmt"
|
||||
"net/http"
|
||||
|
||||
"git.coopgo.io/coopgo-apps/parcoursmob/renderer"
|
||||
"git.coopgo.io/coopgo-apps/parcoursmob/services"
|
||||
"git.coopgo.io/coopgo-apps/parcoursmob/utils/cache"
|
||||
"git.coopgo.io/coopgo-apps/parcoursmob/utils/identification"
|
||||
groupsmanagement "git.coopgo.io/coopgo-platform/groups-management/grpcapi"
|
||||
"github.com/spf13/viper"
|
||||
)
|
||||
|
||||
type AuthHandler struct {
|
||||
idp *identification.IdentificationProvider
|
||||
config *viper.Viper
|
||||
services *services.ServicesHandler
|
||||
Renderer *renderer.Renderer
|
||||
cache *cache.CacheHandler
|
||||
}
|
||||
|
||||
func NewAuthHandler(cfg *viper.Viper, idp *identification.IdentificationProvider, svc *services.ServicesHandler, cache *cache.CacheHandler) (*AuthHandler, error) {
|
||||
templates_root := cfg.GetString("templates.root")
|
||||
renderer := renderer.NewRenderer(cfg, templates_root)
|
||||
return &AuthHandler{
|
||||
idp: idp,
|
||||
config: cfg,
|
||||
services: svc,
|
||||
Renderer: renderer,
|
||||
cache: cache,
|
||||
}, nil
|
||||
}
|
||||
|
||||
func (h *AuthHandler) Groups(w http.ResponseWriter, r *http.Request) {
|
||||
session, _ := h.idp.SessionsStore.Get(r, "parcoursmob_session")
|
||||
|
||||
|
||||
79
handlers/auth/onboarding.go
Normal file
79
handlers/auth/onboarding.go
Normal file
@@ -0,0 +1,79 @@
|
||||
package auth
|
||||
|
||||
import (
|
||||
"context"
|
||||
"fmt"
|
||||
"net/http"
|
||||
|
||||
mobilityaccounts "git.coopgo.io/coopgo-platform/mobility-accounts/grpcapi"
|
||||
ma "git.coopgo.io/coopgo-platform/mobility-accounts/storage"
|
||||
)
|
||||
|
||||
func (h *AuthHandler) Onboarding(w http.ResponseWriter, r *http.Request) {
|
||||
r.ParseForm()
|
||||
|
||||
key := r.FormValue("key")
|
||||
onboarding, err := h.cache.Get("onboarding/" + key)
|
||||
if err != nil {
|
||||
fmt.Println(err)
|
||||
w.WriteHeader(http.StatusInternalServerError)
|
||||
return
|
||||
}
|
||||
|
||||
onboardingmap := onboarding.(map[string]any)
|
||||
|
||||
if r.Method == "POST" {
|
||||
if r.FormValue("password") == "" {
|
||||
fmt.Println("password is empty !")
|
||||
w.WriteHeader(http.StatusInternalServerError)
|
||||
return
|
||||
}
|
||||
|
||||
groups := []string{
|
||||
onboardingmap["group"].(string),
|
||||
//onboardingmap["group"].(string) + ":admin",
|
||||
}
|
||||
|
||||
if onboardingmap["admin"].(bool) {
|
||||
groups = append(groups, onboardingmap["group"].(string)+":admin")
|
||||
}
|
||||
|
||||
account := &ma.Account{
|
||||
Authentication: ma.AccountAuth{
|
||||
Local: ma.LocalAuth{
|
||||
Username: onboardingmap["username"].(string),
|
||||
Password: r.FormValue("password"),
|
||||
},
|
||||
},
|
||||
Namespace: "parcoursmob",
|
||||
Data: map[string]any{
|
||||
"first_name": r.FormValue("first_name"),
|
||||
"last_name": r.FormValue("last_name"),
|
||||
"email": onboardingmap["username"],
|
||||
"groups": groups,
|
||||
},
|
||||
}
|
||||
|
||||
acc, err := mobilityaccounts.AccountFromStorageType(account)
|
||||
if err != nil {
|
||||
fmt.Println(err)
|
||||
w.WriteHeader(http.StatusInternalServerError)
|
||||
return
|
||||
}
|
||||
|
||||
request := &mobilityaccounts.RegisterRequest{
|
||||
Account: acc,
|
||||
}
|
||||
|
||||
_, err = h.services.GRPC.MobilityAccounts.Register(context.TODO(), request)
|
||||
|
||||
if err != nil {
|
||||
fmt.Println(err)
|
||||
w.WriteHeader(http.StatusInternalServerError)
|
||||
return
|
||||
}
|
||||
http.Redirect(w, r, "/app/", http.StatusFound)
|
||||
}
|
||||
|
||||
h.Renderer.AuthOnboarding(w, r, key, onboarding)
|
||||
}
|
||||
Reference in New Issue
Block a user