|
|
|
from modules.db_connection import call_azure_function |
|
|
|
def register_user(username, password, role, additional_info): |
|
try: |
|
|
|
user_result = call_azure_function('insert_user', { |
|
'username': username, |
|
'password': password, |
|
'role': role |
|
}) |
|
|
|
if user_result.get('success'): |
|
|
|
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 |