File size: 2,941 Bytes
1e29ad7
aae5506
1e29ad7
 
 
 
 
aae5506
1e29ad7
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
aae5506
1e29ad7
 
 
 
 
aae5506
1e29ad7
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
aae5506
1e29ad7
 
aae5506
1e29ad7
 
aae5506
1e29ad7
 
aae5506
1e29ad7
aae5506
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
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
from simple_salesforce import Salesforce

# Authenticate with Salesforce
sf = Salesforce(username='[email protected]', 
                password='Lavanyanaga@123', 
                security_token='z7Wvk6mys7n8XjqbYKf3bwBh7')
import bcrypt

def hash_password(password):
    return bcrypt.hashpw(password.encode('utf-8'), bcrypt.gensalt()).decode('utf-8')
def verify_password(plain_password, hashed_password):
    return bcrypt.checkpw(plain_password.encode('utf-8'), hashed_password.encode('utf-8'))
def signup(name, email, phone, password):
    hashed_password = hash_password(password)
    try:
        sf.User_Login__c.create({
            'Name__c': name,
            'Email__c': email,
            'Phone__c': phone,
            'Password__c': hashed_password
        })
        return "Signup successful! You can now login."
    except Exception as e:
        return f"Error during signup: {str(e)}"
def login(email, password):
    query = f"SELECT Id, Name__c, Email__c, Password__c FROM User_Login__c WHERE Email__c = '{email}'"
    result = sf.query(query)
    
    if len(result['records']) == 0:
        return "Invalid email or password."

    user = result['records'][0]
    if verify_password(password, user['Password__c']):
        return f"Welcome, {user['Name__c']}!", user
    else:
        return "Invalid email or password.", None
import gradio as gr
def signup_page(name, email, phone, password):
    response = signup(name, email, phone, password)
    return response
def login_page(email, password):
    response, user = login(email, password)
    if user:
        return response, user['Name__c'], user['Email__c'], user['Phone__c']
    return response, None, None, None
def home_page(name, email, phone):
    return f"Welcome, {name}! Your email: {email}, Phone: {phone}"
signup_interface = gr.Interface(
    fn=signup_page,
    inputs=[
        gr.Textbox(label="Name"),
        gr.Textbox(label="Email"),
        gr.Textbox(label="Phone"),
        gr.Textbox(label="Password", type="password"),
    ],
    outputs=gr.Textbox(label="Signup Status"),
    title="Signup Page"
)
login_interface = gr.Interface(
    fn=login_page,
    inputs=[
        gr.Textbox(label="Email"),
        gr.Textbox(label="Password", type="password"),
    ],
    outputs=[
        gr.Textbox(label="Login Status"),
        gr.Textbox(label="Name"),
        gr.Textbox(label="Email"),
        gr.Textbox(label="Phone"),
    ],
    title="Login Page"
)
home_interface = gr.Interface(
    fn=home_page,
    inputs=[
        gr.Textbox(label="Name"),
        gr.Textbox(label="Email"),
        gr.Textbox(label="Phone"),
    ],
    outputs=gr.Textbox(label="Welcome Message"),
    title="Home Page"
)
with gr.Blocks() as app:
    with gr.Tab("Signup"):
        signup_interface.render()

    with gr.Tab("Login"):
        login_interface.render()

    with gr.Tab("Home"):
        home_interface.render()

# Launch the app
app.launch()