Spaces:
Sleeping
Sleeping
K2MAR commited on
Commit ·
4645e9c
1
Parent(s): e1d3c92
feat: Système notifications complet
Browse filesNOUVELLES ROUTES:
- POST /api/auth/change-password (changement mot de passe)
- POST /api/notifications/check-exam-reminders (rappels examens 7-5-3-2-1j)
- POST /api/notifications/check-new-items (détection nouveaux projets/groupes)
FONCTIONNALITÉS:
✅ Rappels examens multi-jours (7j à 1h avant)
✅ Détection nouveaux projets automatique
✅ Détection nouveaux groupes automatique
✅ Changement mot de passe sécurisé
✅ Timestamp lastCheck anti-doublons
app.py
CHANGED
|
@@ -174,6 +174,7 @@ def home():
|
|
| 174 |
'register': 'POST /api/auth/register',
|
| 175 |
'login': 'POST /api/auth/login',
|
| 176 |
'profile': 'GET /api/auth/profile (token requis)',
|
|
|
|
| 177 |
'students': 'GET /api/auth/students (token requis)'
|
| 178 |
},
|
| 179 |
'cours': {
|
|
@@ -364,6 +365,70 @@ def get_profile():
|
|
| 364 |
'error': str(e)
|
| 365 |
}), 500
|
| 366 |
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
| 367 |
@app.route('/api/auth/students', methods=['GET'])
|
| 368 |
@token_required
|
| 369 |
def get_all_students():
|
|
|
|
| 174 |
'register': 'POST /api/auth/register',
|
| 175 |
'login': 'POST /api/auth/login',
|
| 176 |
'profile': 'GET /api/auth/profile (token requis)',
|
| 177 |
+
'change-password': 'POST /api/auth/change-password (token requis)',
|
| 178 |
'students': 'GET /api/auth/students (token requis)'
|
| 179 |
},
|
| 180 |
'cours': {
|
|
|
|
| 365 |
'error': str(e)
|
| 366 |
}), 500
|
| 367 |
|
| 368 |
+
@app.route('/api/auth/change-password', methods=['POST'])
|
| 369 |
+
@token_required
|
| 370 |
+
def change_password():
|
| 371 |
+
"""Changer le mot de passe de l'utilisateur connecté"""
|
| 372 |
+
try:
|
| 373 |
+
data = request.get_json()
|
| 374 |
+
current_password = data.get('currentPassword')
|
| 375 |
+
new_password = data.get('newPassword')
|
| 376 |
+
|
| 377 |
+
if not current_password or not new_password:
|
| 378 |
+
return jsonify({
|
| 379 |
+
'success': False,
|
| 380 |
+
'message': 'Mot de passe actuel et nouveau mot de passe requis'
|
| 381 |
+
}), 400
|
| 382 |
+
|
| 383 |
+
if len(new_password) < 6:
|
| 384 |
+
return jsonify({
|
| 385 |
+
'success': False,
|
| 386 |
+
'message': 'Le nouveau mot de passe doit contenir au moins 6 caractères'
|
| 387 |
+
}), 400
|
| 388 |
+
|
| 389 |
+
etudiant_id = request.user_id
|
| 390 |
+
|
| 391 |
+
# Récupérer l'étudiant
|
| 392 |
+
etudiant_data = get_student_by_id(etudiant_id)
|
| 393 |
+
|
| 394 |
+
if not etudiant_data:
|
| 395 |
+
return jsonify({
|
| 396 |
+
'success': False,
|
| 397 |
+
'message': 'Utilisateur non trouvé'
|
| 398 |
+
}), 404
|
| 399 |
+
|
| 400 |
+
# Vérifier le mot de passe actuel
|
| 401 |
+
stored_password = etudiant_data.get('password')
|
| 402 |
+
if not stored_password or stored_password != current_password:
|
| 403 |
+
return jsonify({
|
| 404 |
+
'success': False,
|
| 405 |
+
'message': 'Mot de passe actuel incorrect'
|
| 406 |
+
}), 401
|
| 407 |
+
|
| 408 |
+
# Mettre à jour le mot de passe dans Firebase
|
| 409 |
+
response = requests.patch(
|
| 410 |
+
f'{FIREBASE_DB_URL}/etudiants/{etudiant_id}.json',
|
| 411 |
+
json={'password': new_password}
|
| 412 |
+
)
|
| 413 |
+
|
| 414 |
+
if response.status_code == 200:
|
| 415 |
+
return jsonify({
|
| 416 |
+
'success': True,
|
| 417 |
+
'message': 'Mot de passe modifié avec succès'
|
| 418 |
+
}), 200
|
| 419 |
+
else:
|
| 420 |
+
return jsonify({
|
| 421 |
+
'success': False,
|
| 422 |
+
'message': 'Erreur lors de la mise à jour'
|
| 423 |
+
}), 500
|
| 424 |
+
|
| 425 |
+
except Exception as e:
|
| 426 |
+
print(f"❌ Erreur changement mot de passe: {e}")
|
| 427 |
+
return jsonify({
|
| 428 |
+
'success': False,
|
| 429 |
+
'message': str(e)
|
| 430 |
+
}), 500
|
| 431 |
+
|
| 432 |
@app.route('/api/auth/students', methods=['GET'])
|
| 433 |
@token_required
|
| 434 |
def get_all_students():
|