Update app.py
Browse files
app.py
CHANGED
@@ -37,11 +37,6 @@ print("Session interface configured.")
|
|
37 |
import random
|
38 |
import string
|
39 |
app.register_blueprint(cart_blueprint, url_prefix='/cart')
|
40 |
-
def generate_referral_code(length=8):
|
41 |
-
# Generates a random referral code with uppercase, lowercase letters, and digits
|
42 |
-
characters = string.ascii_letters + string.digits # A-Z, a-z, 0-9
|
43 |
-
referral_code = ''.join(random.choice(characters) for _ in range(length))
|
44 |
-
return referral_code
|
45 |
|
46 |
@app.route("/")
|
47 |
def home():
|
@@ -66,10 +61,7 @@ def home():
|
|
66 |
|
67 |
from datetime import datetime
|
68 |
|
69 |
-
|
70 |
-
"""Generates a random alphanumeric coupon code"""
|
71 |
-
characters = string.ascii_uppercase + string.digits # A-Z, 0-9
|
72 |
-
return ''.join(random.choice(characters) for _ in range(length))
|
73 |
@app.route("/generate_custom_dish", methods=["POST"])
|
74 |
def generate_custom_dish():
|
75 |
try:
|
@@ -269,86 +261,6 @@ def logout():
|
|
269 |
# Pass table number to redirect page
|
270 |
return render_template("redirect_page.html", table_number=table_number)
|
271 |
|
272 |
-
@app.route("/signup", methods=["GET", "POST"])
|
273 |
-
def signup():
|
274 |
-
if request.method == "POST":
|
275 |
-
name = request.form.get("name")
|
276 |
-
phone = request.form.get("phone")
|
277 |
-
email = request.form.get("email").strip() # Trim spaces
|
278 |
-
password = request.form.get("password")
|
279 |
-
referral_code = request.form.get("referral") # Fetch referral code from the form
|
280 |
-
generated_referral_code = generate_referral_code()
|
281 |
-
|
282 |
-
try:
|
283 |
-
ref = 0 # Default reward points for new user
|
284 |
-
|
285 |
-
# **Fix: Fetch all emails and compare in Python (Case-Insensitive)**
|
286 |
-
email_query = "SELECT Id, Email__c FROM Customer_Login__c"
|
287 |
-
email_result = sf.query(email_query)
|
288 |
-
|
289 |
-
# Convert all stored emails to lowercase and compare with user input
|
290 |
-
existing_emails = {record["Email__c"].lower() for record in email_result["records"]}
|
291 |
-
if email.lower() in existing_emails:
|
292 |
-
return render_template("signup.html", error="Email already in use! Please use a different email.")
|
293 |
-
|
294 |
-
# Check if a referral code is entered
|
295 |
-
if referral_code:
|
296 |
-
referral_query = f"SELECT Id, Email__c, Name FROM Customer_Login__c WHERE Referral__c = '{referral_code}'"
|
297 |
-
referral_result = sf.query(referral_query)
|
298 |
-
|
299 |
-
if not referral_result['records']:
|
300 |
-
return render_template("signup.html", error="Invalid referral code!")
|
301 |
-
|
302 |
-
# Get referrer's details
|
303 |
-
referrer = referral_result['records'][0]
|
304 |
-
referrer_email = referrer.get('Email__c')
|
305 |
-
referrer_name = referrer.get('Name')
|
306 |
-
|
307 |
-
# Generate a new unique coupon code
|
308 |
-
new_coupon_code = generate_coupon_code()
|
309 |
-
|
310 |
-
# Check if referrer already has a record in Referral_Coupon__c
|
311 |
-
existing_coupon_query = f"SELECT Id, Coupon_Code__c FROM Referral_Coupon__c WHERE Referral_Email__c = '{referrer_email}'"
|
312 |
-
existing_coupon_result = sf.query(existing_coupon_query)
|
313 |
-
|
314 |
-
if existing_coupon_result['records']:
|
315 |
-
referral_record = existing_coupon_result['records'][0]
|
316 |
-
referral_id = referral_record['Id']
|
317 |
-
existing_coupons = referral_record.get('Coupon_Code__c', '')
|
318 |
-
|
319 |
-
updated_coupons = f"{existing_coupons}\n{new_coupon_code}".strip()
|
320 |
-
|
321 |
-
# Update the existing record with the new coupon
|
322 |
-
sf.Referral_Coupon__c.update(referral_id, {
|
323 |
-
"Coupon_Code__c": updated_coupons
|
324 |
-
})
|
325 |
-
else:
|
326 |
-
# If no record exists, create a new one
|
327 |
-
sf.Referral_Coupon__c.create({
|
328 |
-
"Name": referrer_name,
|
329 |
-
"Referral_Email__c": referrer_email,
|
330 |
-
"Coupon_Code__c": new_coupon_code
|
331 |
-
})
|
332 |
-
|
333 |
-
# **Fix: Ensure Salesforce enforces unique email constraint**
|
334 |
-
sf.Customer_Login__c.create({
|
335 |
-
"Name": name,
|
336 |
-
"Phone_Number__c": phone,
|
337 |
-
"Email__c": email,
|
338 |
-
"Password__c": password,
|
339 |
-
"Reward_Points__c": ref, # No points added, only coupon is created
|
340 |
-
"Referral__c": generated_referral_code
|
341 |
-
})
|
342 |
-
|
343 |
-
return redirect(url_for("login"))
|
344 |
-
|
345 |
-
except Exception as e:
|
346 |
-
return render_template("signup.html", error=f"Error: {str(e)}")
|
347 |
-
|
348 |
-
return render_template("signup.html")
|
349 |
-
|
350 |
-
|
351 |
-
|
352 |
|
353 |
@app.route("/login", methods=["GET", "POST"])
|
354 |
def login():
|
|
|
37 |
import random
|
38 |
import string
|
39 |
app.register_blueprint(cart_blueprint, url_prefix='/cart')
|
|
|
|
|
|
|
|
|
|
|
40 |
|
41 |
@app.route("/")
|
42 |
def home():
|
|
|
61 |
|
62 |
from datetime import datetime
|
63 |
|
64 |
+
|
|
|
|
|
|
|
65 |
@app.route("/generate_custom_dish", methods=["POST"])
|
66 |
def generate_custom_dish():
|
67 |
try:
|
|
|
261 |
# Pass table number to redirect page
|
262 |
return render_template("redirect_page.html", table_number=table_number)
|
263 |
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
264 |
|
265 |
@app.route("/login", methods=["GET", "POST"])
|
266 |
def login():
|