documentations
This commit is contained in:
parent
c92e746334
commit
973c48295b
@ -16,8 +16,7 @@ import (
|
|||||||
"golang.org/x/crypto/bcrypt"
|
"golang.org/x/crypto/bcrypt"
|
||||||
"gorm.io/gorm"
|
"gorm.io/gorm"
|
||||||
)
|
)
|
||||||
|
// login fonction
|
||||||
// Simuler un SSO + Redirection selon rôle
|
|
||||||
func LoginHandler(db *gorm.DB) http.HandlerFunc {
|
func LoginHandler(db *gorm.DB) http.HandlerFunc {
|
||||||
return func(w http.ResponseWriter, r *http.Request) {
|
return func(w http.ResponseWriter, r *http.Request) {
|
||||||
w.Header().Set("Content-Type", "application/json")
|
w.Header().Set("Content-Type", "application/json")
|
||||||
@ -93,6 +92,7 @@ func SSOLoginHandler(db *gorm.DB) http.HandlerFunc {
|
|||||||
http.Redirect(w, r, "/dashboard", http.StatusSeeOther)
|
http.Redirect(w, r, "/dashboard", http.StatusSeeOther)
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
// sso connection
|
||||||
func SSOLoginPostHandler(db *gorm.DB) http.HandlerFunc {
|
func SSOLoginPostHandler(db *gorm.DB) http.HandlerFunc {
|
||||||
return func(w http.ResponseWriter, r *http.Request) {
|
return func(w http.ResponseWriter, r *http.Request) {
|
||||||
var body struct {
|
var body struct {
|
||||||
@ -203,6 +203,7 @@ func WebhookHandler(db *gorm.DB) http.HandlerFunc {
|
|||||||
w.WriteHeader(http.StatusOK)
|
w.WriteHeader(http.StatusOK)
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
// fonction pour extraire les message
|
||||||
func extractMessageContent(m map[string]interface{}) string {
|
func extractMessageContent(m map[string]interface{}) string {
|
||||||
t := m["type"].(string)
|
t := m["type"].(string)
|
||||||
switch t {
|
switch t {
|
||||||
@ -361,7 +362,11 @@ func WebhookReceiveHandler(db *gorm.DB) http.HandlerFunc {
|
|||||||
w.WriteHeader(http.StatusOK)
|
w.WriteHeader(http.StatusOK)
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
/*
|
||||||
|
*
|
||||||
|
* Block pour le crud user/ client
|
||||||
|
*
|
||||||
|
*/
|
||||||
|
|
||||||
func CreateUser(db *gorm.DB) http.HandlerFunc {
|
func CreateUser(db *gorm.DB) http.HandlerFunc {
|
||||||
return func(w http.ResponseWriter, r *http.Request) {
|
return func(w http.ResponseWriter, r *http.Request) {
|
||||||
@ -444,6 +449,29 @@ func DeleteUser(db *gorm.DB) http.HandlerFunc {
|
|||||||
w.WriteHeader(http.StatusNoContent)
|
w.WriteHeader(http.StatusNoContent)
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
func AdminUserDelete(db *gorm.DB) http.HandlerFunc {
|
||||||
|
return func(w http.ResponseWriter, r *http.Request) {
|
||||||
|
id := mux.Vars(r)["id"]
|
||||||
|
|
||||||
|
var user models.User
|
||||||
|
if err := db.Unscoped().First(&user, id).Error; err != nil {
|
||||||
|
http.Error(w, "Utilisateur introuvable", http.StatusNotFound)
|
||||||
|
return
|
||||||
|
}
|
||||||
|
|
||||||
|
// Suppression définitive
|
||||||
|
if err := db.Unscoped().Delete(&user).Error; err != nil {
|
||||||
|
http.Error(w, "Erreur suppression", http.StatusInternalServerError)
|
||||||
|
return
|
||||||
|
}
|
||||||
|
|
||||||
|
w.WriteHeader(http.StatusOK)
|
||||||
|
w.Write([]byte(""))
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
|
||||||
|
// function pour l envoie des messages par template.
|
||||||
func HandleTemplateTest(db *gorm.DB) http.HandlerFunc {
|
func HandleTemplateTest(db *gorm.DB) http.HandlerFunc {
|
||||||
return func(w http.ResponseWriter, r *http.Request) {
|
return func(w http.ResponseWriter, r *http.Request) {
|
||||||
val := r.Context().Value("ssoid")
|
val := r.Context().Value("ssoid")
|
||||||
@ -522,6 +550,7 @@ func HandleTemplateTest(db *gorm.DB) http.HandlerFunc {
|
|||||||
json.NewEncoder(w).Encode(respBody)
|
json.NewEncoder(w).Encode(respBody)
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
// function pour envoie de message sans template. ne peux fonctionner que si le receveur a repondu
|
||||||
func SendWhatsAppMessage(db *gorm.DB) http.HandlerFunc {
|
func SendWhatsAppMessage(db *gorm.DB) http.HandlerFunc {
|
||||||
return func(w http.ResponseWriter, r *http.Request) {
|
return func(w http.ResponseWriter, r *http.Request) {
|
||||||
val := r.Context().Value("ssoid")
|
val := r.Context().Value("ssoid")
|
||||||
@ -597,26 +626,6 @@ func SendWhatsAppMessage(db *gorm.DB) http.HandlerFunc {
|
|||||||
w.Write(respBody)
|
w.Write(respBody)
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
func AdminUserDelete(db *gorm.DB) http.HandlerFunc {
|
|
||||||
return func(w http.ResponseWriter, r *http.Request) {
|
|
||||||
id := mux.Vars(r)["id"]
|
|
||||||
|
|
||||||
var user models.User
|
|
||||||
if err := db.Unscoped().First(&user, id).Error; err != nil {
|
|
||||||
http.Error(w, "Utilisateur introuvable", http.StatusNotFound)
|
|
||||||
return
|
|
||||||
}
|
|
||||||
|
|
||||||
// Suppression définitive
|
|
||||||
if err := db.Unscoped().Delete(&user).Error; err != nil {
|
|
||||||
http.Error(w, "Erreur suppression", http.StatusInternalServerError)
|
|
||||||
return
|
|
||||||
}
|
|
||||||
|
|
||||||
w.WriteHeader(http.StatusOK)
|
|
||||||
w.Write([]byte(""))
|
|
||||||
}
|
|
||||||
}
|
|
||||||
|
|
||||||
|
|
||||||
|
|
||||||
|
|||||||
@ -11,7 +11,7 @@ import (
|
|||||||
"golang.org/x/crypto/bcrypt"
|
"golang.org/x/crypto/bcrypt"
|
||||||
"gorm.io/gorm"
|
"gorm.io/gorm"
|
||||||
)
|
)
|
||||||
|
// les renders permette d afficher les pages html.
|
||||||
|
|
||||||
func Login(w http.ResponseWriter, r *http.Request){
|
func Login(w http.ResponseWriter, r *http.Request){
|
||||||
renderTemplate(w,"login",nil)
|
renderTemplate(w,"login",nil)
|
||||||
@ -460,7 +460,7 @@ func Dashboard(db *gorm.DB) http.HandlerFunc {
|
|||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
|
// pour un rendu complet de la page
|
||||||
func renderTemplate(w http.ResponseWriter, templ string, data map[string]interface{}) {
|
func renderTemplate(w http.ResponseWriter, templ string, data map[string]interface{}) {
|
||||||
t, err := template.ParseFiles(
|
t, err := template.ParseFiles(
|
||||||
"./frontend/templates/head.pages.tmpl",
|
"./frontend/templates/head.pages.tmpl",
|
||||||
@ -480,7 +480,7 @@ func renderTemplate(w http.ResponseWriter, templ string, data map[string]interfa
|
|||||||
http.Error(w, err.Error(), http.StatusInternalServerError)
|
http.Error(w, err.Error(), http.StatusInternalServerError)
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
// pour un rendu de composent.
|
||||||
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 {
|
||||||
|
|||||||
@ -88,34 +88,5 @@ func RoutesPublic(r *mux.Router, db *gorm.DB) {
|
|||||||
})
|
})
|
||||||
|
|
||||||
r.HandleFunc("/apidoc", renders.ApiDocPage(db))
|
r.HandleFunc("/apidoc", renders.ApiDocPage(db))
|
||||||
|
|
||||||
|
|
||||||
// // 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