Update app.py
Browse files
app.py
CHANGED
|
@@ -73,64 +73,9 @@ def home():
|
|
| 73 |
session.modified = True
|
| 74 |
return redirect(url_for("menu.menu")) # Redirect to menu directly
|
| 75 |
return render_template("index.html")
|
| 76 |
-
@app.route("/login", methods=["GET", "POST"])
|
| 77 |
-
def login():
|
| 78 |
-
if request.method == "POST":
|
| 79 |
-
email = request.form.get("email")
|
| 80 |
-
password = request.form.get("password")
|
| 81 |
-
print(f"Login attempt with email: {email}") # Debug log
|
| 82 |
-
|
| 83 |
-
try:
|
| 84 |
-
# Fetch user details from Salesforce
|
| 85 |
-
query = f"SELECT Id, Name, Email__c, Reward_Points__c FROM Customer_Login__c WHERE Email__c='{email}' AND Password__c='{password}'"
|
| 86 |
-
result = sf.query(query)
|
| 87 |
-
|
| 88 |
-
if result["records"]:
|
| 89 |
-
user = result["records"][0]
|
| 90 |
-
session['user_id'] = user['Id']
|
| 91 |
-
|
| 92 |
-
# ✅ Always store or update session email
|
| 93 |
-
if 'user_email' not in session or session['user_email'] != email:
|
| 94 |
-
session['user_email'] = email
|
| 95 |
-
session['user_name'] = user.get("Name", "")
|
| 96 |
-
print(f"✅ Session email updated: {session['user_email']}")
|
| 97 |
-
|
| 98 |
-
reward_points = user.get("Reward_Points__c") or 0
|
| 99 |
-
|
| 100 |
-
# Coupon generation logic (if reward points >= 500)
|
| 101 |
-
if reward_points >= 500:
|
| 102 |
-
new_coupon_code = generate_coupon_code()
|
| 103 |
-
coupon_query = sf.query(f"SELECT Id, Coupon_Code__c FROM Referral_Coupon__c WHERE Referral_Email__c = '{email}'")
|
| 104 |
-
|
| 105 |
-
if coupon_query["records"]:
|
| 106 |
-
coupon_record = coupon_query["records"][0]
|
| 107 |
-
referral_coupon_id = coupon_record["Id"]
|
| 108 |
-
existing_coupons = coupon_record.get("Coupon_Code__c", "")
|
| 109 |
-
|
| 110 |
-
updated_coupons = f"{existing_coupons}\n{new_coupon_code}".strip()
|
| 111 |
-
sf.Referral_Coupon__c.update(referral_coupon_id, {"Coupon_Code__c": updated_coupons})
|
| 112 |
-
else:
|
| 113 |
-
sf.Referral_Coupon__c.create({
|
| 114 |
-
"Referral_Email__c": email,
|
| 115 |
-
"Name": user.get("Name", ""),
|
| 116 |
-
"Coupon_Code__c": new_coupon_code
|
| 117 |
-
})
|
| 118 |
-
|
| 119 |
-
new_reward_points = reward_points - 500
|
| 120 |
-
sf.Customer_Login__c.update(user['Id'], {"Reward_Points__c": new_reward_points})
|
| 121 |
-
|
| 122 |
-
return redirect(url_for("menu.menu"))
|
| 123 |
-
|
| 124 |
-
else:
|
| 125 |
-
print("Invalid credentials!")
|
| 126 |
-
return render_template("login.html", error="Invalid credentials!")
|
| 127 |
-
|
| 128 |
-
except Exception as e:
|
| 129 |
-
print(f"Error during login: {str(e)}")
|
| 130 |
-
return render_template("login.html", error=f"Error: {str(e)}")
|
| 131 |
-
|
| 132 |
-
return render_template("login.html")
|
| 133 |
|
|
|
|
|
|
|
| 134 |
|
| 135 |
@app.route("/logout")
|
| 136 |
def logout():
|
|
|
|
| 73 |
session.modified = True
|
| 74 |
return redirect(url_for("menu.menu")) # Redirect to menu directly
|
| 75 |
return render_template("index.html")
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
| 76 |
|
| 77 |
+
|
| 78 |
+
|
| 79 |
|
| 80 |
@app.route("/logout")
|
| 81 |
def logout():
|