chore: fix UI
This commit is contained in:
@@ -9,7 +9,6 @@ import (
|
||||
"log"
|
||||
"net/http"
|
||||
"strconv"
|
||||
"strings"
|
||||
|
||||
"github.com/gin-gonic/gin"
|
||||
"golang.org/x/crypto/bcrypt"
|
||||
@@ -33,7 +32,7 @@ func UpdateMyProfile(c *gin.Context) {
|
||||
if err := c.ShouldBindJSON(&req); err != nil {
|
||||
log.Printf("❌ [UPDATE_MY_PROFILE] Erreur binding: %v", err)
|
||||
c.JSON(http.StatusBadRequest, gin.H{
|
||||
"error": "Données invalides",
|
||||
"error": "Données invalides",
|
||||
})
|
||||
return
|
||||
}
|
||||
@@ -50,13 +49,21 @@ func UpdateMyProfile(c *gin.Context) {
|
||||
hasChanges := false
|
||||
|
||||
// Mise à jour du username
|
||||
if req.Username != "" {
|
||||
req.Username = utils.StripHTML(req.Username)
|
||||
}
|
||||
if req.Username != "" && req.Username != client.Username {
|
||||
// Vérifier que le nouveau username n'existe pas
|
||||
// Vérifier que le nouveau username n'existe pas (clients et users)
|
||||
if existingClient, _ := database.GetClientByUsername(req.Username); existingClient != nil {
|
||||
log.Printf("❌ [UPDATE_MY_PROFILE] Username déjà utilisé: %s", req.Username)
|
||||
c.JSON(http.StatusConflict, gin.H{"error": "Nom d'utilisateur déjà utilisé"})
|
||||
return
|
||||
}
|
||||
if existingUser, _ := database.GetUserByUsername(req.Username); existingUser != nil {
|
||||
log.Printf("❌ [UPDATE_MY_PROFILE] Username réservé: %s", req.Username)
|
||||
c.JSON(http.StatusConflict, gin.H{"error": "Nom d'utilisateur déjà utilisé"})
|
||||
return
|
||||
}
|
||||
client.Username = req.Username
|
||||
hasChanges = true
|
||||
}
|
||||
@@ -78,22 +85,28 @@ func UpdateMyProfile(c *gin.Context) {
|
||||
}
|
||||
|
||||
// Mise à jour du nom
|
||||
if req.Nom != "" {
|
||||
req.Nom = utils.StripHTML(req.Nom)
|
||||
}
|
||||
if req.Nom != "" && req.Nom != client.Nom {
|
||||
if len(strings.TrimSpace(req.Nom)) < 2 {
|
||||
if len(req.Nom) < 2 {
|
||||
c.JSON(http.StatusBadRequest, gin.H{"error": "Le nom doit contenir au moins 2 caractères"})
|
||||
return
|
||||
}
|
||||
client.Nom = strings.TrimSpace(req.Nom)
|
||||
client.Nom = req.Nom
|
||||
hasChanges = true
|
||||
}
|
||||
|
||||
// Mise à jour du prénom
|
||||
if req.Prenom != "" {
|
||||
req.Prenom = utils.StripHTML(req.Prenom)
|
||||
}
|
||||
if req.Prenom != "" && req.Prenom != client.Prenom {
|
||||
if len(strings.TrimSpace(req.Prenom)) < 2 {
|
||||
if len(req.Prenom) < 2 {
|
||||
c.JSON(http.StatusBadRequest, gin.H{"error": "Le prénom doit contenir au moins 2 caractères"})
|
||||
return
|
||||
}
|
||||
client.Prenom = strings.TrimSpace(req.Prenom)
|
||||
client.Prenom = req.Prenom
|
||||
hasChanges = true
|
||||
}
|
||||
|
||||
@@ -184,7 +197,7 @@ func UpdateClientByAdmin(c *gin.Context) {
|
||||
if err := c.ShouldBindJSON(&req); err != nil {
|
||||
log.Printf("❌ [UPDATE_CLIENT_ADMIN] Erreur binding: %v", err)
|
||||
c.JSON(http.StatusBadRequest, gin.H{
|
||||
"error": "Données invalides",
|
||||
"error": "Données invalides",
|
||||
})
|
||||
return
|
||||
}
|
||||
@@ -208,6 +221,9 @@ func UpdateClientByAdmin(c *gin.Context) {
|
||||
hasChanges := false
|
||||
|
||||
// Mise à jour du username
|
||||
if req.Username != "" {
|
||||
req.Username = utils.StripHTML(req.Username)
|
||||
}
|
||||
if req.Username != "" && req.Username != client.Username {
|
||||
// Vérifier que le nouveau username n'existe pas
|
||||
if existingClient, _ := database.GetClientByUsername(req.Username); existingClient != nil {
|
||||
@@ -238,15 +254,21 @@ func UpdateClientByAdmin(c *gin.Context) {
|
||||
}
|
||||
|
||||
// Mise à jour du nom
|
||||
if req.Nom != "" {
|
||||
req.Nom = utils.StripHTML(req.Nom)
|
||||
}
|
||||
if req.Nom != "" && req.Nom != client.Nom {
|
||||
client.Nom = strings.TrimSpace(req.Nom)
|
||||
client.Nom = req.Nom
|
||||
hasChanges = true
|
||||
log.Printf("✏️ [UPDATE_CLIENT_ADMIN] Nom modifié: %s", req.Nom)
|
||||
}
|
||||
|
||||
// Mise à jour du prénom
|
||||
if req.Prenom != "" {
|
||||
req.Prenom = utils.StripHTML(req.Prenom)
|
||||
}
|
||||
if req.Prenom != "" && req.Prenom != client.Prenom {
|
||||
client.Prenom = strings.TrimSpace(req.Prenom)
|
||||
client.Prenom = req.Prenom
|
||||
hasChanges = true
|
||||
log.Printf("✏️ [UPDATE_CLIENT_ADMIN] Prénom modifié: %s", req.Prenom)
|
||||
}
|
||||
@@ -277,10 +299,16 @@ func UpdateClientByAdmin(c *gin.Context) {
|
||||
log.Printf("✏️ [UPDATE_CLIENT_ADMIN] Commandes modifiées: %d → %d", client.Command, *req.Command)
|
||||
}
|
||||
|
||||
if req.Amende != nil && *req.Amende != client.Amende {
|
||||
client.Amende = *req.Amende
|
||||
hasChanges = true
|
||||
log.Printf("✏️ [UPDATE_CLIENT_ADMIN] Amendes modifiées: %.2f → %.2f", client.Amende, *req.Amende)
|
||||
if req.Amende != nil {
|
||||
if *req.Amende < 0 {
|
||||
c.JSON(http.StatusBadRequest, gin.H{"error": "L'amende ne peut pas être négative"})
|
||||
return
|
||||
}
|
||||
if *req.Amende != client.Amende {
|
||||
client.Amende = *req.Amende
|
||||
hasChanges = true
|
||||
log.Printf("✏️ [UPDATE_CLIENT_ADMIN] Amendes modifiées: %.2f → %.2f", client.Amende, *req.Amende)
|
||||
}
|
||||
}
|
||||
|
||||
if !hasChanges {
|
||||
@@ -353,13 +381,21 @@ func UpdateUserByAdmin(c *gin.Context) {
|
||||
hasChanges := false
|
||||
|
||||
// Mise à jour du username
|
||||
if req.Username != "" {
|
||||
req.Username = utils.StripHTML(req.Username)
|
||||
}
|
||||
if req.Username != "" && req.Username != user.Username {
|
||||
// Vérifier que le nouveau username n'existe pas
|
||||
// Vérifier que le nouveau username n'existe pas (users et clients)
|
||||
if existingUser, _ := database.GetUserByUsername(req.Username); existingUser != nil {
|
||||
log.Printf("❌ [UPDATE_USER_ADMIN] Username déjà utilisé: %s", req.Username)
|
||||
c.JSON(http.StatusConflict, gin.H{"error": "Nom d'utilisateur déjà utilisé"})
|
||||
return
|
||||
}
|
||||
if existingClient, _ := database.GetClientByUsername(req.Username); existingClient != nil {
|
||||
log.Printf("❌ [UPDATE_USER_ADMIN] Username réservé: %s", req.Username)
|
||||
c.JSON(http.StatusConflict, gin.H{"error": "Nom d'utilisateur déjà utilisé"})
|
||||
return
|
||||
}
|
||||
user.Username = req.Username
|
||||
hasChanges = true
|
||||
}
|
||||
|
||||
Reference in New Issue
Block a user