diff --git a/game_collection/user_management.py b/game_collection/user_management.py index 88f571c..fe8ea32 100644 --- a/game_collection/user_management.py +++ b/game_collection/user_management.py @@ -100,6 +100,22 @@ def delete_user(user_id): db.session.commit() return jsonify({'message': 'User deleted!'}), 200 +@user_bp.route('/users/change_password', methods=['PUT']) +def change_password(): + data = request.json + current_password = data.get('current_password') + new_password = data.get('new_password') + + if not current_password or not new_password: + return jsonify({'message': 'Current and new passwords are required!'}), 400 + + if not check_password_hash(g.user.password, current_password): + return jsonify({'message': 'Current password is incorrect!'}), 401 + + g.user.password = generate_password_hash(new_password) + db.session.commit() + return jsonify({'message': 'Password changed successfully!'}), 200 + @user_bp.route('/games/', methods=['PUT']) def edit_game(game_id): if not authenticate():