nagasurendra commited on
Commit
70eb50f
·
verified ·
1 Parent(s): 57462dd

Update app.py

Browse files
Files changed (1) hide show
  1. app.py +22 -25
app.py CHANGED
@@ -1,29 +1,33 @@
1
  import gradio as gr
2
  import pandas as pd
 
3
  from bcrypt import hashpw, gensalt, checkpw
4
 
5
  # File for storing user data
6
  USER_FILE = "users.xlsx"
7
 
 
 
 
8
  # Utility Functions
9
  def save_user(name, phone, email, password):
10
- """Save user details to Excel file."""
11
  try:
12
- # Load existing users
13
- try:
14
- users = pd.read_excel(USER_FILE)
15
- except FileNotFoundError:
16
- users = pd.DataFrame(columns=["Name", "Phone", "Email", "Password"])
17
-
18
  # Check if email already exists
19
- if email in users["Email"].values:
 
20
  return False # User already exists
21
 
22
- # Add new user
23
  hashed_password = hashpw(password.encode(), gensalt()).decode()
24
- new_user = {"Name": name, "Phone": phone, "Email": email, "Password": hashed_password}
25
- users = pd.concat([users, pd.DataFrame([new_user])], ignore_index=True)
26
- users.to_excel(USER_FILE, index=False)
 
 
 
 
 
27
  return True
28
  except Exception as e:
29
  print(f"Error saving user: {e}")
@@ -32,21 +36,14 @@ def save_user(name, phone, email, password):
32
  def check_credentials(email, password):
33
  """Check user credentials during login."""
34
  try:
35
- users = pd.read_excel(USER_FILE)
36
- user = users[users["Email"] == email]
37
- if not user.empty:
38
- return checkpw(password.encode(), user.iloc[0]["Password"].encode())
39
  return False
40
- except FileNotFoundError:
41
- return False
42
-
43
- # Function to load the menu data
44
- def load_menu():
45
- menu_file = "menu.xlsx" # Ensure this file exists in the same directory
46
- try:
47
- return pd.read_excel(menu_file)
48
  except Exception as e:
49
- raise ValueError(f"Error loading menu file: {e}")
 
50
 
51
 
52
  # Function to filter menu items based on preference
 
1
  import gradio as gr
2
  import pandas as pd
3
+ from simple_salesforce import Salesforce
4
  from bcrypt import hashpw, gensalt, checkpw
5
 
6
  # File for storing user data
7
  USER_FILE = "users.xlsx"
8
 
9
+ # Utility Functions
10
+ sf = Salesforce(username='diggavalli98@gmail.com', password='Sati@1020', security_token='sSSjyhInIsUohKpG8sHzty2q')
11
+
12
  # Utility Functions
13
  def save_user(name, phone, email, password):
14
+ """Save user details to Salesforce."""
15
  try:
 
 
 
 
 
 
16
  # Check if email already exists
17
+ query_result = sf.query(f"SELECT Id FROM Customer_Login__c WHERE Email__c = '{email}'")
18
+ if query_result['totalSize'] > 0:
19
  return False # User already exists
20
 
21
+ # Hash the password
22
  hashed_password = hashpw(password.encode(), gensalt()).decode()
23
+
24
+ # Create new user in Salesforce
25
+ sf.Customer_Login__c.create({
26
+ 'Name': name,
27
+ 'Email__c': email,
28
+ 'Password__c': hashed_password,
29
+ 'Phone_Number__c': phone
30
+ })
31
  return True
32
  except Exception as e:
33
  print(f"Error saving user: {e}")
 
36
  def check_credentials(email, password):
37
  """Check user credentials during login."""
38
  try:
39
+ query_result = sf.query(f"SELECT Password__c FROM Customer_Login__c WHERE Email__c = '{email}'")
40
+ if query_result['totalSize'] == 1:
41
+ stored_password = query_result['records'][0]['Password__c']
42
+ return checkpw(password.encode(), stored_password.encode())
43
  return False
 
 
 
 
 
 
 
 
44
  except Exception as e:
45
+ print(f"Error checking credentials: {e}")
46
+ return False
47
 
48
 
49
  # Function to filter menu items based on preference