-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathauth.py
More file actions
27 lines (24 loc) · 743 Bytes
/
auth.py
File metadata and controls
27 lines (24 loc) · 743 Bytes
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
from db import get_connection
def login(username, password):
if not username or not password:
return None
conn = get_connection()
cursor = conn.cursor()
user = cursor.execute(
"""
SELECT
users.id,
users.username,
users.role,
users.full_name,
users.department_id,
users.position,
departments.name AS department_name
FROM users
LEFT JOIN departments ON departments.id = users.department_id
WHERE users.username = ? AND users.password = ? AND COALESCE(users.password, '') <> ''
""",
(username, password),
).fetchone()
conn.close()
return dict(user) if user else None