Add username availability check and fix cursor initialization in user.py; update token validation in api_security.py
This commit is contained in:
+13
-2
@@ -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
|
||||
|
||||
Reference in New Issue
Block a user