Refactoring
This commit is contained in:
131
fix-passwords.sh
Normal file
131
fix-passwords.sh
Normal file
@@ -0,0 +1,131 @@
|
||||
#!/bin/bash
|
||||
|
||||
echo "============================================================================="
|
||||
echo "🔧 RÉPARATION DES MOTS DE PASSE UTILISATEURS UNIONFLOW"
|
||||
echo "============================================================================="
|
||||
echo ""
|
||||
|
||||
# Obtenir le token admin
|
||||
echo "[INFO] Obtention du token d'administration..."
|
||||
token_response=$(curl -s -X POST \
|
||||
"http://192.168.1.145:8180/realms/master/protocol/openid-connect/token" \
|
||||
-H "Content-Type: application/x-www-form-urlencoded" \
|
||||
-d "username=admin&password=admin&grant_type=password&client_id=admin-cli")
|
||||
|
||||
if echo "$token_response" | grep -q "access_token"; then
|
||||
token=$(echo "$token_response" | grep -o '"access_token":"[^"]*' | cut -d'"' -f4)
|
||||
echo "[SUCCESS] Token obtenu"
|
||||
else
|
||||
echo "[ERROR] Impossible d'obtenir le token"
|
||||
exit 1
|
||||
fi
|
||||
|
||||
echo ""
|
||||
echo "Réparation des mots de passe..."
|
||||
echo ""
|
||||
|
||||
# Fonction pour obtenir l'ID utilisateur
|
||||
get_user_id() {
|
||||
local username="$1"
|
||||
local response=$(curl -s -X GET \
|
||||
"http://192.168.1.145:8180/admin/realms/unionflow/users?username=${username}" \
|
||||
-H "Authorization: Bearer ${token}")
|
||||
|
||||
echo "$response" | grep -o '"id":"[^"]*' | head -1 | cut -d'"' -f4
|
||||
}
|
||||
|
||||
# Fonction pour réinitialiser le mot de passe
|
||||
reset_password() {
|
||||
local username="$1"
|
||||
local password="$2"
|
||||
|
||||
echo -n "Réparation mot de passe pour $username... "
|
||||
|
||||
# Obtenir l'ID utilisateur
|
||||
user_id=$(get_user_id "$username")
|
||||
|
||||
if [ -z "$user_id" ]; then
|
||||
echo "✗ Utilisateur non trouvé"
|
||||
return 1
|
||||
fi
|
||||
|
||||
# Réinitialiser le mot de passe
|
||||
local response=$(curl -s -w "%{http_code}" -X PUT \
|
||||
"http://192.168.1.145:8180/admin/realms/unionflow/users/${user_id}/reset-password" \
|
||||
-H "Authorization: Bearer ${token}" \
|
||||
-H "Content-Type: application/json" \
|
||||
-d "{\"type\":\"password\",\"value\":\"${password}\",\"temporary\":false}")
|
||||
|
||||
local http_code="${response: -3}"
|
||||
|
||||
if [ "$http_code" = "204" ]; then
|
||||
echo "✓ SUCCÈS"
|
||||
return 0
|
||||
else
|
||||
echo "✗ ÉCHEC (code: $http_code)"
|
||||
return 1
|
||||
fi
|
||||
}
|
||||
|
||||
# Réinitialiser les mots de passe pour tous les utilisateurs
|
||||
declare -A users=(
|
||||
["marie.active"]="Marie123!"
|
||||
["superadmin"]="SuperAdmin123!"
|
||||
["jean.simple"]="Jean123!"
|
||||
["tech.lead"]="TechLead123!"
|
||||
["rh.manager"]="RhManager123!"
|
||||
["admin.org"]="AdminOrg123!"
|
||||
["tresorier"]="Tresorier123!"
|
||||
["visiteur"]="Visiteur123!"
|
||||
)
|
||||
|
||||
success_count=0
|
||||
total_count=${#users[@]}
|
||||
|
||||
for username in "${!users[@]}"; do
|
||||
password="${users[$username]}"
|
||||
if reset_password "$username" "$password"; then
|
||||
((success_count++))
|
||||
fi
|
||||
done
|
||||
|
||||
echo ""
|
||||
echo "============================================================================="
|
||||
echo "📊 RÉSULTATS RÉPARATION"
|
||||
echo "============================================================================="
|
||||
echo ""
|
||||
echo "✅ Mots de passe réparés : $success_count/$total_count"
|
||||
echo ""
|
||||
|
||||
if [ $success_count -gt 0 ]; then
|
||||
echo "🧪 Test d'authentification avec marie.active..."
|
||||
|
||||
auth_response=$(curl -s -X POST \
|
||||
"http://192.168.1.145:8180/realms/unionflow/protocol/openid-connect/token" \
|
||||
-H "Content-Type: application/x-www-form-urlencoded" \
|
||||
-d "username=marie.active&password=Marie123!&grant_type=password&client_id=unionflow-mobile")
|
||||
|
||||
if echo "$auth_response" | grep -q "access_token"; then
|
||||
echo "✓ Test authentification réussi !"
|
||||
echo ""
|
||||
echo "🎉 RÉPARATION TERMINÉE AVEC SUCCÈS !"
|
||||
echo ""
|
||||
echo "🚀 COMPTES PRÊTS POUR L'APPLICATION MOBILE :"
|
||||
echo " • marie.active / Marie123! (MEMBRE_ACTIF)"
|
||||
echo " • superadmin / SuperAdmin123! (SUPER_ADMINISTRATEUR)"
|
||||
echo " • jean.simple / Jean123! (MEMBRE_SIMPLE)"
|
||||
echo " • tech.lead / TechLead123! (RESPONSABLE_TECHNIQUE)"
|
||||
echo " • rh.manager / RhManager123! (RESPONSABLE_MEMBRES)"
|
||||
echo ""
|
||||
else
|
||||
echo "✗ Test authentification échoué"
|
||||
echo "Réponse: ${auth_response:0:100}..."
|
||||
fi
|
||||
else
|
||||
echo "❌ Aucun mot de passe n'a pu être réparé"
|
||||
fi
|
||||
|
||||
echo ""
|
||||
echo "============================================================================="
|
||||
echo "✅ RÉPARATION TERMINÉE"
|
||||
echo "============================================================================="
|
||||
Reference in New Issue
Block a user