AIdeaText commited on
Commit
7d2fbf4
verified
1 Parent(s): 5b70ab2

Update modules/auth/auth.py

Browse files
Files changed (1) hide show
  1. modules/auth/auth.py +20 -37
modules/auth/auth.py CHANGED
@@ -1,9 +1,6 @@
1
  #/modules/auth/auth.py
2
-
3
- ##########modules/auth/auth.py
4
-
5
  import os
6
- import streamlit as st
7
  from azure.cosmos import CosmosClient, exceptions
8
  from azure.cosmos.exceptions import CosmosHttpResponseError
9
  import bcrypt
@@ -46,39 +43,25 @@ if not endpoint or not key:
46
  key = clean_and_validate_key(key)
47
 
48
 
49
- def authenticate_user(username, password):
50
- """Autentica un usuario y registra el inicio de sesi贸n"""
51
- try:
52
- user_item = get_user(username)
53
-
54
- if not user_item:
55
- logger.warning(f"Usuario no encontrado: {username}")
56
- return False, None
57
-
58
- if verify_password(user_item['password'], password):
59
- logger.info(f"Usuario autenticado: {username}, Rol: {user_item['role']}")
60
-
61
- try:
62
- session_id = record_login(username)
63
- if session_id:
64
- st.session_state.session_id = session_id
65
- st.session_state.username = username
66
- st.session_state.login_time = datetime.now(timezone.utc).isoformat()
67
- logger.info(f"Sesi贸n iniciada: {session_id}")
68
- else:
69
- logger.warning("No se pudo registrar la sesi贸n")
70
- except Exception as e:
71
- logger.error(f"Error al registrar inicio de sesi贸n: {str(e)}")
72
-
73
- return True, user_item['role']
74
-
75
- logger.warning(f"Contrase帽a incorrecta para usuario: {username}")
76
- return False, None
77
-
78
- except Exception as e:
79
- logger.error(f"Error durante la autenticaci贸n del usuario: {str(e)}")
80
- return False, None
81
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
82
  def authenticate_student(username, password):
83
  """Autentica un estudiante"""
84
  success, role = authenticate_user(username, password)
@@ -185,7 +168,7 @@ def verify_password(stored_password, provided_password):
185
  )
186
 
187
  __all__ = [
188
- 'authenticate_user',
189
  'authenticate_admin',
190
  'authenticate_student',
191
  'register_student',
 
1
  #/modules/auth/auth.py
2
+ import gradio as gr
 
 
3
  import os
 
4
  from azure.cosmos import CosmosClient, exceptions
5
  from azure.cosmos.exceptions import CosmosHttpResponseError
6
  import bcrypt
 
43
  key = clean_and_validate_key(key)
44
 
45
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
46
 
47
+ ##################################################################
48
+ def create_auth_interface():
49
+ """Crea la interfaz de autenticaci贸n."""
50
+ with gr.Blocks() as auth_interface:
51
+ gr.Markdown("# Login")
52
+ username = gr.Textbox(label="Usuario")
53
+ password = gr.Textbox(label="Contrase帽a", type="password")
54
+ login_btn = gr.Button("Iniciar Sesi贸n")
55
+ message = gr.Markdown()
56
+
57
+ def handle_login(user, pwd):
58
+ success, role = authenticate_user(user, pwd)
59
+ return f"Bienvenido, {user} ({role})" if success else "Credenciales incorrectas."
60
+
61
+ login_btn.click(fn=handle_login, inputs=[username, password], outputs=message)
62
+ return auth_interface
63
+
64
+ ######################################################################################
65
  def authenticate_student(username, password):
66
  """Autentica un estudiante"""
67
  success, role = authenticate_user(username, password)
 
168
  )
169
 
170
  __all__ = [
171
+ 'create_auth_interface', # por 'authenticate_user',
172
  'authenticate_admin',
173
  'authenticate_student',
174
  'register_student',