test2 / modules /auth.py
AIdeaText's picture
Update modules/auth.py
18e8360 verified
raw
history blame
1.72 kB
# /modules/auth.py
from modules.db_connection import call_azure_function
def register_user(username, password, role, additional_info):
try:
# Primero, inserta en la tabla Users
user_result = call_azure_function('insert_user', {
'username': username,
'password': password,
'role': role
})
if user_result.get('success'):
# Si la inserción en Users fue exitosa, inserta en Estudiantes o Profesores
if role == 'Estudiante':
result = call_azure_function('insert_estudiante', {
'user_id': user_result['user_id'],
**additional_info
})
elif role == 'Profesor':
result = call_azure_function('insert_profesor', {
'user_id': user_result['user_id'],
**additional_info
})
return result.get('success', False)
else:
return False
except Exception as e:
print(f"Error registering user: {str(e)}")
return False
def authenticate_user(username, password):
try:
result = call_azure_function('get_user', {
'username': username,
'password': password
})
return bool(result)
except Exception as e:
print(f"Error authenticating user: {str(e)}")
return False
def get_user_role(username):
try:
result = call_azure_function('get_user', {
'username': username
})
return result['role'] if result else None
except Exception as e:
print(f"Error getting user role: {str(e)}")
return None