Spaces:
Sleeping
Sleeping
File size: 1,203 Bytes
7064f87 385bd50 7064f87 385bd50 7064f87 385bd50 7064f87 385bd50 7064f87 385bd50 7064f87 385bd50 |
1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 24 25 26 27 28 29 30 31 |
from database import get_conn
def get_device_id():
return "SIMULATED_DEVICE_ID" # β
Replace with actual device ID in production
def authenticate_user(email, password, device_id):
conn = get_conn()
cursor = conn.cursor()
cursor.execute("SELECT password, device_id, role FROM users WHERE email=?", (email,))
row = cursor.fetchone()
if not row:
return False, "User not found." # β
Email doesn't exist
if row[0] != password:
return False, "Incorrect password." # β
Wrong password
if row[2] == "student":
if row[1] and row[1] != device_id:
return False, "Access denied: Different device." # β
Device restriction check
elif not row[1]:
cursor.execute("UPDATE users SET device_id=? WHERE email=?", (device_id, email))
conn.commit() # β
First login, save the device
conn.close()
return True, "Login successful." # β
Authenticated
def get_user_role(email):
conn = get_conn()
cursor = conn.cursor()
cursor.execute("SELECT role FROM users WHERE email=?", (email,))
row = cursor.fetchone()
conn.close() # β
GOOD: You added this
return row[0] if row else None
|