diff --git a/.gitignore b/.gitignore index 4c49bd7..ff0fd90 100644 --- a/.gitignore +++ b/.gitignore @@ -1 +1,2 @@ .env +**/__pycache__/ \ No newline at end of file diff --git a/.vscode/settings.json b/.vscode/settings.json index 85b80f5..1795aeb 100644 --- a/.vscode/settings.json +++ b/.vscode/settings.json @@ -1,6 +1,10 @@ { "cSpell.words": [ + "blocklist", "dotenv", + "gensalt", + "hashpw", + "checkpw", "jsonify" ] } \ No newline at end of file diff --git a/app/__init__.py b/app/__init__.py index 954eefb..c5f1e58 100644 --- a/app/__init__.py +++ b/app/__init__.py @@ -1,10 +1,10 @@ from flask import Flask from flask_jwt_extended import JWTManager -def create_app(): - app = Flask(__name__) - jwt = JWTManager(app) +app = Flask(__name__) +jwt_manager = JWTManager(app) +def create_app(): from app.api import bp, bp_errors, bp_product, bp_user app.register_blueprint(bp) app.register_blueprint(bp_errors) diff --git a/app/__pycache__/__init__.cpython-310.pyc b/app/__pycache__/__init__.cpython-310.pyc deleted file mode 100644 index c692374..0000000 Binary files a/app/__pycache__/__init__.cpython-310.pyc and /dev/null differ diff --git a/app/__pycache__/__init__.cpython-311.pyc b/app/__pycache__/__init__.cpython-311.pyc deleted file mode 100644 index 995c4bc..0000000 Binary files a/app/__pycache__/__init__.cpython-311.pyc and /dev/null differ diff --git a/app/__pycache__/config.cpython-310.pyc b/app/__pycache__/config.cpython-310.pyc deleted file mode 100644 index 32e5d24..0000000 Binary files a/app/__pycache__/config.cpython-310.pyc and /dev/null differ diff --git a/app/__pycache__/config.cpython-311.pyc b/app/__pycache__/config.cpython-311.pyc deleted file mode 100644 index 0137554..0000000 Binary files a/app/__pycache__/config.cpython-311.pyc and /dev/null differ diff --git a/app/__pycache__/decorators.cpython-311.pyc b/app/__pycache__/decorators.cpython-311.pyc deleted file mode 100644 index 05eb1c3..0000000 Binary files a/app/__pycache__/decorators.cpython-311.pyc and /dev/null differ diff --git a/app/__pycache__/extensions.cpython-310.pyc b/app/__pycache__/extensions.cpython-310.pyc deleted file mode 100644 index cb508fd..0000000 Binary files a/app/__pycache__/extensions.cpython-310.pyc and /dev/null differ diff --git a/app/__pycache__/extensions.cpython-311.pyc b/app/__pycache__/extensions.cpython-311.pyc deleted file mode 100644 index b93580f..0000000 Binary files a/app/__pycache__/extensions.cpython-311.pyc and /dev/null differ diff --git a/app/api/__pycache__/__init__.cpython-310.pyc b/app/api/__pycache__/__init__.cpython-310.pyc deleted file mode 100644 index dd13cd7..0000000 Binary files a/app/api/__pycache__/__init__.cpython-310.pyc and /dev/null differ diff --git a/app/api/__pycache__/__init__.cpython-311.pyc b/app/api/__pycache__/__init__.cpython-311.pyc deleted file mode 100644 index 69aaf01..0000000 Binary files a/app/api/__pycache__/__init__.cpython-311.pyc and /dev/null differ diff --git a/app/api/routes/__pycache__/__init__.cpython-310.pyc b/app/api/routes/__pycache__/__init__.cpython-310.pyc deleted file mode 100644 index d8f16cc..0000000 Binary files a/app/api/routes/__pycache__/__init__.cpython-310.pyc and /dev/null differ diff --git a/app/api/routes/__pycache__/__init__.cpython-311.pyc b/app/api/routes/__pycache__/__init__.cpython-311.pyc deleted file mode 100644 index f0c4c3c..0000000 Binary files a/app/api/routes/__pycache__/__init__.cpython-311.pyc and /dev/null differ diff --git a/app/api/routes/__pycache__/error.cpython-311.pyc b/app/api/routes/__pycache__/error.cpython-311.pyc deleted file mode 100644 index 74ba1f1..0000000 Binary files a/app/api/routes/__pycache__/error.cpython-311.pyc and /dev/null differ diff --git a/app/api/routes/__pycache__/error_routes.cpython-310.pyc b/app/api/routes/__pycache__/error_routes.cpython-310.pyc deleted file mode 100644 index 4e400a7..0000000 Binary files a/app/api/routes/__pycache__/error_routes.cpython-310.pyc and /dev/null differ diff --git a/app/api/routes/__pycache__/error_routes.cpython-311.pyc b/app/api/routes/__pycache__/error_routes.cpython-311.pyc deleted file mode 100644 index 206d2ca..0000000 Binary files a/app/api/routes/__pycache__/error_routes.cpython-311.pyc and /dev/null differ diff --git a/app/api/routes/__pycache__/main_routes.cpython-310.pyc b/app/api/routes/__pycache__/main_routes.cpython-310.pyc deleted file mode 100644 index bc71dca..0000000 Binary files a/app/api/routes/__pycache__/main_routes.cpython-310.pyc and /dev/null differ diff --git a/app/api/routes/__pycache__/main_routes.cpython-311.pyc b/app/api/routes/__pycache__/main_routes.cpython-311.pyc deleted file mode 100644 index 254e589..0000000 Binary files a/app/api/routes/__pycache__/main_routes.cpython-311.pyc and /dev/null differ diff --git a/app/api/routes/__pycache__/product.cpython-311.pyc b/app/api/routes/__pycache__/product.cpython-311.pyc deleted file mode 100644 index 2b1dd16..0000000 Binary files a/app/api/routes/__pycache__/product.cpython-311.pyc and /dev/null differ diff --git a/app/api/routes/__pycache__/product_routes.cpython-310.pyc b/app/api/routes/__pycache__/product_routes.cpython-310.pyc deleted file mode 100644 index 639a622..0000000 Binary files a/app/api/routes/__pycache__/product_routes.cpython-310.pyc and /dev/null differ diff --git a/app/api/routes/__pycache__/product_routes.cpython-311.pyc b/app/api/routes/__pycache__/product_routes.cpython-311.pyc deleted file mode 100644 index 9d57ad6..0000000 Binary files a/app/api/routes/__pycache__/product_routes.cpython-311.pyc and /dev/null differ diff --git a/app/api/routes/__pycache__/user_routes.cpython-310.pyc b/app/api/routes/__pycache__/user_routes.cpython-310.pyc deleted file mode 100644 index ca238c2..0000000 Binary files a/app/api/routes/__pycache__/user_routes.cpython-310.pyc and /dev/null differ diff --git a/app/api/routes/__pycache__/user_routes.cpython-311.pyc b/app/api/routes/__pycache__/user_routes.cpython-311.pyc deleted file mode 100644 index 6355a94..0000000 Binary files a/app/api/routes/__pycache__/user_routes.cpython-311.pyc and /dev/null differ diff --git a/app/extensions.py b/app/extensions.py index 7d8db09..be72693 100644 --- a/app/extensions.py +++ b/app/extensions.py @@ -12,7 +12,7 @@ db_connection = mysql.connector.connect( database=MySqlConfig.MYSQL_DATABASE, ) -db_cursor = db_connection.cursor() +db_cursor = db_connection.cursor(dictionary=True) jwt_redis_blocklist = redis.StrictRedis( host=RedisConfig.REDIS_HOST, diff --git a/app/jwt_utils.py b/app/jwt_utils.py index aec66f9..2df5ae7 100644 --- a/app/jwt_utils.py +++ b/app/jwt_utils.py @@ -1,9 +1,6 @@ from app.extensions import jwt_redis_blocklist -from flask_jwt_extended import create_access_token -from flask_jwt_extended import get_jwt -from flask_jwt_extended import jwt_required -from flask_jwt_extended import JWTManager +from . import jwt_manager @jwt.token_in_blocklist_loader def check_if_token_is_revoked(jwt_header, jwt_payload: dict) -> bool: diff --git a/app/services/__pycache__/jwt_check_service.cpython-311.pyc b/app/services/__pycache__/jwt_check_service.cpython-311.pyc deleted file mode 100644 index cf0bee5..0000000 Binary files a/app/services/__pycache__/jwt_check_service.cpython-311.pyc and /dev/null differ diff --git a/app/services/__pycache__/product_service.cpython-310.pyc b/app/services/__pycache__/product_service.cpython-310.pyc deleted file mode 100644 index 583d184..0000000 Binary files a/app/services/__pycache__/product_service.cpython-310.pyc and /dev/null differ diff --git a/app/services/__pycache__/product_service.cpython-311.pyc b/app/services/__pycache__/product_service.cpython-311.pyc deleted file mode 100644 index a473fd2..0000000 Binary files a/app/services/__pycache__/product_service.cpython-311.pyc and /dev/null differ diff --git a/app/services/__pycache__/user_service.cpython-310.pyc b/app/services/__pycache__/user_service.cpython-310.pyc deleted file mode 100644 index 001c894..0000000 Binary files a/app/services/__pycache__/user_service.cpython-310.pyc and /dev/null differ diff --git a/app/services/__pycache__/user_service.cpython-311.pyc b/app/services/__pycache__/user_service.cpython-311.pyc deleted file mode 100644 index d593e0e..0000000 Binary files a/app/services/__pycache__/user_service.cpython-311.pyc and /dev/null differ diff --git a/app/services/product_service.py b/app/services/product_service.py index 92e2a18..e2ff6d0 100644 --- a/app/services/product_service.py +++ b/app/services/product_service.py @@ -8,30 +8,30 @@ class ProductService: def get_name(product_id: int): cursor.execute(f"select name from product where product.product_id = {product_id}") result = cursor.fetchone() - return result[0] + return result['name'] @staticmethod def get_manufacturer(product_id: int): cursor.execute(f"select manufacturer from product where product.product_id = {product_id}") result = cursor.fetchone() - return result[0] + return result['manufacturer'] @staticmethod def get_price(product_id: int): cursor.execute(f"select price_pc from product where product.product_id = {product_id}") - result = cursor.fetchone() + result = cursor['price_pc'] return result[0] @staticmethod def get_image(product_id: int): cursor.execute(f"select image from product where product.product_id = {product_id}") - result = cursor.fetchone() + result = cursor['image'] return base64.b64encode(result[0]).decode('utf-8') @staticmethod def get_image_name(product_id: int): cursor.execute(f"select image_name from product where product.product_id = {product_id}") - result = cursor.fetchone() + result = cursor['image_name'] return result[0] @staticmethod @@ -40,13 +40,9 @@ class ProductService: result = cursor.fetchone() return { - "name": result[0], - "manufacturer": result[1], - "price": result[2], - "image_name": result[3], - "image": base64.b64encode(result[4]).decode('utf-8') - } - - @staticmethod - def create_user(username: str, email: str, password: str): - print("asd") \ No newline at end of file + "name": result['name'], + "manufacturer": result['manufacturer'], + "price": result['price_pc'], + "image_name": result['image_name'], + "image": base64.b64encode(result['image']).decode('utf-8') + } \ No newline at end of file diff --git a/app/services/user_service.py b/app/services/user_service.py index cd779ba..26dc84a 100644 --- a/app/services/user_service.py +++ b/app/services/user_service.py @@ -31,11 +31,11 @@ class UserService: hashed_password = bcrypt.hashpw(password.encode('utf-8'), bcrypt.gensalt()) try: - db_cursor.execute("select max(user_id) from user") - last_id = db_cursor.fetchone()[0] + db_cursor.execute("select max(user_id) as max_id from user") + last_id = db_cursor.fetchone()['max_id'] if last_id < 23000: - return {"Failed": "Error occured when fetching last user id"} + return {"Failed": "Error occurred when fetching last user id"} new_id = last_id + 1 @@ -53,9 +53,9 @@ class UserService: db_cursor.execute("select user_id, password, last_change from user where username = %s", (username,)) result = db_cursor.fetchone() - user_id = result[0] - password_hash = result[1] - last_change = result[2] + user_id = result['user_id'] + password_hash = result['password'] + last_change = result['last_change'] if user_id is None: return {"Failed": "Username not found"}, 400 @@ -73,7 +73,7 @@ class UserService: def update_email(user_id: str, new_email: str) -> Tuple[Union[dict, str], int]: if not UserService.__verify_email(new_email): - return {"Failed": "Failed to verify email. Try another email"}, 400 + return {"Failed": "Failed to verify email. Try another email"}, 400 try: db_cursor.execute("update user set email = %s where user_id = %s", (new_email, user_id))