Spaces:
Sleeping
Sleeping
Update app.py
Browse files
app.py
CHANGED
@@ -6,14 +6,16 @@ sf = Salesforce(username='surendra@sathkrutha.com',
|
|
6 |
password='Lavanyanaga@123',
|
7 |
security_token='z7Wvk6mys7n8XjqbYKf3bwBh7')
|
8 |
|
|
|
|
|
9 |
# Signup Function
|
10 |
def signup(name, email, phone, password):
|
11 |
try:
|
12 |
sf.User_Login__c.create({
|
13 |
-
'Name__c': name,
|
14 |
-
'Email__c': email,
|
15 |
-
'Phone__c': phone,
|
16 |
-
'Password__c': password
|
17 |
})
|
18 |
return "Signup successful! You can now login."
|
19 |
except Exception as e:
|
@@ -22,32 +24,30 @@ def signup(name, email, phone, password):
|
|
22 |
# Login Function
|
23 |
def login(email, password):
|
24 |
try:
|
25 |
-
email = email.strip()
|
26 |
-
password = password.strip()
|
27 |
|
|
|
28 |
query = f"SELECT Name__c, Email__c, Phone__c, Password__c FROM User_Login__c WHERE Email__c = '{email}'"
|
29 |
result = sf.query(query)
|
30 |
|
31 |
if len(result['records']) == 0:
|
32 |
-
print(f"No user found with email: {email}")
|
33 |
return "Invalid email or password.", None, None, None
|
34 |
|
35 |
user = result['records'][0]
|
36 |
stored_password = user['Password__c']
|
37 |
|
38 |
-
|
39 |
-
print(f"Stored Password: {stored_password}")
|
40 |
-
|
41 |
if password == stored_password:
|
42 |
-
print("Password matched!")
|
43 |
return "Login successful!", user['Name__c'], user['Email__c'], user['Phone__c']
|
44 |
else:
|
45 |
-
print("Password did not match!")
|
46 |
return "Invalid email or password.", None, None, None
|
47 |
except Exception as e:
|
48 |
-
print(f"Error during login: {str(e)}")
|
49 |
return f"Error during login: {str(e)}", None, None, None
|
50 |
|
|
|
|
|
|
|
51 |
|
52 |
# Gradio Signup Page
|
53 |
def signup_page(name, email, phone, password):
|
@@ -89,7 +89,19 @@ login_interface = gr.Interface(
|
|
89 |
title="Login Page"
|
90 |
)
|
91 |
|
92 |
-
# Gradio
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
93 |
with gr.Blocks() as app:
|
94 |
with gr.Tab("Signup"):
|
95 |
signup_interface.render()
|
@@ -97,4 +109,8 @@ with gr.Blocks() as app:
|
|
97 |
with gr.Tab("Login"):
|
98 |
login_interface.render()
|
99 |
|
|
|
|
|
|
|
|
|
100 |
app.launch()
|
|
|
6 |
password='Lavanyanaga@123',
|
7 |
security_token='z7Wvk6mys7n8XjqbYKf3bwBh7')
|
8 |
|
9 |
+
|
10 |
+
|
11 |
# Signup Function
|
12 |
def signup(name, email, phone, password):
|
13 |
try:
|
14 |
sf.User_Login__c.create({
|
15 |
+
'Name__c': name.strip(),
|
16 |
+
'Email__c': email.strip(),
|
17 |
+
'Phone__c': phone.strip(),
|
18 |
+
'Password__c': password.strip() # Store plain-text password
|
19 |
})
|
20 |
return "Signup successful! You can now login."
|
21 |
except Exception as e:
|
|
|
24 |
# Login Function
|
25 |
def login(email, password):
|
26 |
try:
|
27 |
+
email = email.strip()
|
28 |
+
password = password.strip()
|
29 |
|
30 |
+
# Query Salesforce for user details
|
31 |
query = f"SELECT Name__c, Email__c, Phone__c, Password__c FROM User_Login__c WHERE Email__c = '{email}'"
|
32 |
result = sf.query(query)
|
33 |
|
34 |
if len(result['records']) == 0:
|
|
|
35 |
return "Invalid email or password.", None, None, None
|
36 |
|
37 |
user = result['records'][0]
|
38 |
stored_password = user['Password__c']
|
39 |
|
40 |
+
# Compare plain-text passwords
|
|
|
|
|
41 |
if password == stored_password:
|
|
|
42 |
return "Login successful!", user['Name__c'], user['Email__c'], user['Phone__c']
|
43 |
else:
|
|
|
44 |
return "Invalid email or password.", None, None, None
|
45 |
except Exception as e:
|
|
|
46 |
return f"Error during login: {str(e)}", None, None, None
|
47 |
|
48 |
+
# Home Page Function
|
49 |
+
def home_page(name, email, phone):
|
50 |
+
return f"Welcome, {name}! Your email is {email} and your phone number is {phone}."
|
51 |
|
52 |
# Gradio Signup Page
|
53 |
def signup_page(name, email, phone, password):
|
|
|
89 |
title="Login Page"
|
90 |
)
|
91 |
|
92 |
+
# Gradio Home Page
|
93 |
+
home_interface = gr.Interface(
|
94 |
+
fn=home_page,
|
95 |
+
inputs=[
|
96 |
+
gr.Textbox(label="Name"),
|
97 |
+
gr.Textbox(label="Email"),
|
98 |
+
gr.Textbox(label="Phone"),
|
99 |
+
],
|
100 |
+
outputs=gr.Textbox(label="Welcome Message"),
|
101 |
+
title="Home Page"
|
102 |
+
)
|
103 |
+
|
104 |
+
# Combine All Pages in Gradio
|
105 |
with gr.Blocks() as app:
|
106 |
with gr.Tab("Signup"):
|
107 |
signup_interface.render()
|
|
|
109 |
with gr.Tab("Login"):
|
110 |
login_interface.render()
|
111 |
|
112 |
+
with gr.Tab("Home"):
|
113 |
+
home_interface.render()
|
114 |
+
|
115 |
+
# Launch the Gradio App
|
116 |
app.launch()
|