From 8e076a429864640fe6c375bfe2f23dcf09c510ed Mon Sep 17 00:00:00 2001 From: voldemort <5692900+yell0wsuit@users.noreply.github.com> Date: Wed, 23 Jul 2025 16:37:34 +0700 Subject: [PATCH] Add module docstrings to user_changes.py for improved documentation and clarity; enhance error handling in change_password_route and change_api_key_route functions. --- routes/user_changes.py | 8 ++++++-- 1 file changed, 6 insertions(+), 2 deletions(-) diff --git a/routes/user_changes.py b/routes/user_changes.py index f8b37ad..9b56c2d 100644 --- a/routes/user_changes.py +++ b/routes/user_changes.py @@ -1,3 +1,5 @@ +"""Module to handle the user changes.""" + import re from flask import Blueprint, request, jsonify, session from custom_functions.database.user_db import change_password, change_api_key @@ -10,6 +12,7 @@ PASSWORD_REGEX = re.compile(r'^[A-Za-z0-9!@#$%^&*()_+\-=\[\]{};\'":\\|,.<>\/?`~] @user_change_bp.route("/user/change_password", methods=["POST"]) def change_password_route(): + """Handle the change password route.""" username = session.get("username") if not username: return jsonify({"message": "False"}), 400 @@ -25,18 +28,19 @@ def change_password_route(): return jsonify({"message": "True"}), 200 except Exception as e: - return jsonify({"message": "False"}), 400 + return jsonify({"message": "False", "error": str(e)}), 400 @user_change_bp.route("/user/change_api_key", methods=["POST"]) def change_api_key_route(): + """Handle the change API key route.""" # Ensure the user is logged in by checking session for 'username' username = session.get("username") if not username: return jsonify({"message": "False", "error": "User not logged in"}), 400 # Get the new API key from the request body - new_api_key = request.json.get("new_api_key") + new_api_key = request.get_json().get("new_api_key") if not new_api_key: return jsonify({"message": "False", "error": "New API key not provided"}), 400