diff --git a/backend/gestion/handlers/auth.go b/backend/gestion/handlers/auth.go index aa53c5c7..e96d47c2 100644 --- a/backend/gestion/handlers/auth.go +++ b/backend/gestion/handlers/auth.go @@ -181,6 +181,11 @@ func RegisterClient(c *gin.Context) { // AdminCreateClient crée un client depuis l'interface admin (sans session ni token) func AdminCreateClient(c *gin.Context) { + if userRole := c.GetString("role"); userRole != "admin" { + c.JSON(http.StatusForbidden, gin.H{"error": "Seul un administrateur peut créer des clients"}) + return + } + var req models.RegisterClientRequest if err := c.ShouldBindJSON(&req); err != nil { log.Printf("❌ [ADMIN_CREATE_CLIENT] Binding error: %v | body: username=%q nom=%q prenom=%q tel=%q", err, req.Username, req.Nom, req.Prenom, req.Telephone) @@ -821,8 +826,8 @@ func CreateUser(c *gin.Context) { return } userRole := c.GetString("role") - if userRole != "cabine" && userRole != "admin" { - c.JSON(http.StatusForbidden, gin.H{"error": "Accès réservé aux livreurs et aux administrateurs"}) + if userRole != "admin" { + c.JSON(http.StatusForbidden, gin.H{"error": "Seul un administrateur peut créer des utilisateurs"}) return } err := database.CreateUser(&user)