Spaces:
Sleeping
Sleeping
Update app.py
Browse files
app.py
CHANGED
|
@@ -5,25 +5,36 @@ from bcrypt import hashpw, gensalt, checkpw
|
|
| 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
|
| 11 |
try:
|
| 12 |
-
#
|
| 13 |
-
|
| 14 |
-
|
| 15 |
-
|
| 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 |
-
#
|
| 23 |
hashed_password = hashpw(password.encode(), gensalt()).decode()
|
| 24 |
-
|
| 25 |
-
|
| 26 |
-
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
| 27 |
return True
|
| 28 |
except Exception as e:
|
| 29 |
print(f"Error saving user: {e}")
|
|
@@ -32,14 +43,18 @@ def save_user(name, phone, email, password):
|
|
| 32 |
def check_credentials(email, password):
|
| 33 |
"""Check user credentials during login."""
|
| 34 |
try:
|
| 35 |
-
|
| 36 |
-
|
| 37 |
-
|
| 38 |
-
|
|
|
|
|
|
|
| 39 |
return False
|
| 40 |
-
except
|
|
|
|
| 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
|
|
|
|
| 5 |
# File for storing user data
|
| 6 |
USER_FILE = "users.xlsx"
|
| 7 |
|
| 8 |
+
# Utility Functions
|
| 9 |
+
from simple_salesforce import Salesforce
|
| 10 |
+
from bcrypt import hashpw, gensalt, checkpw
|
| 11 |
+
import datetime
|
| 12 |
+
|
| 13 |
+
# Salesforce connection setup
|
| 14 |
+
sf = Salesforce(username='your_username', password='your_password', security_token='your_security_token')
|
| 15 |
+
|
| 16 |
# Utility Functions
|
| 17 |
def save_user(name, phone, email, password):
|
| 18 |
+
"""Save user details to Salesforce."""
|
| 19 |
try:
|
| 20 |
+
# Check if the email already exists in Salesforce
|
| 21 |
+
query = f"SELECT Id FROM Customer_Login__c WHERE Email__c = '{email}'"
|
| 22 |
+
result = sf.query(query)
|
| 23 |
+
if result['totalSize'] > 0:
|
|
|
|
|
|
|
|
|
|
|
|
|
| 24 |
return False # User already exists
|
| 25 |
|
| 26 |
+
# Hash the password
|
| 27 |
hashed_password = hashpw(password.encode(), gensalt()).decode()
|
| 28 |
+
|
| 29 |
+
# Insert new user record into Salesforce
|
| 30 |
+
new_user = {
|
| 31 |
+
"Name": name,
|
| 32 |
+
"Email__c": email,
|
| 33 |
+
"Password__c": hashed_password,
|
| 34 |
+
"Phone_Number__c": phone,
|
| 35 |
+
"Login_Status__c": "Logged Out"
|
| 36 |
+
}
|
| 37 |
+
sf.Customer_Login__c.create(new_user)
|
| 38 |
return True
|
| 39 |
except Exception as e:
|
| 40 |
print(f"Error saving user: {e}")
|
|
|
|
| 43 |
def check_credentials(email, password):
|
| 44 |
"""Check user credentials during login."""
|
| 45 |
try:
|
| 46 |
+
# Query user by email
|
| 47 |
+
query = f"SELECT Password__c FROM Customer_Login__c WHERE Email__c = '{email}'"
|
| 48 |
+
result = sf.query(query)
|
| 49 |
+
if result['totalSize'] == 1:
|
| 50 |
+
hashed_password = result['records'][0]['Password__c']
|
| 51 |
+
return checkpw(password.encode(), hashed_password.encode())
|
| 52 |
return False
|
| 53 |
+
except Exception as e:
|
| 54 |
+
print(f"Error checking credentials: {e}")
|
| 55 |
return False
|
| 56 |
|
| 57 |
+
|
| 58 |
# Function to load the menu data
|
| 59 |
def load_menu():
|
| 60 |
menu_file = "menu.xlsx" # Ensure this file exists in the same directory
|