Skip to content
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
Binary file modified app/database/dbs/user.db
Binary file not shown.
54 changes: 54 additions & 0 deletions app/database/user.py
Original file line number Diff line number Diff line change
Expand Up @@ -106,3 +106,57 @@ def create_user(self, username, password):
except Exception as e:
print(f"[ERROR] {FILE_NAME}: create_user: {e}")
return False

def remove_user(self, username):
"""
Removes a user record from the database by username.
Args:
username (str): The username of the user to remove.
Returns:
bool: True if the user was removed successfully, False otherwise.
Raises:
Exception: If there is an error executing the database query.
"""
query = f"DELETE FROM {self.table_user} WHERE userid = ?;"

if DEBUG_MODE:
print(f"[DEBUG] {FILE_NAME}: remove_user: {query} with username: {username}")

try:
self.cursor.execute(query, (username,))
self.connection.commit()
return True

except Exception as e:
print(f"[ERROR] {FILE_NAME}: remove_user: {e}")
return False

def remove_invalid_user(self):
"""
Removes invalid user records from the database.
This method is a placeholder for future implementation.
"""
query = f"DELETE FROM {self.table_user} WHERE userid IS NULL OR trim(userid) = '';"

try:
self.cursor.execute(query)
self.connection.commit()
return True
except Exception as e:
print(f"[ERROR] {FILE_NAME}: remove_invalid_user: {e}")
return False

def remove_all(self):
"""
Removes all user records from the database.
This method is a placeholder for future implementation.
"""
query = f"DELETE FROM {self.table_user};"

try:
self.cursor.execute(query)
self.connection.commit()
return True
except Exception as e:
print(f"[ERROR] {FILE_NAME}: remove_all: {e}")
return False