saleslogin / app.py
nagasurendra's picture
Update app.py
d5abb5e verified
import gradio as gr
from simple_salesforce import Salesforce
# Salesforce Connection
sf = Salesforce(username='surendra@sathkrutha.com',
password='Lavanyanaga@123',
security_token='z7Wvk6mys7n8XjqbYKf3bwBh7')
# Signup Function
def signup(name, email, phone, password):
try:
sf.User_Login__c.create({
'Name__c': name.strip(),
'Email__c': email.strip(),
'Phone__c': phone.strip(),
'Password2__c': password.strip() # Use the new field Password2__c
})
return "Signup successful! You can now login."
except Exception as e:
return f"Error during signup: {str(e)}"
# Login Function
def login(email, password):
try:
email = email.strip()
password = password.strip()
# Query Salesforce for user details
query = f"SELECT Name__c, Email__c, Phone__c, Password2__c FROM User_Login__c WHERE Email__c = '{email}'"
result = sf.query(query)
if len(result['records']) == 0:
print(f"No user found with email: {email}")
return "Invalid email or password.", None, None, None
user = result['records'][0]
stored_password = user['Password2__c']
print(f"Entered Email: {email}")
print(f"Entered Password: {password}")
print(f"Stored Password: {stored_password}")
# Compare plain-text passwords
if password == stored_password:
print("Password matched!")
return "Login successful!", user['Name__c'], user['Email__c'], user['Phone__c']
else:
print("Password did not match!")
return "Invalid email or password.", None, None, None
except Exception as e:
print(f"Error during login: {str(e)}")
return f"Error during login: {str(e)}", None, None, None
# Gradio Signup Page
def signup_page(name, email, phone, password):
response = signup(name, email, phone, password)
return response
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"
)
# Gradio Login Page
def login_page(email, password):
login_status, name, email, phone = login(email, password)
if login_status == "Login successful!":
return login_status, name, email, phone
else:
return login_status, "Error", "Error", "Error"
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"
)
# Combine Pages in Gradio
with gr.Blocks() as app:
with gr.Tab("Signup"):
signup_interface.render()
with gr.Tab("Login"):
login_interface.render()
# Launch Gradio App
app.launch()