Spaces:
Sleeping
Sleeping
Update components/login_signup.py
Browse files- components/login_signup.py +71 -42
components/login_signup.py
CHANGED
|
@@ -1,44 +1,73 @@
|
|
| 1 |
import gradio as gr
|
| 2 |
-
from utils.
|
| 3 |
-
|
| 4 |
-
|
| 5 |
-
|
| 6 |
-
def
|
| 7 |
-
|
| 8 |
-
|
| 9 |
-
|
| 10 |
-
|
| 11 |
-
|
| 12 |
-
|
| 13 |
-
|
| 14 |
-
|
| 15 |
-
|
| 16 |
-
if
|
| 17 |
-
return "
|
| 18 |
-
|
| 19 |
-
|
| 20 |
-
|
| 21 |
-
|
| 22 |
-
|
| 23 |
-
|
| 24 |
-
|
| 25 |
-
|
| 26 |
-
with gr.
|
| 27 |
-
gr.Markdown("
|
| 28 |
-
email = gr.Textbox(label="Email")
|
| 29 |
-
password = gr.Textbox(label="Password", type="password")
|
|
|
|
|
|
|
| 30 |
login_btn = gr.Button("Login")
|
| 31 |
-
|
| 32 |
-
|
| 33 |
-
|
| 34 |
-
with gr.
|
| 35 |
-
gr.Markdown("
|
| 36 |
-
name = gr.Textbox(label="Name")
|
| 37 |
-
|
| 38 |
-
|
| 39 |
-
|
| 40 |
-
|
| 41 |
-
|
| 42 |
-
|
| 43 |
-
|
| 44 |
-
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
| 1 |
import gradio as gr
|
| 2 |
+
from utils.database_handler import check_credentials, save_user
|
| 3 |
+
|
| 4 |
+
def login_page():
|
| 5 |
+
# Login Button Actions
|
| 6 |
+
def authenticate_user(email, password):
|
| 7 |
+
if check_credentials(email, password):
|
| 8 |
+
return gr.update(visible=False), gr.update(visible=True), "Welcome to Biryani Hub!"
|
| 9 |
+
else:
|
| 10 |
+
return gr.update(visible=True), gr.update(visible=False), "Invalid email or password. Try again."
|
| 11 |
+
|
| 12 |
+
def navigate_to_signup():
|
| 13 |
+
return gr.update(visible=False), gr.update(visible=True)
|
| 14 |
+
|
| 15 |
+
def create_account(name, phone, email, password):
|
| 16 |
+
if save_user(name, phone, email, password):
|
| 17 |
+
return "Account created successfully! You can now log in.", gr.update(visible=True), gr.update(visible=False)
|
| 18 |
+
else:
|
| 19 |
+
return "Email already exists. Try logging in.", gr.update(visible=False), gr.update(visible=True)
|
| 20 |
+
|
| 21 |
+
def navigate_to_login():
|
| 22 |
+
return gr.update(visible=True), gr.update(visible=False)
|
| 23 |
+
|
| 24 |
+
with gr.Blocks() as login_interface:
|
| 25 |
+
# Login Section
|
| 26 |
+
with gr.Column(visible=True) as login_section:
|
| 27 |
+
gr.Markdown("# Login to Biryani Hub")
|
| 28 |
+
email = gr.Textbox(label="Email", placeholder="Enter your email")
|
| 29 |
+
password = gr.Textbox(label="Password", placeholder="Enter your password", type="password")
|
| 30 |
+
error_box = gr.Markdown("", visible=False)
|
| 31 |
+
success_box = gr.Markdown("", visible=False)
|
| 32 |
login_btn = gr.Button("Login")
|
| 33 |
+
create_account_btn = gr.Button("Create an Account")
|
| 34 |
+
|
| 35 |
+
# Sign-Up Section
|
| 36 |
+
with gr.Column(visible=False) as signup_section:
|
| 37 |
+
gr.Markdown("# Create Your Account")
|
| 38 |
+
name = gr.Textbox(label="Name", placeholder="Enter your full name")
|
| 39 |
+
phone = gr.Textbox(label="Phone", placeholder="Enter your phone number")
|
| 40 |
+
signup_email = gr.Textbox(label="Email", placeholder="Enter your email")
|
| 41 |
+
signup_password = gr.Textbox(label="Password", placeholder="Enter a password", type="password")
|
| 42 |
+
success_message = gr.Markdown("", visible=False)
|
| 43 |
+
error_message = gr.Markdown("", visible=False)
|
| 44 |
+
submit_btn = gr.Button("Sign Up")
|
| 45 |
+
back_to_login_btn = gr.Button("Back to Login")
|
| 46 |
+
|
| 47 |
+
# Button Actions
|
| 48 |
+
login_btn.click(
|
| 49 |
+
authenticate_user,
|
| 50 |
+
inputs=[email, password],
|
| 51 |
+
outputs=[error_box, success_box, success_box]
|
| 52 |
+
)
|
| 53 |
+
create_account_btn.click(
|
| 54 |
+
navigate_to_signup,
|
| 55 |
+
inputs=[],
|
| 56 |
+
outputs=[login_section, signup_section]
|
| 57 |
+
)
|
| 58 |
+
submit_btn.click(
|
| 59 |
+
create_account,
|
| 60 |
+
inputs=[name, phone, signup_email, signup_password],
|
| 61 |
+
outputs=[success_message, signup_section, login_section]
|
| 62 |
+
)
|
| 63 |
+
back_to_login_btn.click(
|
| 64 |
+
navigate_to_login,
|
| 65 |
+
inputs=[],
|
| 66 |
+
outputs=[login_section, signup_section]
|
| 67 |
+
)
|
| 68 |
+
|
| 69 |
+
return login_interface
|
| 70 |
+
|
| 71 |
+
# Expose login_page for integration in the main app
|
| 72 |
+
if __name__ == "__main__":
|
| 73 |
+
login_page().launch()
|