2025-05-09 08:14:22 +00:00
|
|
|
package routes
|
|
|
|
|
|
|
|
|
|
import (
|
|
|
|
|
"cangui/whatsapp/backend/handlers"
|
|
|
|
|
"cangui/whatsapp/backend/renders"
|
|
|
|
|
"net/http"
|
|
|
|
|
|
|
|
|
|
"github.com/gorilla/mux"
|
|
|
|
|
"gorm.io/gorm"
|
|
|
|
|
)
|
|
|
|
|
|
|
|
|
|
// Routes non protégées
|
|
|
|
|
func RoutesPublic(r *mux.Router, db *gorm.DB) {
|
|
|
|
|
|
|
|
|
|
// Fichiers statiques (CSS, JS, etc.)
|
|
|
|
|
staticDir := "./frontend/assets/"
|
|
|
|
|
r.PathPrefix("/frontend/assets/").Handler(
|
|
|
|
|
http.StripPrefix("/frontend/assets/", http.FileServer(http.Dir(staticDir))),
|
|
|
|
|
)
|
|
|
|
|
|
|
|
|
|
// Page de login
|
|
|
|
|
r.HandleFunc("/login", renders.Login)
|
|
|
|
|
r.HandleFunc("/api/whatsapp/webhook", handlers.WebhookVerifyHandler()).Methods("GET")
|
2025-05-09 08:52:26 +00:00
|
|
|
r.HandleFunc("/api/whatsapp/webhook", handlers.WebhookReceiveHandler(db)).Methods("POST")
|
2025-05-09 08:14:22 +00:00
|
|
|
|
|
|
|
|
// Endpoint d'API pour se logger
|
|
|
|
|
r.HandleFunc("/api/login", handlers.LoginHandler(db)).Methods("POST")
|
|
|
|
|
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
// Routes protégées
|
|
|
|
|
func RoutesProtected(r *mux.Router, db *gorm.DB) {
|
|
|
|
|
r.HandleFunc("/jwt", renders.JwtTest)
|
|
|
|
|
r.HandleFunc("/api/message/send", handlers.SendWhatsAppMessage(db)).Methods("POST")
|
|
|
|
|
r.HandleFunc("/admin/user/{id}/conversations", renders.AdminConversationPage(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/new", renders.AdminUserCreate()).Methods("GET")
|
2025-05-09 15:09:51 +00:00
|
|
|
r.HandleFunc("/admin/user", renders.AdminUserList(db))
|
|
|
|
|
|
2025-05-09 08:14:22 +00:00
|
|
|
r.HandleFunc("/dashboard", renders.Dashboard(db))
|
|
|
|
|
r.HandleFunc("/test/send", renders.TestMessagesPages)
|
2025-05-09 09:27:52 +00:00
|
|
|
r.HandleFunc("/test/send2", renders.TestMessagesPages2)
|
2025-05-09 13:45:48 +00:00
|
|
|
r.HandleFunc("/admin/user/{id}/conversation-thread", renders.AdminConversationThread(db)).Methods("GET")
|
2025-05-09 13:12:48 +00:00
|
|
|
r.HandleFunc("/api/message/send2", handlers.HandleTemplateTest(db)).Methods("POST")
|
2025-05-09 14:51:23 +00:00
|
|
|
r.HandleFunc("/logout", func(w http.ResponseWriter, r *http.Request) {
|
|
|
|
|
http.SetCookie(w, &http.Cookie{
|
|
|
|
|
Name: "token",
|
|
|
|
|
Value: "",
|
|
|
|
|
Path: "/",
|
|
|
|
|
MaxAge: -1,
|
|
|
|
|
HttpOnly: true,
|
|
|
|
|
})
|
|
|
|
|
http.Redirect(w, r, "/login", http.StatusSeeOther)
|
|
|
|
|
})
|
|
|
|
|
|
2025-05-09 08:14:22 +00:00
|
|
|
|
|
|
|
|
|
|
|
|
|
// // 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
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
}
|