Update modules/ui/views/login_ui.py
Browse files- modules/ui/views/login_ui.py +41 -35
modules/ui/views/login_ui.py
CHANGED
@@ -1,37 +1,43 @@
|
|
1 |
-
#modules/ui/
|
2 |
-
|
3 |
import gradio as gr
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
4 |
|
5 |
-
def
|
6 |
-
|
7 |
-
Interfaz de inicio de sesi贸n.
|
8 |
-
"""
|
9 |
-
with gr.Blocks() as login_interface:
|
10 |
-
gr.Markdown("# Iniciar Sesi贸n")
|
11 |
-
|
12 |
-
with gr.Row():
|
13 |
-
username = gr.Textbox(label="Usuario")
|
14 |
-
with gr.Row():
|
15 |
-
password = gr.Textbox(label="Contrase帽a", type="password")
|
16 |
-
|
17 |
-
with gr.Row():
|
18 |
-
back_button = gr.Button("Volver")
|
19 |
-
login_button = gr.Button("Iniciar Sesi贸n", variant="primary")
|
20 |
-
|
21 |
-
message = gr.Markdown()
|
22 |
-
|
23 |
-
def render(navigate_back, handle_login):
|
24 |
-
back_button.click(
|
25 |
-
fn=navigate_back,
|
26 |
-
inputs=[],
|
27 |
-
outputs=[]
|
28 |
-
)
|
29 |
-
|
30 |
-
login_button.click(
|
31 |
-
fn=handle_login,
|
32 |
-
inputs=[username, password],
|
33 |
-
outputs=[message]
|
34 |
-
)
|
35 |
-
|
36 |
-
login_interface.render = render
|
37 |
-
return login_interface
|
|
|
1 |
+
# modules/ui/views/login.py
|
|
|
2 |
import gradio as gr
|
3 |
+
from ...auth.auth import authenticate_user
|
4 |
+
|
5 |
+
class LoginView:
|
6 |
+
def __init__(self):
|
7 |
+
with gr.Blocks() as self.view:
|
8 |
+
with gr.Column():
|
9 |
+
gr.Markdown("# Iniciar Sesi贸n")
|
10 |
+
self.username = gr.Textbox(label="Usuario")
|
11 |
+
self.password = gr.Textbox(
|
12 |
+
label="Contrase帽a",
|
13 |
+
type="password"
|
14 |
+
)
|
15 |
+
self.role = gr.State()
|
16 |
+
self.message = gr.Markdown()
|
17 |
+
|
18 |
+
with gr.Row():
|
19 |
+
self.back_button = gr.Button("Volver")
|
20 |
+
self.login_button = gr.Button(
|
21 |
+
"Iniciar Sesi贸n",
|
22 |
+
variant="primary"
|
23 |
+
)
|
24 |
+
|
25 |
+
def handle_login(username, password):
|
26 |
+
success, role = authenticate_user(username, password)
|
27 |
+
if success:
|
28 |
+
self.role.value = role
|
29 |
+
return username, role, ""
|
30 |
+
return None, None, "Credenciales incorrectas"
|
31 |
+
|
32 |
+
self.login_button.click(
|
33 |
+
fn=handle_login,
|
34 |
+
inputs=[self.username, self.password],
|
35 |
+
outputs=[self.username, self.role, self.message]
|
36 |
+
)
|
37 |
+
|
38 |
+
@property
|
39 |
+
def submit(self):
|
40 |
+
return self.login_button.click
|
41 |
|
42 |
+
def create_login_view():
|
43 |
+
return LoginView().view
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|