forked from tpd94/CDRM-Project
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.
This commit is contained in:
parent
bbeeffcd9d
commit
8e076a4298
@ -1,3 +1,5 @@
|
|||||||
|
"""Module to handle the user changes."""
|
||||||
|
|
||||||
import re
|
import re
|
||||||
from flask import Blueprint, request, jsonify, session
|
from flask import Blueprint, request, jsonify, session
|
||||||
from custom_functions.database.user_db import change_password, change_api_key
|
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"])
|
@user_change_bp.route("/user/change_password", methods=["POST"])
|
||||||
def change_password_route():
|
def change_password_route():
|
||||||
|
"""Handle the change password route."""
|
||||||
username = session.get("username")
|
username = session.get("username")
|
||||||
if not username:
|
if not username:
|
||||||
return jsonify({"message": "False"}), 400
|
return jsonify({"message": "False"}), 400
|
||||||
@ -25,18 +28,19 @@ def change_password_route():
|
|||||||
return jsonify({"message": "True"}), 200
|
return jsonify({"message": "True"}), 200
|
||||||
|
|
||||||
except Exception as e:
|
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"])
|
@user_change_bp.route("/user/change_api_key", methods=["POST"])
|
||||||
def change_api_key_route():
|
def change_api_key_route():
|
||||||
|
"""Handle the change API key route."""
|
||||||
# Ensure the user is logged in by checking session for 'username'
|
# Ensure the user is logged in by checking session for 'username'
|
||||||
username = session.get("username")
|
username = session.get("username")
|
||||||
if not username:
|
if not username:
|
||||||
return jsonify({"message": "False", "error": "User not logged in"}), 400
|
return jsonify({"message": "False", "error": "User not logged in"}), 400
|
||||||
|
|
||||||
# Get the new API key from the request body
|
# 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:
|
if not new_api_key:
|
||||||
return jsonify({"message": "False", "error": "New API key not provided"}), 400
|
return jsonify({"message": "False", "error": "New API key not provided"}), 400
|
||||||
|
Loading…
x
Reference in New Issue
Block a user