File size: 2,964 Bytes
3fa4c7d
e39b8fd
 
8c5f062
e39b8fd
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
9dab323
e39b8fd
9dab323
e39b8fd
 
 
 
3fa4c7d
e39b8fd
 
9dab323
e39b8fd
9dab323
e39b8fd
 
 
 
 
 
 
 
 
9dab323
e39b8fd
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
import gradio as gr
from utils.database_handler import check_credentials, save_user

def login_signup():
    def authenticate_user(email, password):
        if check_credentials(email, password):
            return gr.update(visible=False), gr.update(visible=True), "Welcome to Biryani Hub!"
        else:
            return gr.update(visible=True), gr.update(visible=False), "Invalid email or password. Try again."

    def navigate_to_signup():
        return gr.update(visible=False), gr.update(visible=True)

    def create_account(name, phone, email, password):
        if save_user(name, phone, email, password):
            return "Account created successfully! You can now log in.", gr.update(visible=True), gr.update(visible=False)
        else:
            return "Email already exists. Try logging in.", gr.update(visible=False), gr.update(visible=True)

    def navigate_to_login():
        return gr.update(visible=True), gr.update(visible=False)

    with gr.Blocks() as login_interface:
        # Login Section
        with gr.Column(visible=True) as login_section:
            gr.Markdown("## Login to Biryani Hub")
            email = gr.Textbox(label="Email", placeholder="Enter your email")
            password = gr.Textbox(label="Password", placeholder="Enter your password", type="password")
            error_box = gr.Markdown("", visible=False)
            success_box = gr.Markdown("", visible=False)
            login_btn = gr.Button("Login")
            create_account_btn = gr.Button("Create an Account")

        # Sign-Up Section
        with gr.Column(visible=False) as signup_section:
            gr.Markdown("## Create Your Account")
            name = gr.Textbox(label="Name", placeholder="Enter your full name")
            phone = gr.Textbox(label="Phone", placeholder="Enter your phone number")
            signup_email = gr.Textbox(label="Email", placeholder="Enter your email")
            signup_password = gr.Textbox(label="Password", placeholder="Enter a password", type="password")
            success_message = gr.Markdown("", visible=False)
            error_message = gr.Markdown("", visible=False)
            submit_btn = gr.Button("Sign Up")
            back_to_login_btn = gr.Button("Back to Login")

        # Button Actions
        login_btn.click(
            authenticate_user,
            inputs=[email, password],
            outputs=[error_box, success_box, success_box]
        )
        create_account_btn.click(
            navigate_to_signup,
            inputs=[],
            outputs=[login_section, signup_section]
        )
        submit_btn.click(
            create_account,
            inputs=[name, phone, signup_email, signup_password],
            outputs=[success_message, signup_section, login_section]
        )
        back_to_login_btn.click(
            navigate_to_login,
            inputs=[],
            outputs=[login_section, signup_section]
        )

    return login_interface