|
|
|
import streamlit as st |
|
import pymssql |
|
from app import get_db_connection |
|
|
|
|
|
def register_user(username, password, role): |
|
conn = get_db_connection() |
|
cursor = conn.cursor() |
|
try: |
|
cursor.execute("INSERT INTO Users (Username, Password, Role) VALUES (%s, %s, %s)", (username, password, role)) |
|
conn.commit() |
|
return True |
|
except pymssql.IntegrityError: |
|
return False |
|
finally: |
|
cursor.close() |
|
conn.close() |
|
|
|
|
|
def authenticate_user(username, password): |
|
conn = get_db_connection() |
|
cursor = conn.cursor() |
|
try: |
|
cursor.execute("SELECT UserID, Role FROM Users WHERE Username = %s AND Password = %s", (username, password)) |
|
user = cursor.fetchone() |
|
return bool(user) |
|
finally: |
|
cursor.close() |
|
conn.close() |
|
|
|
|
|
def get_user_role(username): |
|
conn = get_db_connection() |
|
cursor = conn.cursor() |
|
try: |
|
cursor.execute("SELECT Role FROM Users WHERE Username = %s", (username,)) |
|
role = cursor.fetchone() |
|
return role[0] if role else None |
|
finally: |
|
cursor.close() |
|
conn.close() |