Spaces:
Sleeping
Sleeping
Update main.py
Browse files
main.py
CHANGED
|
@@ -390,5 +390,41 @@ def get_user_profile():
|
|
| 390 |
except Exception as e:
|
| 391 |
return jsonify({'error': str(e)}), 500
|
| 392 |
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
| 393 |
if __name__ == '__main__':
|
| 394 |
app.run(debug=True, host="0.0.0.0", port=7860)
|
|
|
|
| 390 |
except Exception as e:
|
| 391 |
return jsonify({'error': str(e)}), 500
|
| 392 |
|
| 393 |
+
|
| 394 |
+
# delete users
|
| 395 |
+
|
| 396 |
+
@app.route('/api/admin/users/<string:uid>', methods=['DELETE'])
|
| 397 |
+
def delete_user(uid):
|
| 398 |
+
try:
|
| 399 |
+
verify_admin(request.headers.get('Authorization', ''))
|
| 400 |
+
|
| 401 |
+
# Verify the user exists
|
| 402 |
+
try:
|
| 403 |
+
user = auth.get_user(uid)
|
| 404 |
+
except auth.UserNotFoundError:
|
| 405 |
+
return jsonify({'error': 'User not found'}), 404
|
| 406 |
+
|
| 407 |
+
# Delete authentication user
|
| 408 |
+
auth.delete_user(uid)
|
| 409 |
+
|
| 410 |
+
# Delete database record
|
| 411 |
+
db.reference(f'users/{uid}').delete()
|
| 412 |
+
|
| 413 |
+
# Delete user's transactions
|
| 414 |
+
transactions_ref = db.reference('transactions')
|
| 415 |
+
user_transactions = transactions_ref.order_by_child('uid').equal_to(uid).get()
|
| 416 |
+
if user_transactions:
|
| 417 |
+
for transaction_id in user_transactions.keys():
|
| 418 |
+
transactions_ref.child(transaction_id).delete()
|
| 419 |
+
|
| 420 |
+
return jsonify({
|
| 421 |
+
'success': True,
|
| 422 |
+
'message': f'User {uid} and all associated data deleted successfully'
|
| 423 |
+
})
|
| 424 |
+
except Exception as e:
|
| 425 |
+
return jsonify({'error': str(e)}), 500
|
| 426 |
+
|
| 427 |
+
# ... (rest of the code remains the same)
|
| 428 |
+
|
| 429 |
if __name__ == '__main__':
|
| 430 |
app.run(debug=True, host="0.0.0.0", port=7860)
|