improved start sequence, fixed user update

This commit is contained in:
2025-04-09 09:48:02 -04:00
parent ae4cd12f97
commit e53e5004e1
6 changed files with 126 additions and 61 deletions

View File

@@ -68,49 +68,62 @@ def add_user(mac_address, description, vlan_id):
cursor.close()
conn.close()
def update_user_description(mac_address, description):
"""Update the description field of a user identified by MAC address."""
def update_user(mac_address, description, vlan_id):
"""Update both description and VLAN ID for a given MAC address."""
conn = get_connection()
cursor = conn.cursor()
cursor.execute("UPDATE users SET description = %s WHERE mac_address = %s", (description, mac_address.lower()))
cursor.execute(
"UPDATE users SET description = %s, vlan_id = %s WHERE mac_address = %s",
(description, vlan_id, mac_address.lower())
)
conn.commit()
cursor.close()
conn.close()
# def update_user_description(mac_address, description):
# """Update the description field of a user identified by MAC address."""
# conn = get_connection()
# cursor = conn.cursor()
# cursor.execute("UPDATE users SET description = %s WHERE mac_address = %s", (description, mac_address.lower()))
# conn.commit()
# cursor.close()
# conn.close()
# Note: This function seems redundant with update_user_description. Included as per instructions.
def update_description(mac_address, description):
"""Update the description for a given MAC address in the users table."""
conn = get_connection()
cursor = conn.cursor()
cursor.execute(
"UPDATE users SET description = %s WHERE mac_address = %s",
(description, mac_address.lower())
)
conn.commit()
cursor.close()
conn.close()
# def update_description(mac_address, description):
# """Update the description for a given MAC address in the users table."""
# conn = get_connection()
# cursor = conn.cursor()
# cursor.execute(
# "UPDATE users SET description = %s WHERE mac_address = %s",
# (description, mac_address.lower())
# )
# conn.commit()
# cursor.close()
# conn.close()
def update_user_vlan(mac_address, vlan_id):
"""Update the VLAN ID for a given MAC address in the users table."""
conn = get_connection()
cursor = conn.cursor()
cursor.execute("UPDATE users SET vlan_id = %s WHERE mac_address = %s", (vlan_id, mac_address.lower()))
conn.commit()
cursor.close()
conn.close()
# def update_user_vlan(mac_address, vlan_id):
# """Update the VLAN ID for a given MAC address in the users table."""
# conn = get_connection()
# cursor = conn.cursor()
# cursor.execute("UPDATE users SET vlan_id = %s WHERE mac_address = %s", (vlan_id, mac_address.lower()))
# conn.commit()
# cursor.close()
# conn.close()
# Note: This function seems redundant with update_user_vlan. Included as per instructions.
def update_vlan(mac_address, vlan_id):
"""Update the VLAN ID for a given MAC address in the users table."""
conn = get_connection()
cursor = conn.cursor()
cursor.execute(
"UPDATE users SET vlan_id = %s WHERE mac_address = %s",
(vlan_id, mac_address.lower())
)
conn.commit()
cursor.close()
conn.close()
# # Note: This function seems redundant with update_user_vlan. Included as per instructions.
# def update_vlan(mac_address, vlan_id):
# """Update the VLAN ID for a given MAC address in the users table."""
# conn = get_connection()
# cursor = conn.cursor()
# cursor.execute(
# "UPDATE users SET vlan_id = %s WHERE mac_address = %s",
# (vlan_id, mac_address.lower())
# )
# conn.commit()
# cursor.close()
# conn.close()
def delete_user(mac_address):
"""Remove a user from the database by their MAC address."""