Update modules/auth.py
Browse files- modules/auth.py +24 -14
modules/auth.py
CHANGED
@@ -16,26 +16,36 @@ def save_users(df):
|
|
16 |
|
17 |
# Función para registrar un nuevo usuario
|
18 |
def register_user(username, password, role):
|
19 |
-
|
20 |
-
|
|
|
|
|
|
|
|
|
|
|
|
|
21 |
return False
|
22 |
-
|
23 |
-
|
24 |
-
save_users(users)
|
25 |
-
return True
|
26 |
|
27 |
# Función para autenticar un usuario
|
28 |
def authenticate_user(username, password):
|
29 |
-
|
30 |
-
|
31 |
-
|
|
|
|
|
|
|
|
|
|
|
32 |
return True
|
33 |
return False
|
34 |
|
35 |
# Función para obtener el rol del usuario
|
36 |
def get_user_role(username):
|
37 |
-
|
38 |
-
|
39 |
-
|
40 |
-
|
41 |
-
|
|
|
|
16 |
|
17 |
# Función para registrar un nuevo usuario
|
18 |
def register_user(username, password, role):
|
19 |
+
conn = get_db_connection()
|
20 |
+
cursor = conn.cursor()
|
21 |
+
try:
|
22 |
+
cursor.execute("INSERT INTO Users (Username, Role) VALUES (?, ?)",
|
23 |
+
(username, role))
|
24 |
+
conn.commit()
|
25 |
+
return True
|
26 |
+
except pyodbc.IntegrityError:
|
27 |
return False
|
28 |
+
finally:
|
29 |
+
conn.close()
|
|
|
|
|
30 |
|
31 |
# Función para autenticar un usuario
|
32 |
def authenticate_user(username, password):
|
33 |
+
conn = get_db_connection()
|
34 |
+
cursor = conn.cursor()
|
35 |
+
cursor.execute("SELECT UserID, Role FROM Users WHERE Username = ?", (username,))
|
36 |
+
user = cursor.fetchone()
|
37 |
+
conn.close()
|
38 |
+
if user:
|
39 |
+
# Aquí deberías verificar la contraseña de forma segura
|
40 |
+
# Por ahora, asumimos que la autenticación es correcta si el usuario existe
|
41 |
return True
|
42 |
return False
|
43 |
|
44 |
# Función para obtener el rol del usuario
|
45 |
def get_user_role(username):
|
46 |
+
conn = get_db_connection()
|
47 |
+
cursor = conn.cursor()
|
48 |
+
cursor.execute("SELECT Role FROM Users WHERE Username = ?", (username,))
|
49 |
+
role = cursor.fetchone()
|
50 |
+
conn.close()
|
51 |
+
return role[0] if role else None
|