dfddd
This commit is contained in:
parent
8152bdb417
commit
2cac603952
@ -13,17 +13,17 @@ import (
|
|||||||
)
|
)
|
||||||
|
|
||||||
|
|
||||||
func Login(w http.ResponseWriter, r *http.Request){
|
func Login(w http.ResponseWriter, r *http.Request,db *gorm.DB){
|
||||||
renderTemplate(w,"login",nil)
|
renderTemplate(w,r,"login",nil,db)
|
||||||
}
|
}
|
||||||
func JwtTest(w http.ResponseWriter, r *http.Request){
|
func JwtTest(w http.ResponseWriter, r *http.Request,db *gorm.DB){
|
||||||
renderTemplate(w,"jwt",nil)
|
renderTemplate(w,r,"jwt",nil,db)
|
||||||
}
|
}
|
||||||
func TestMessagesPages(w http.ResponseWriter, r *http.Request){
|
func TestMessagesPages(w http.ResponseWriter, r *http.Request,db *gorm.DB){
|
||||||
renderTemplate(w,"test-send",nil)
|
renderTemplate(w,r,"test-send",nil,db)
|
||||||
}
|
}
|
||||||
func TestMessagesPages2(w http.ResponseWriter, r *http.Request){
|
func TestMessagesPages2(w http.ResponseWriter, r *http.Request,db *gorm.DB){
|
||||||
renderTemplate(w,"test",nil)
|
renderTemplate(w,r,"test",nil,db)
|
||||||
}
|
}
|
||||||
func AdminUserList(db *gorm.DB) http.HandlerFunc {
|
func AdminUserList(db *gorm.DB) http.HandlerFunc {
|
||||||
return func(w http.ResponseWriter, r *http.Request) {
|
return func(w http.ResponseWriter, r *http.Request) {
|
||||||
@ -38,7 +38,7 @@ func AdminUserList(db *gorm.DB) http.HandlerFunc {
|
|||||||
"Users": users,
|
"Users": users,
|
||||||
}
|
}
|
||||||
|
|
||||||
renderTemplate(w, "admin_users", data)
|
renderTemplate(w,r, "admin_users", data,db)
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
func AdminUserEdit(db *gorm.DB) http.HandlerFunc {
|
func AdminUserEdit(db *gorm.DB) http.HandlerFunc {
|
||||||
@ -110,14 +110,11 @@ func CreateUserHandler(db *gorm.DB) http.HandlerFunc {
|
|||||||
w.Write([]byte("<article class='message is-success'><div class='message-body'>Utilisateur créé avec succès.</div></article>"))
|
w.Write([]byte("<article class='message is-success'><div class='message-body'>Utilisateur créé avec succès.</div></article>"))
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
||||||
func AdminUserCreateForm() http.HandlerFunc {
|
func AdminUserCreateForm() http.HandlerFunc {
|
||||||
return func(w http.ResponseWriter, r *http.Request) {
|
return func(w http.ResponseWriter, r *http.Request) {
|
||||||
renderPartial(w, "admin_user_create", nil)
|
renderPartial(w, "admin_user_create", nil)
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
func AdminUserEditForm(db *gorm.DB) http.HandlerFunc {
|
func AdminUserEditForm(db *gorm.DB) http.HandlerFunc {
|
||||||
return func(w http.ResponseWriter, r *http.Request) {
|
return func(w http.ResponseWriter, r *http.Request) {
|
||||||
id := mux.Vars(r)["id"]
|
id := mux.Vars(r)["id"]
|
||||||
@ -189,21 +186,15 @@ func AdminUserUpdate(db *gorm.DB) http.HandlerFunc {
|
|||||||
w.Write([]byte("<article class='message is-success'><div class='message-body'>Utilisateur mis à jour avec succès.</div></article>"))
|
w.Write([]byte("<article class='message is-success'><div class='message-body'>Utilisateur mis à jour avec succès.</div></article>"))
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
||||||
|
|
||||||
|
|
||||||
|
|
||||||
func AdminConversationPage(db *gorm.DB) http.HandlerFunc {
|
func AdminConversationPage(db *gorm.DB) http.HandlerFunc {
|
||||||
return func(w http.ResponseWriter, r *http.Request) {
|
return func(w http.ResponseWriter, r *http.Request) {
|
||||||
idStr := mux.Vars(r)["id"]
|
idStr := mux.Vars(r)["id"]
|
||||||
data := map[string]interface{}{
|
data := map[string]interface{}{
|
||||||
"UserID": idStr,
|
"UserID": idStr,
|
||||||
}
|
}
|
||||||
renderTemplate(w, "adminconversations", data)
|
renderTemplate(w,r, "adminconversations", data,db)
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
func AdminConversationRows(db *gorm.DB) http.HandlerFunc {
|
func AdminConversationRows(db *gorm.DB) http.HandlerFunc {
|
||||||
return func(w http.ResponseWriter, r *http.Request) {
|
return func(w http.ResponseWriter, r *http.Request) {
|
||||||
// 1. Récupérer SSOID depuis le contexte
|
// 1. Récupérer SSOID depuis le contexte
|
||||||
@ -264,9 +255,6 @@ func AdminConversationRows(db *gorm.DB) http.HandlerFunc {
|
|||||||
renderPartial(w, "admin_conversations_rows", data)
|
renderPartial(w, "admin_conversations_rows", data)
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
||||||
|
|
||||||
func AdminConversationThread(db *gorm.DB) http.HandlerFunc {
|
func AdminConversationThread(db *gorm.DB) http.HandlerFunc {
|
||||||
return func(w http.ResponseWriter, r *http.Request) {
|
return func(w http.ResponseWriter, r *http.Request) {
|
||||||
idStr := mux.Vars(r)["id"]
|
idStr := mux.Vars(r)["id"]
|
||||||
@ -338,32 +326,45 @@ func Dashboard(db *gorm.DB) http.HandlerFunc {
|
|||||||
"Conversations": conversations,
|
"Conversations": conversations,
|
||||||
}
|
}
|
||||||
|
|
||||||
renderTemplate(w, "dashboard", data)
|
renderTemplate(w,r ,"dashboard", data,db)
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
||||||
|
|
||||||
func renderTemplate(w http.ResponseWriter, templ string, data map[string]interface{}) {
|
func renderTemplate(w http.ResponseWriter, r *http.Request, templ string, data map[string]interface{}, db *gorm.DB) {
|
||||||
|
// Initialiser la map si elle est nil
|
||||||
|
if data == nil {
|
||||||
|
data = make(map[string]interface{})
|
||||||
|
}
|
||||||
|
|
||||||
|
// Si "User" absent mais SSOID présent dans le contexte, on charge l'utilisateur
|
||||||
|
if _, exists := data["User"]; !exists {
|
||||||
|
if val := r.Context().Value("ssoid"); val != nil {
|
||||||
|
ssoid := val.(string)
|
||||||
|
var user models.User
|
||||||
|
if err := db.Where("sso_id = ?", ssoid).First(&user).Error; err == nil {
|
||||||
|
data["User"] = user
|
||||||
|
}
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
t, err := template.ParseFiles(
|
t, err := template.ParseFiles(
|
||||||
"./frontend/templates/head.pages.tmpl",
|
"./frontend/templates/head.pages.tmpl",
|
||||||
"./frontend/templates/sidebar.pages.tmpl",
|
"./frontend/templates/sidebar.pages.tmpl",
|
||||||
"./frontend/templates/" + templ + ".pages.tmpl",
|
"./frontend/templates/" + templ + ".pages.tmpl",
|
||||||
)
|
)
|
||||||
|
|
||||||
if err != nil {
|
if err != nil {
|
||||||
http.Error(w, err.Error(), http.StatusInternalServerError)
|
http.Error(w, err.Error(), http.StatusInternalServerError)
|
||||||
return
|
return
|
||||||
}
|
}
|
||||||
|
|
||||||
// Exécutez explicitement le template principal
|
if err := t.ExecuteTemplate(w, templ+".pages.tmpl", data); err != nil {
|
||||||
err = t.ExecuteTemplate(w, templ+".pages.tmpl", data)
|
|
||||||
|
|
||||||
if err != nil {
|
|
||||||
http.Error(w, err.Error(), http.StatusInternalServerError)
|
http.Error(w, err.Error(), http.StatusInternalServerError)
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
||||||
func renderPartial(w http.ResponseWriter, templ string, data map[string]interface{}) {
|
func renderPartial(w http.ResponseWriter, templ string, data map[string]interface{}) {
|
||||||
t, err := template.ParseFiles("./frontend/templates/" + templ + ".pages.tmpl")
|
t, err := template.ParseFiles("./frontend/templates/" + templ + ".pages.tmpl")
|
||||||
if err != nil {
|
if err != nil {
|
||||||
|
|||||||
@ -11,41 +11,67 @@ import (
|
|||||||
|
|
||||||
// Routes non protégées
|
// Routes non protégées
|
||||||
func RoutesPublic(r *mux.Router, db *gorm.DB) {
|
func RoutesPublic(r *mux.Router, db *gorm.DB) {
|
||||||
|
// Assets statiques
|
||||||
// Fichiers statiques (CSS, JS, etc.)
|
|
||||||
staticDir := "./frontend/assets/"
|
staticDir := "./frontend/assets/"
|
||||||
r.PathPrefix("/frontend/assets/").Handler(
|
r.PathPrefix("/frontend/assets/").Handler(
|
||||||
http.StripPrefix("/frontend/assets/", http.FileServer(http.Dir(staticDir))),
|
http.StripPrefix("/frontend/assets/", http.FileServer(http.Dir(staticDir))),
|
||||||
)
|
)
|
||||||
|
|
||||||
// Page de login
|
// Login
|
||||||
r.HandleFunc("/login", renders.Login)
|
r.HandleFunc("/login", func(w http.ResponseWriter, r *http.Request) {
|
||||||
r.HandleFunc("/api/whatsapp/webhook", handlers.WebhookVerifyHandler()).Methods("GET")
|
renders.Login(w, r, db)
|
||||||
r.HandleFunc("/api/whatsapp/webhook", handlers.WebhookReceiveHandler(db)).Methods("POST")
|
})
|
||||||
|
|
||||||
// Endpoint d'API pour se logger
|
|
||||||
r.HandleFunc("/api/login", handlers.LoginHandler(db)).Methods("POST")
|
r.HandleFunc("/api/login", handlers.LoginHandler(db)).Methods("POST")
|
||||||
|
|
||||||
|
// Webhook WhatsApp (vérification + réception)
|
||||||
|
r.HandleFunc("/api/whatsapp/webhook", handlers.WebhookVerifyHandler()).Methods("GET")
|
||||||
|
r.HandleFunc("/api/whatsapp/webhook", handlers.WebhookReceiveHandler(db)).Methods("POST")
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
||||||
// Routes protégées
|
// Routes protégées
|
||||||
func RoutesProtected(r *mux.Router, db *gorm.DB) {
|
func RoutesProtected(r *mux.Router, db *gorm.DB) {
|
||||||
r.HandleFunc("/jwt", renders.JwtTest)
|
// Dashboard (admin ou client)
|
||||||
r.HandleFunc("/api/message/send", handlers.SendWhatsAppMessage(db)).Methods("POST")
|
r.HandleFunc("/dashboard", func(w http.ResponseWriter, r *http.Request) {
|
||||||
r.HandleFunc("/admin/user/{id}/conversations", renders.AdminConversationPage(db))
|
renders.Dashboard(db)
|
||||||
r.HandleFunc("/api/user/{id}/conversations", renders.AdminConversationRows(db))
|
})
|
||||||
r.HandleFunc("/admin/user/{id}/edit", renders.AdminUserEdit(db)).Methods("GET")
|
|
||||||
r.HandleFunc("/admin/user", renders.AdminUserList(db))
|
|
||||||
r.HandleFunc("/api/user/delete/{id}", handlers.AdminUserDelete(db)).Methods("DELETE")
|
|
||||||
r.HandleFunc("/api/user/update/{id}", renders.AdminUserUpdate(db)).Methods("PUT")
|
|
||||||
r.HandleFunc("/api/user/create", renders.CreateUserHandler(db)).Methods("POST")
|
|
||||||
r.HandleFunc("/admin/user/create-form", renders.AdminUserCreateForm()).Methods("GET")
|
|
||||||
|
|
||||||
r.HandleFunc("/dashboard", renders.Dashboard(db))
|
// Test d'envoi de message (simples & templates)
|
||||||
r.HandleFunc("/test/send", renders.TestMessagesPages)
|
r.HandleFunc("/test/send", func(w http.ResponseWriter, r *http.Request) {renders.TestMessagesPages(w, r, db)})
|
||||||
r.HandleFunc("/test/send2", renders.TestMessagesPages2)
|
r.HandleFunc("/test/send2", func(w http.ResponseWriter, r *http.Request) {renders.TestMessagesPages2(w, r, db)})
|
||||||
r.HandleFunc("/admin/user/{id}/conversation-thread", renders.AdminConversationThread(db)).Methods("GET")
|
r.HandleFunc("/api/message/send", handlers.SendWhatsAppMessage(db)).Methods("POST")
|
||||||
r.HandleFunc("/api/message/send2", handlers.HandleTemplateTest(db)).Methods("POST")
|
r.HandleFunc("/api/message/send2", handlers.HandleTemplateTest(db)).Methods("POST")
|
||||||
|
|
||||||
|
// Conversations (admin/client)
|
||||||
|
r.HandleFunc("/admin/user/{id}/conversations", func(w http.ResponseWriter, r *http.Request) {
|
||||||
|
renders.AdminConversationPage(db)
|
||||||
|
})
|
||||||
|
r.HandleFunc("/api/user/{id}/conversations", func(w http.ResponseWriter, r *http.Request) {
|
||||||
|
renders.AdminConversationRows(db)
|
||||||
|
})
|
||||||
|
r.HandleFunc("/admin/user/{id}/conversation-thread", func(w http.ResponseWriter, r *http.Request) {
|
||||||
|
renders.AdminConversationThread(db)
|
||||||
|
})
|
||||||
|
|
||||||
|
// Utilisateurs (admin)
|
||||||
|
r.HandleFunc("/admin/user", func(w http.ResponseWriter, r *http.Request) {
|
||||||
|
renders.AdminUserList(db)
|
||||||
|
})
|
||||||
|
r.HandleFunc("/admin/user/create-form", renders.AdminUserCreateForm()).Methods("GET")
|
||||||
|
r.HandleFunc("/admin/user/{id}/edit", func(w http.ResponseWriter, r *http.Request) {
|
||||||
|
renders.AdminUserEdit(db)
|
||||||
|
}).Methods("GET")
|
||||||
|
|
||||||
|
r.HandleFunc("/api/user/create", renders.CreateUserHandler(db)).Methods("POST")
|
||||||
|
r.HandleFunc("/api/user/update/{id}", func(w http.ResponseWriter, r *http.Request) {
|
||||||
|
renders.AdminUserUpdate(db)
|
||||||
|
}).Methods("PUT")
|
||||||
|
r.HandleFunc("/api/user/delete/{id}", handlers.AdminUserDelete(db)).Methods("DELETE")
|
||||||
|
|
||||||
|
// Test JWT
|
||||||
|
r.HandleFunc("/jwt", func(w http.ResponseWriter, r *http.Request){renders.JwtTest(w, r, db)})
|
||||||
|
|
||||||
|
// Déconnexion
|
||||||
r.HandleFunc("/logout", func(w http.ResponseWriter, r *http.Request) {
|
r.HandleFunc("/logout", func(w http.ResponseWriter, r *http.Request) {
|
||||||
http.SetCookie(w, &http.Cookie{
|
http.SetCookie(w, &http.Cookie{
|
||||||
Name: "token",
|
Name: "token",
|
||||||
@ -56,35 +82,4 @@ func RoutesProtected(r *mux.Router, db *gorm.DB) {
|
|||||||
})
|
})
|
||||||
http.Redirect(w, r, "/login", http.StatusSeeOther)
|
http.Redirect(w, r, "/login", http.StatusSeeOther)
|
||||||
})
|
})
|
||||||
|
|
||||||
|
|
||||||
|
|
||||||
// // Ici on place les vues et API qui doivent être protégées
|
|
||||||
// r.HandleFunc("/stream", StreamHandler)
|
|
||||||
// r.HandleFunc("/dashboard", renders.Dashboard(bd))
|
|
||||||
// r.HandleFunc("/settings", renders.Settings)
|
|
||||||
// r.HandleFunc("/library", renders.Library)
|
|
||||||
// r.HandleFunc("/menuLibary", renders.Library)
|
|
||||||
// r.HandleFunc("/godownloader/downloads", renders.GoDownload)
|
|
||||||
// r.HandleFunc("/godownloader/linkcollectors", renders.GoDownloadLinkCollectors)
|
|
||||||
// r.HandleFunc("/godownloader/settings", renders.GoDownloadSetting)
|
|
||||||
// // API user
|
|
||||||
// r.HandleFunc("/api/user/create", users.CreateUser(bd)).Methods("POST")
|
|
||||||
// r.HandleFunc("/api/user/update/{id}", users.UpdateUser(bd)).Methods("PUT")
|
|
||||||
// r.HandleFunc("/api/user/delete/{id}", users.DeleteUser(bd)).Methods("DELETE")
|
|
||||||
// r.HandleFunc("/api/user/all/", users.ReadAllUser(bd)).Methods("GET")
|
|
||||||
// r.HandleFunc("/api/user/{id}", users.FindUserById(bd)).Methods("GET")
|
|
||||||
|
|
||||||
// // API download
|
|
||||||
// r.HandleFunc("/api/pathDownload/create", download.CreateSavePath(bd)).Methods("POST")
|
|
||||||
// r.HandleFunc("/api/pathDownload/update/{id}", download.UpdateSavePath(bd)).Methods("PUT")
|
|
||||||
// r.HandleFunc("/api/pathDownload/delete/{id}", download.DeleteSavePath(bd)).Methods("DELETE")
|
|
||||||
// r.HandleFunc("/api/pathDownload/all/", download.ReadAllSavePath(bd)).Methods("GET")
|
|
||||||
|
|
||||||
// //API Check path
|
|
||||||
// r.HandleFunc("/validate-path", download.PathValidationHandler)
|
|
||||||
|
|
||||||
//API Scan folder
|
|
||||||
|
|
||||||
|
|
||||||
}
|
}
|
||||||
Loading…
Reference in New Issue
Block a user