Spaces:
Sleeping
Sleeping
Update app.py
Browse files
app.py
CHANGED
@@ -17,18 +17,14 @@ def verify_password(plain_password, hashed_password):
|
|
17 |
def signup(name, email, phone, password):
|
18 |
try:
|
19 |
email = email.strip()
|
20 |
-
|
21 |
-
# Check if the email already exists in Salesforce
|
22 |
query = f"SELECT Id FROM Customer_Login__c WHERE Email__c = '{email}'"
|
23 |
result = sf.query(query)
|
24 |
|
25 |
if len(result['records']) > 0:
|
26 |
return "Email already exists! Please use a different email."
|
27 |
|
28 |
-
# Hash the password
|
29 |
hashed_password = hash_password(password)
|
30 |
|
31 |
-
# Create the new user record
|
32 |
sf.Customer_Login__c.create({
|
33 |
'Name': name.strip(),
|
34 |
'Email__c': email,
|
@@ -43,9 +39,6 @@ def signup(name, email, phone, password):
|
|
43 |
def login(email, password):
|
44 |
try:
|
45 |
email = email.strip()
|
46 |
-
password = password.strip()
|
47 |
-
|
48 |
-
# Query Salesforce for user details
|
49 |
query = f"SELECT Name, Password__c FROM Customer_Login__c WHERE Email__c = '{email}'"
|
50 |
result = sf.query(query)
|
51 |
|
@@ -55,8 +48,7 @@ def login(email, password):
|
|
55 |
user = result['records'][0]
|
56 |
stored_password = user['Password__c']
|
57 |
|
58 |
-
|
59 |
-
if verify_password(password, stored_password):
|
60 |
return "Login successful!", user['Name']
|
61 |
else:
|
62 |
return "Invalid email or password.", None
|
@@ -72,6 +64,15 @@ def load_menu_from_salesforce():
|
|
72 |
except Exception as e:
|
73 |
return []
|
74 |
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
75 |
# Function to filter menu items
|
76 |
def filter_menu(preference):
|
77 |
menu_data = load_menu_from_salesforce()
|
@@ -113,7 +114,17 @@ def filter_menu(preference):
|
|
113 |
|
114 |
# Create Modal Window HTML
|
115 |
def create_modal_window():
|
116 |
-
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
117 |
<div id="modal" style="display: none; position: fixed; background: white; border-radius: 8px; box-shadow: 0 4px 8px rgba(0, 0, 0, 0.2); padding: 20px; z-index: 1000;">
|
118 |
<div style="text-align: right;">
|
119 |
<button onclick="closeModal()" style="background: none; border: none; font-size: 18px; cursor: pointer;">×</button>
|
@@ -122,21 +133,13 @@ def create_modal_window():
|
|
122 |
<h2 id="modal-name"></h2>
|
123 |
<p id="modal-description"></p>
|
124 |
<p id="modal-price"></p>
|
125 |
-
<!-- Add-ons Section -->
|
126 |
<label for="biryani-extras"><strong>Add-ons :</strong></label>
|
127 |
<div id="biryani-extras-options" style="display: flex; flex-wrap: wrap; gap: 10px; margin: 10px 0;">
|
128 |
-
|
129 |
-
<label><input type="checkbox" name="biryani-extra" value="Sprite" /> Sprite + $2.00</label>
|
130 |
-
<label><input type="checkbox" name="biryani-extra" value="Extra Raitha" /> Extra Raitha + $1.00</label>
|
131 |
-
<label><input type="checkbox" name="biryani-extra" value="Extra Salan" /> Extra Salan + $2.00</label>
|
132 |
</div>
|
133 |
-
<!-- Quantity and Special Instructions -->
|
134 |
<label for="quantity">Quantity:</label>
|
135 |
<input type="number" id="quantity" value="1" min="1" style="width: 50px;" />
|
136 |
-
<br><br>
|
137 |
<textarea id="special-instructions" placeholder="Add your special instructions here..." style="width: 100%; height: 60px;"></textarea>
|
138 |
-
<br><br>
|
139 |
-
<!-- Add to Cart Button -->
|
140 |
<button style="background-color: #28a745; color: white; border: none; padding: 10px 20px; font-size: 14px; border-radius: 5px; cursor: pointer;" onclick="addToCart()">Add to Cart</button>
|
141 |
</div>
|
142 |
"""
|
@@ -146,17 +149,14 @@ def create_modal_window():
|
|
146 |
def modal_js():
|
147 |
modal_script = """
|
148 |
<script>
|
|
|
|
|
149 |
function openModal(name, image2, description, price) {
|
150 |
const modal = document.getElementById('modal');
|
151 |
modal.style.display = 'block';
|
152 |
modal.style.position = 'fixed';
|
153 |
-
|
154 |
-
|
155 |
-
modal.style.top = `${event.touches ? event.touches[0].screenY : event.clientY}px`;
|
156 |
-
} else {
|
157 |
-
modal.style.width = '30%';
|
158 |
-
modal.style.top = `${event.clientY}px`;
|
159 |
-
}
|
160 |
modal.style.left = '50%';
|
161 |
modal.style.transform = 'translate(-50%, -50%)';
|
162 |
document.getElementById('modal-image').src = image2;
|
@@ -176,13 +176,39 @@ def modal_js():
|
|
176 |
const price = parseFloat(document.getElementById('modal-price').innerText.replace('$', ''));
|
177 |
const quantity = parseInt(document.getElementById('quantity').value) || 1;
|
178 |
const instructions = document.getElementById('special-instructions').value;
|
179 |
-
const extras = Array.from(document.querySelectorAll('input[name="biryani-extra"]:checked')).map(extra =>
|
180 |
-
|
|
|
|
|
|
|
181 |
const totalCost = (price + extrasCost) * quantity;
|
182 |
-
|
183 |
-
|
184 |
closeModal();
|
185 |
}
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
186 |
</script>
|
187 |
"""
|
188 |
return modal_script
|
@@ -214,6 +240,7 @@ with gr.Blocks() as app:
|
|
214 |
with gr.Column():
|
215 |
preference = gr.Radio(choices=["All", "Veg", "Non-Veg"], label="Filter Preference", value="All")
|
216 |
menu_output = gr.HTML()
|
|
|
217 |
gr.HTML(create_modal_window()) # Add modal window HTML
|
218 |
gr.HTML(modal_js()) # Add modal JavaScript
|
219 |
|
|
|
17 |
def signup(name, email, phone, password):
|
18 |
try:
|
19 |
email = email.strip()
|
|
|
|
|
20 |
query = f"SELECT Id FROM Customer_Login__c WHERE Email__c = '{email}'"
|
21 |
result = sf.query(query)
|
22 |
|
23 |
if len(result['records']) > 0:
|
24 |
return "Email already exists! Please use a different email."
|
25 |
|
|
|
26 |
hashed_password = hash_password(password)
|
27 |
|
|
|
28 |
sf.Customer_Login__c.create({
|
29 |
'Name': name.strip(),
|
30 |
'Email__c': email,
|
|
|
39 |
def login(email, password):
|
40 |
try:
|
41 |
email = email.strip()
|
|
|
|
|
|
|
42 |
query = f"SELECT Name, Password__c FROM Customer_Login__c WHERE Email__c = '{email}'"
|
43 |
result = sf.query(query)
|
44 |
|
|
|
48 |
user = result['records'][0]
|
49 |
stored_password = user['Password__c']
|
50 |
|
51 |
+
if verify_password(password.strip(), stored_password):
|
|
|
52 |
return "Login successful!", user['Name']
|
53 |
else:
|
54 |
return "Invalid email or password.", None
|
|
|
64 |
except Exception as e:
|
65 |
return []
|
66 |
|
67 |
+
# Function to load add-ons data
|
68 |
+
def load_add_ons_from_salesforce():
|
69 |
+
try:
|
70 |
+
query = "SELECT Name, Price__c FROM Add_Ons__c"
|
71 |
+
result = sf.query(query)
|
72 |
+
return result['records']
|
73 |
+
except Exception as e:
|
74 |
+
return []
|
75 |
+
|
76 |
# Function to filter menu items
|
77 |
def filter_menu(preference):
|
78 |
menu_data = load_menu_from_salesforce()
|
|
|
114 |
|
115 |
# Create Modal Window HTML
|
116 |
def create_modal_window():
|
117 |
+
add_ons = load_add_ons_from_salesforce()
|
118 |
+
add_ons_html = ""
|
119 |
+
for add_on in add_ons:
|
120 |
+
add_ons_html += f"""
|
121 |
+
<label>
|
122 |
+
<input type="checkbox" name="biryani-extra" value="{add_on['Name']}" data-price="{add_on['Price__c']}" />
|
123 |
+
{add_on['Name']} + ${add_on['Price__c']}
|
124 |
+
</label>
|
125 |
+
"""
|
126 |
+
|
127 |
+
modal_html = f"""
|
128 |
<div id="modal" style="display: none; position: fixed; background: white; border-radius: 8px; box-shadow: 0 4px 8px rgba(0, 0, 0, 0.2); padding: 20px; z-index: 1000;">
|
129 |
<div style="text-align: right;">
|
130 |
<button onclick="closeModal()" style="background: none; border: none; font-size: 18px; cursor: pointer;">×</button>
|
|
|
133 |
<h2 id="modal-name"></h2>
|
134 |
<p id="modal-description"></p>
|
135 |
<p id="modal-price"></p>
|
|
|
136 |
<label for="biryani-extras"><strong>Add-ons :</strong></label>
|
137 |
<div id="biryani-extras-options" style="display: flex; flex-wrap: wrap; gap: 10px; margin: 10px 0;">
|
138 |
+
{add_ons_html}
|
|
|
|
|
|
|
139 |
</div>
|
|
|
140 |
<label for="quantity">Quantity:</label>
|
141 |
<input type="number" id="quantity" value="1" min="1" style="width: 50px;" />
|
|
|
142 |
<textarea id="special-instructions" placeholder="Add your special instructions here..." style="width: 100%; height: 60px;"></textarea>
|
|
|
|
|
143 |
<button style="background-color: #28a745; color: white; border: none; padding: 10px 20px; font-size: 14px; border-radius: 5px; cursor: pointer;" onclick="addToCart()">Add to Cart</button>
|
144 |
</div>
|
145 |
"""
|
|
|
149 |
def modal_js():
|
150 |
modal_script = """
|
151 |
<script>
|
152 |
+
let cart = [];
|
153 |
+
|
154 |
function openModal(name, image2, description, price) {
|
155 |
const modal = document.getElementById('modal');
|
156 |
modal.style.display = 'block';
|
157 |
modal.style.position = 'fixed';
|
158 |
+
modal.style.width = window.innerWidth <= 768 ? '90%' : '30%';
|
159 |
+
modal.style.top = `${event.clientY}px`;
|
|
|
|
|
|
|
|
|
|
|
160 |
modal.style.left = '50%';
|
161 |
modal.style.transform = 'translate(-50%, -50%)';
|
162 |
document.getElementById('modal-image').src = image2;
|
|
|
176 |
const price = parseFloat(document.getElementById('modal-price').innerText.replace('$', ''));
|
177 |
const quantity = parseInt(document.getElementById('quantity').value) || 1;
|
178 |
const instructions = document.getElementById('special-instructions').value;
|
179 |
+
const extras = Array.from(document.querySelectorAll('input[name="biryani-extra"]:checked')).map(extra => ({
|
180 |
+
name: extra.value,
|
181 |
+
price: parseFloat(extra.getAttribute('data-price') || '0')
|
182 |
+
}));
|
183 |
+
const extrasCost = extras.reduce((total, extra) => total + extra.price, 0);
|
184 |
const totalCost = (price + extrasCost) * quantity;
|
185 |
+
cart.push({ name, price, quantity, extras, instructions, totalCost });
|
186 |
+
updateCartUI();
|
187 |
closeModal();
|
188 |
}
|
189 |
+
|
190 |
+
function updateCartUI() {
|
191 |
+
const cartContainer = document.getElementById('cart-container');
|
192 |
+
cartContainer.innerHTML = "";
|
193 |
+
cart.forEach((item, index) => {
|
194 |
+
const extrasList = item.extras.map(extra => `${extra.name} (+$${extra.price.toFixed(2)})`).join(', ');
|
195 |
+
cartContainer.innerHTML += `
|
196 |
+
<div style="border: 1px solid #ddd; padding: 10px; margin-bottom: 10px; border-radius: 8px;">
|
197 |
+
<h3>${item.name}</h3>
|
198 |
+
<p>Quantity: ${item.quantity}</p>
|
199 |
+
<p>Extras: ${extrasList || 'None'}</p>
|
200 |
+
<p>Special Instructions: ${item.instructions || 'None'}</p>
|
201 |
+
<p>Total Cost: $${item.totalCost.toFixed(2)}</p>
|
202 |
+
<button onclick="removeFromCart(${index})" style="color: red;">Remove</button>
|
203 |
+
</div>
|
204 |
+
`;
|
205 |
+
});
|
206 |
+
}
|
207 |
+
|
208 |
+
function removeFromCart(index) {
|
209 |
+
cart.splice(index, 1);
|
210 |
+
updateCartUI();
|
211 |
+
}
|
212 |
</script>
|
213 |
"""
|
214 |
return modal_script
|
|
|
240 |
with gr.Column():
|
241 |
preference = gr.Radio(choices=["All", "Veg", "Non-Veg"], label="Filter Preference", value="All")
|
242 |
menu_output = gr.HTML()
|
243 |
+
gr.HTML("<div id='cart-container' style='margin-top: 20px; padding: 10px; border: 1px solid #ddd; border-radius: 8px; background-color: #f9f9f9;'>Your cart is empty.</div>")
|
244 |
gr.HTML(create_modal_window()) # Add modal window HTML
|
245 |
gr.HTML(modal_js()) # Add modal JavaScript
|
246 |
|