Add username availability check and fix cursor initialization in user.py; update token validation in api_security.py

This commit is contained in:
Mabe
2026-09-19 16:48:56 -07:00
parent c105c36086
commit c0108fd1e1
2 changed files with 14 additions and 2 deletions
+1
View File
@@ -80,6 +80,7 @@ def check_token(token):
except Exception as e: except Exception as e:
logging.error("Token not the same") logging.error("Token not the same")
logging.error(e) logging.error(e)
return valid
def check_validaty(): def check_validaty():
+13 -2
View File
@@ -3,7 +3,7 @@ import db
from dotenv import load_dotenv from dotenv import load_dotenv
import logging import logging
import os import os
import mariadb
#Logging #Logging
logging.basicConfig( logging.basicConfig(
@@ -29,7 +29,7 @@ if db_host == None:
os._exit(1) os._exit(1)
db.connect(db_user, db_psswd, db_host, int(db_port), db_name) db.connect(db_user, db_psswd, db_host, int(db_port), db_name)
cursor = db.connection.cursor()
def create_user(username, password): def create_user(username, password):
user = username user = username
@@ -67,3 +67,14 @@ def delete_user(username, password):
logging.info(f"User {username} was successfully deleted") logging.info(f"User {username} was successfully deleted")
except Exception as e: except Exception as e:
logging.error(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