From c0108fd1e15d63abd336c682dc5fdf3497d20597 Mon Sep 17 00:00:00 2001 From: Mabe Date: Sat, 19 Sep 2026 16:48:56 -0700 Subject: [PATCH] Add username availability check and fix cursor initialization in user.py; update token validation in api_security.py --- auth/api_security.py | 1 + auth/user.py | 15 +++++++++++++-- 2 files changed, 14 insertions(+), 2 deletions(-) diff --git a/auth/api_security.py b/auth/api_security.py index c9825eb..9292629 100644 --- a/auth/api_security.py +++ b/auth/api_security.py @@ -80,6 +80,7 @@ def check_token(token): except Exception as e: logging.error("Token not the same") logging.error(e) + return valid def check_validaty(): diff --git a/auth/user.py b/auth/user.py index 8026156..a7a6e9d 100644 --- a/auth/user.py +++ b/auth/user.py @@ -3,7 +3,7 @@ import db from dotenv import load_dotenv import logging import os - +import mariadb #Logging logging.basicConfig( @@ -29,7 +29,7 @@ if db_host == None: os._exit(1) db.connect(db_user, db_psswd, db_host, int(db_port), db_name) - +cursor = db.connection.cursor() def create_user(username, password): user = username @@ -67,3 +67,14 @@ def delete_user(username, password): logging.info(f"User {username} was successfully deleted") except Exception as e: logging.error(e) + +def check_username(username): + try: + cursor.execute("SELECT 1 FROM user WHERE username = ?", (username,)) + exists = cursor.fetchone() is not None + return exists # True if taken, False if available + except db.IntegrityError as e: + if e.errno == 1062: + logging.error("Username taken") + return True #If the username is not available it returns True + \ No newline at end of file