Update modules/auth.py
Browse files- modules/auth.py +23 -30
modules/auth.py
CHANGED
|
@@ -1,42 +1,35 @@
|
|
| 1 |
# /modules/auth.py
|
| 2 |
-
|
| 3 |
-
import pymssql
|
| 4 |
-
from modules.db_connection import get_db_connection
|
| 5 |
|
| 6 |
-
# Funci贸n para registrar un nuevo usuario
|
| 7 |
def register_user(username, password, role):
|
| 8 |
-
conn = get_db_connection()
|
| 9 |
-
cursor = conn.cursor()
|
| 10 |
try:
|
| 11 |
-
|
| 12 |
-
|
|
|
|
|
|
|
|
|
|
| 13 |
return True
|
| 14 |
-
except
|
|
|
|
| 15 |
return False
|
| 16 |
-
finally:
|
| 17 |
-
cursor.close()
|
| 18 |
-
conn.close()
|
| 19 |
|
| 20 |
-
# Funci贸n para autenticar un usuario
|
| 21 |
def authenticate_user(username, password):
|
| 22 |
-
conn = get_db_connection()
|
| 23 |
-
cursor = conn.cursor()
|
| 24 |
try:
|
| 25 |
-
|
| 26 |
-
|
| 27 |
-
|
| 28 |
-
|
| 29 |
-
|
| 30 |
-
|
|
|
|
|
|
|
| 31 |
|
| 32 |
-
# Funci贸n para obtener el rol del usuario
|
| 33 |
def get_user_role(username):
|
| 34 |
-
conn = get_db_connection()
|
| 35 |
-
cursor = conn.cursor()
|
| 36 |
try:
|
| 37 |
-
|
| 38 |
-
|
| 39 |
-
|
| 40 |
-
|
| 41 |
-
|
| 42 |
-
|
|
|
|
|
|
| 1 |
# /modules/auth.py
|
| 2 |
+
from modules.db_connection import call_azure_function
|
|
|
|
|
|
|
| 3 |
|
|
|
|
| 4 |
def register_user(username, password, role):
|
|
|
|
|
|
|
| 5 |
try:
|
| 6 |
+
result = call_azure_function('insert_user', {
|
| 7 |
+
'username': username,
|
| 8 |
+
'password': password,
|
| 9 |
+
'role': role
|
| 10 |
+
})
|
| 11 |
return True
|
| 12 |
+
except Exception as e:
|
| 13 |
+
print(f"Error registering user: {str(e)}")
|
| 14 |
return False
|
|
|
|
|
|
|
|
|
|
| 15 |
|
|
|
|
| 16 |
def authenticate_user(username, password):
|
|
|
|
|
|
|
| 17 |
try:
|
| 18 |
+
result = call_azure_function('get_user', {
|
| 19 |
+
'username': username,
|
| 20 |
+
'password': password
|
| 21 |
+
})
|
| 22 |
+
return bool(result)
|
| 23 |
+
except Exception as e:
|
| 24 |
+
print(f"Error authenticating user: {str(e)}")
|
| 25 |
+
return False
|
| 26 |
|
|
|
|
| 27 |
def get_user_role(username):
|
|
|
|
|
|
|
| 28 |
try:
|
| 29 |
+
result = call_azure_function('get_user', {
|
| 30 |
+
'username': username
|
| 31 |
+
})
|
| 32 |
+
return result['role'] if result else None
|
| 33 |
+
except Exception as e:
|
| 34 |
+
print(f"Error getting user role: {str(e)}")
|
| 35 |
+
return None
|