chore: fix updates

This commit is contained in:
2026-03-01 17:30:08 +01:00
parent 2fad63c28d
commit bb8dee3406
9 changed files with 226 additions and 19 deletions
+24 -1
View File
@@ -178,6 +178,28 @@ func (d *Database) UpdateClientPassword(clientID int, hashedPassword string) err
return nil
}
// UpdateClientPasswordAndClearFlag met à jour le mot de passe et remet must_change_password à false
func (d *Database) UpdateClientPasswordAndClearFlag(clientID int, hashedPassword string) error {
query := `UPDATE clients SET password = $1, must_change_password = FALSE, updated_at = CURRENT_TIMESTAMP WHERE id = $2`
result, err := d.Exec(query, hashedPassword, clientID)
if err != nil {
return fmt.Errorf("erreur lors de la mise à jour du mot de passe: %w", err)
}
rowsAffected, err := result.RowsAffected()
if err != nil {
return fmt.Errorf("erreur lors de la vérification: %w", err)
}
if rowsAffected == 0 {
return fmt.Errorf("client non trouvé")
}
log.Printf("✅ Mot de passe client mis à jour + must_change_password=false (ID: %d)", clientID)
return nil
}
// GetClientStats récupère les statistiques d'un client
func (d *Database) GetClientStats(clientID int) (map[string]interface{}, error) {
client, err := d.GetClientByID(clientID)
@@ -369,7 +391,7 @@ func (d *Database) GetClientByTelephone(telephone string) (*models.Client, error
// GetClientByUsername récupère un client par son username
func (d *Database) GetClientByUsername(username string) (*models.Client, error) {
client := &models.Client{}
query := `SELECT id, username, password, nom, prenom, telephone, command, point, point_zipette, amende, created_at
query := `SELECT id, username, password, nom, prenom, telephone, command, point, point_zipette, amende, must_change_password, created_at
FROM clients WHERE username = $1`
err := d.QueryRow(query, username).Scan(
@@ -383,6 +405,7 @@ func (d *Database) GetClientByUsername(username string) (*models.Client, error)
&client.Point,
&client.PointZipette,
&client.Amende,
&client.MustChangePassword,
&client.CreatedAt,
)
+5
View File
@@ -71,6 +71,11 @@ func InitDB() *Database {
log.Println("✅ Tables créées avec succès")
// Migration: ajouter colonne must_change_password si elle n'existe pas
if _, err = database.Exec(`ALTER TABLE clients ADD COLUMN IF NOT EXISTS must_change_password BOOLEAN NOT NULL DEFAULT TRUE`); err != nil {
log.Fatalf("❌ Erreur migration must_change_password: %v", err)
}
// Lancer le nettoyage périodique des tokens expirés
go database.cleanExpiredTokensPeriodically()