UPDATE: moved admin database usage to admin_utils
This commit is contained in:
@@ -1,6 +1,6 @@
|
||||
from flask import Blueprint, session
|
||||
from database.database import Database
|
||||
from utils.utils import sanitize
|
||||
from utils.admin_utils import *
|
||||
|
||||
admin_bp = Blueprint("admin", __name__)
|
||||
|
||||
@@ -9,21 +9,13 @@ def admin_delete_user(banned_user):
|
||||
# Sanitise the user input
|
||||
banned_user = sanitize(banned_user)
|
||||
|
||||
# Create a connection to the database
|
||||
db = Database()
|
||||
db.create_connection()
|
||||
|
||||
# Check if the user is an admin
|
||||
username = session.get("username")
|
||||
is_admin = db.fetchone("""
|
||||
SELECT is_admin
|
||||
FROM users
|
||||
WHERE username = ?;
|
||||
""", (username,))
|
||||
is_admin = check_if_admin(username)
|
||||
|
||||
# Check if the user exists
|
||||
user_exists = db.fetchone("""SELECT user_id from users WHERE username = ?;""", (banned_user))
|
||||
user_exists = check_if_user_exists(banned_user)
|
||||
|
||||
# If the user is an admin, try to delete the account
|
||||
if is_admin and user_exists:
|
||||
db.execute("""DELETE FROM users WHERE username = ?;""", (banned_user))
|
||||
ban_user(banned_user)
|
||||
Reference in New Issue
Block a user