2022-08-11 15:26:55 +00:00
|
|
|
package main
|
|
|
|
|
|
|
|
import (
|
|
|
|
"fmt"
|
|
|
|
"log"
|
|
|
|
"net/http"
|
|
|
|
"time"
|
|
|
|
|
|
|
|
"git.coopgo.io/coopgo-apps/parcoursmob/handlers/api"
|
|
|
|
"git.coopgo.io/coopgo-apps/parcoursmob/handlers/application"
|
|
|
|
"git.coopgo.io/coopgo-apps/parcoursmob/handlers/auth"
|
2022-10-17 03:02:19 +00:00
|
|
|
"git.coopgo.io/coopgo-apps/parcoursmob/renderer"
|
2022-08-11 15:26:55 +00:00
|
|
|
"git.coopgo.io/coopgo-apps/parcoursmob/services"
|
|
|
|
"git.coopgo.io/coopgo-apps/parcoursmob/utils/identification"
|
2022-10-30 19:11:36 +00:00
|
|
|
cache "git.coopgo.io/coopgo-apps/parcoursmob/utils/storage"
|
2022-08-11 15:26:55 +00:00
|
|
|
"github.com/gorilla/mux"
|
|
|
|
)
|
|
|
|
|
|
|
|
func main() {
|
|
|
|
cfg, err := ReadConfig()
|
|
|
|
if err != nil {
|
|
|
|
panic(err)
|
|
|
|
}
|
|
|
|
|
|
|
|
var (
|
|
|
|
address = cfg.GetString("server.listen")
|
|
|
|
service_name = cfg.GetString("service_name")
|
|
|
|
templates_public_dir = cfg.GetString("templates.public_dir")
|
2023-01-30 14:21:08 +00:00
|
|
|
dev_env = cfg.GetBool("dev_env")
|
2022-08-11 15:26:55 +00:00
|
|
|
)
|
|
|
|
|
|
|
|
svc, err := services.NewServicesHandler(cfg)
|
|
|
|
if err != nil {
|
|
|
|
panic(err)
|
|
|
|
}
|
|
|
|
|
2022-10-30 19:11:36 +00:00
|
|
|
kv, err := cache.NewKVHandler(cfg)
|
2022-08-11 15:26:55 +00:00
|
|
|
if err != nil {
|
|
|
|
panic(err)
|
|
|
|
}
|
|
|
|
|
2022-10-31 23:40:20 +00:00
|
|
|
filestorage, err := cache.NewFileStorage(cfg)
|
|
|
|
|
2022-10-30 19:11:36 +00:00
|
|
|
idp, err := identification.NewIdentificationProvider(cfg, svc, kv)
|
2022-08-11 15:26:55 +00:00
|
|
|
if err != nil {
|
|
|
|
panic(err)
|
|
|
|
}
|
|
|
|
|
2022-10-17 03:02:19 +00:00
|
|
|
emailing, err := renderer.NewEmailingHandler(cfg)
|
|
|
|
if err != nil {
|
|
|
|
panic(err)
|
|
|
|
}
|
|
|
|
|
2022-10-30 19:11:36 +00:00
|
|
|
apiHandler, _ := api.NewAPIHandler(cfg, idp, svc, kv)
|
2022-10-31 23:40:20 +00:00
|
|
|
applicationHandler, _ := application.NewApplicationHandler(cfg, svc, kv, filestorage, emailing)
|
2022-10-30 19:11:36 +00:00
|
|
|
authHandler, _ := auth.NewAuthHandler(cfg, idp, svc, kv, emailing)
|
2022-08-11 15:26:55 +00:00
|
|
|
|
|
|
|
fmt.Println("Running", service_name, ":")
|
2023-01-30 14:21:08 +00:00
|
|
|
if dev_env {
|
|
|
|
fmt.Printf("\033]0;%s\007", service_name)
|
|
|
|
}
|
2022-08-11 15:26:55 +00:00
|
|
|
|
|
|
|
r := mux.NewRouter()
|
|
|
|
|
|
|
|
r.PathPrefix("/public/").Handler(http.StripPrefix("/public/", http.FileServer(http.Dir(templates_public_dir))))
|
|
|
|
|
2022-10-17 03:02:19 +00:00
|
|
|
r.HandleFunc("/auth/onboarding", authHandler.Onboarding)
|
2023-01-17 07:31:07 +00:00
|
|
|
r.HandleFunc("/auth/disconnect", authHandler.Disconnect)
|
2022-10-30 19:11:36 +00:00
|
|
|
r.HandleFunc("/auth/lost-password", authHandler.LostPasswordInit)
|
|
|
|
r.HandleFunc("/auth/lost-password/recover", authHandler.LostPasswordRecover)
|
2022-08-11 15:26:55 +00:00
|
|
|
r.HandleFunc("/auth/groups/", authHandler.Groups)
|
|
|
|
r.HandleFunc("/auth/groups/switch", authHandler.GroupSwitch)
|
2022-09-05 05:25:05 +00:00
|
|
|
r.HandleFunc("/", redirectApp)
|
2022-08-11 15:26:55 +00:00
|
|
|
|
|
|
|
api_router := r.PathPrefix("/api").Subrouter()
|
|
|
|
api_router.HandleFunc("/", apiHandler.NotFound)
|
|
|
|
api_router.HandleFunc("/geo/autocomplete", apiHandler.GeoAutocomplete)
|
|
|
|
api_router.HandleFunc("/cache/{cacheid}", apiHandler.GetCache)
|
2022-10-30 19:11:36 +00:00
|
|
|
api_router.HandleFunc("/cache/{cacheid}/export", apiHandler.CacheExport)
|
2022-08-11 15:26:55 +00:00
|
|
|
api_router.HandleFunc("/oauth2/callback", apiHandler.OAuth2Callback)
|
|
|
|
|
|
|
|
application := r.PathPrefix("/app").Subrouter()
|
|
|
|
application.HandleFunc("/", applicationHandler.Dashboard)
|
|
|
|
application.HandleFunc("/beneficiaries/", applicationHandler.BeneficiariesList)
|
|
|
|
application.HandleFunc("/beneficiaries/create", applicationHandler.BeneficiaryCreate)
|
|
|
|
application.HandleFunc("/beneficiaries/{beneficiaryid}", applicationHandler.BeneficiaryDisplay)
|
|
|
|
application.HandleFunc("/beneficiaries/{beneficiaryid}/update", applicationHandler.BeneficiaryUpdate)
|
2022-10-31 23:40:20 +00:00
|
|
|
application.HandleFunc("/beneficiaries/{beneficiaryid}/documents", applicationHandler.BeneficiaryDocuments)
|
|
|
|
application.HandleFunc("/beneficiaries/{beneficiaryid}/documents/{document}", applicationHandler.BeneficiaryDocumentDownload)
|
2022-08-11 15:26:55 +00:00
|
|
|
application.HandleFunc("/beneficiaries/{beneficiaryid}/picture", applicationHandler.BeneficiaryPicture)
|
2022-09-05 05:25:05 +00:00
|
|
|
application.HandleFunc("/members/{beneficiaryid}/picture", applicationHandler.BeneficiaryPicture)
|
2023-01-17 07:31:07 +00:00
|
|
|
application.HandleFunc("/members/{adminid}", applicationHandler.MemberDisplay)
|
|
|
|
application.HandleFunc("/members/{adminid}/update", applicationHandler.MemberUpdate)
|
2022-10-17 03:02:19 +00:00
|
|
|
application.HandleFunc("/journeys/", applicationHandler.JourneysSearch)
|
2022-08-12 12:53:54 +00:00
|
|
|
application.HandleFunc("/vehicles/", applicationHandler.VehiclesSearch)
|
2022-09-05 05:25:05 +00:00
|
|
|
application.HandleFunc("/vehicles/bookings/", applicationHandler.VehiclesBookingsList)
|
2022-08-12 12:53:54 +00:00
|
|
|
application.HandleFunc("/vehicles/bookings/{bookingid}", applicationHandler.VehicleBookingDisplay)
|
|
|
|
application.HandleFunc("/vehicles/v/{vehicleid}/b/{beneficiaryid}", applicationHandler.Book)
|
2022-11-01 16:06:12 +00:00
|
|
|
application.HandleFunc("/vehicles/bookings/{bookingid}/documents/{document}", applicationHandler.BookingDocumentDownload)
|
2022-08-11 15:26:55 +00:00
|
|
|
application.HandleFunc("/vehicles-management/", applicationHandler.VehiclesManagementOverview)
|
|
|
|
application.HandleFunc("/vehicles-management/fleet/add", applicationHandler.VehiclesFleetAdd)
|
2022-08-12 12:53:54 +00:00
|
|
|
application.HandleFunc("/vehicles-management/fleet/{vehicleid}", applicationHandler.VehiclesFleetDisplay)
|
2022-11-07 00:24:16 +00:00
|
|
|
application.HandleFunc("/vehicles-management/fleet/{vehicleid}/unavailability", applicationHandler.VehiclesFleetMakeUnavailable)
|
2022-08-12 12:53:54 +00:00
|
|
|
application.HandleFunc("/vehicles-management/fleet/{vehicleid}/update", applicationHandler.VehiclesFleetUpdate)
|
2022-10-31 23:40:20 +00:00
|
|
|
application.HandleFunc("/vehicles-management/bookings/", applicationHandler.VehiclesManagementBookingsList)
|
2022-08-12 12:53:54 +00:00
|
|
|
application.HandleFunc("/vehicles-management/bookings/{bookingid}", applicationHandler.VehicleManagementBookingDisplay)
|
2022-11-01 16:06:12 +00:00
|
|
|
application.HandleFunc("/vehicles-management/bookings/{bookingid}/documents/{document}", applicationHandler.BookingDocumentDownload)
|
2022-09-05 05:25:05 +00:00
|
|
|
application.HandleFunc("/agenda/", applicationHandler.AgendaHome)
|
|
|
|
application.HandleFunc("/agenda/create-event", applicationHandler.AgendaCreateEvent)
|
|
|
|
application.HandleFunc("/agenda/{eventid}", applicationHandler.AgendaDisplayEvent)
|
|
|
|
application.HandleFunc("/agenda/{eventid}/subscribe", applicationHandler.AgendaSubscribeEvent)
|
2022-10-17 03:02:19 +00:00
|
|
|
application.HandleFunc("/directory/", applicationHandler.DirectoryHome)
|
|
|
|
|
|
|
|
application.HandleFunc("/group/settings", applicationHandler.GroupSettingsDisplay)
|
|
|
|
application.HandleFunc("/group/settings/invite-member", applicationHandler.GroupSettingsInviteMember)
|
2022-10-31 09:38:05 +00:00
|
|
|
|
2022-12-07 10:12:43 +00:00
|
|
|
application.HandleFunc("/journeys/groups_covoiturage", applicationHandler.GroupsGestion)
|
|
|
|
application.HandleFunc("/journeys/groups_covoiturage/create", applicationHandler.CreateGroup)
|
|
|
|
application.HandleFunc("/journeys/groups_covoiturage/create/{groupid}", applicationHandler.DisplayGroupCovoiturage)
|
2023-01-17 13:45:09 +00:00
|
|
|
application.HandleFunc("/journeys/groups_covoiturage/create/{id}/{groupid}/{memberid}", applicationHandler.UpdateGroupCovoiturage)
|
2022-12-14 11:18:11 +00:00
|
|
|
|
2022-10-31 09:38:05 +00:00
|
|
|
/********************Code Supprt Emailing************************/
|
|
|
|
application.HandleFunc("/support/", applicationHandler.SupportSend)
|
2022-11-08 11:24:06 +00:00
|
|
|
/*********************** CODE GROUP **************************/
|
2022-12-14 11:18:11 +00:00
|
|
|
|
2022-11-08 11:24:06 +00:00
|
|
|
appGroup := application.PathPrefix("/group_module").Subrouter()
|
|
|
|
appGroup.HandleFunc("/", applicationHandler.Groups)
|
|
|
|
appGroup.HandleFunc("/groups", applicationHandler.CreateGroupModule)
|
|
|
|
appGroup.HandleFunc("/groups/{groupid}", applicationHandler.DisplayGroupModule)
|
2022-10-31 09:38:05 +00:00
|
|
|
|
2022-08-11 15:26:55 +00:00
|
|
|
//TODO Subrouters with middlewares checking security for each module ?
|
|
|
|
application.Use(idp.Middleware)
|
|
|
|
application.Use(idp.GroupsMiddleware)
|
|
|
|
|
|
|
|
appAdmin := application.PathPrefix("/administration").Subrouter()
|
|
|
|
appAdmin.HandleFunc("/", applicationHandler.Administration)
|
|
|
|
appAdmin.HandleFunc("/groups/", applicationHandler.AdministrationCreateGroup)
|
|
|
|
appAdmin.HandleFunc("/groups/{groupid}", applicationHandler.AdministrationGroupDisplay)
|
2022-09-06 13:02:59 +00:00
|
|
|
appAdmin.HandleFunc("/groups/{groupid}/invite-admin", applicationHandler.AdministrationGroupInviteAdmin)
|
2022-10-30 19:11:36 +00:00
|
|
|
appAdmin.HandleFunc("/groups/{groupid}/invite-member", applicationHandler.AdministrationGroupInviteMember)
|
2023-01-17 07:31:07 +00:00
|
|
|
appAdmin.HandleFunc("/stats/vehicles", applicationHandler.AdminStatVehicles)
|
2022-08-11 15:26:55 +00:00
|
|
|
|
|
|
|
fmt.Println("-> HTTP server listening on", address)
|
|
|
|
|
|
|
|
srv := &http.Server{
|
|
|
|
Handler: r,
|
|
|
|
Addr: address,
|
|
|
|
WriteTimeout: 15 * time.Second,
|
|
|
|
ReadTimeout: 15 * time.Second,
|
|
|
|
}
|
|
|
|
|
|
|
|
log.Fatal(srv.ListenAndServe())
|
|
|
|
|
|
|
|
}
|
2022-09-05 05:25:05 +00:00
|
|
|
|
|
|
|
func redirectApp(w http.ResponseWriter, r *http.Request) {
|
|
|
|
http.Redirect(w, r, "/app/", http.StatusFound)
|
|
|
|
}
|