Spaces:
Sleeping
Sleeping
Update app.py
Browse files
app.py
CHANGED
@@ -130,10 +130,9 @@ def login():
|
|
130 |
print(f"Login attempt with email: {email}") # Debug log
|
131 |
|
132 |
try:
|
133 |
-
# Fetch user details, including Reward_Points__c
|
134 |
query = f"SELECT Id, Name, Email__c, Reward_Points__c FROM Customer_Login__c WHERE Email__c='{email}' AND Password__c='{password}'"
|
135 |
result = sf.query(query)
|
136 |
-
referrer_name = referrer.get('Name')
|
137 |
|
138 |
if result["records"]:
|
139 |
user = result["records"][0]
|
@@ -141,6 +140,7 @@ def login():
|
|
141 |
session['user_email'] = email
|
142 |
print(f"Session variables set: user_id={session['user_id']}, user_email={session['user_email']}")
|
143 |
|
|
|
144 |
reward_points = user.get("Reward_Points__c", 0)
|
145 |
|
146 |
if reward_points >= 500:
|
@@ -169,13 +169,13 @@ def login():
|
|
169 |
})
|
170 |
print(f"Updated existing coupon record for {email}. New Coupon: {new_coupon_code}")
|
171 |
else:
|
172 |
-
# If no record exists, create a new one
|
173 |
sf.Referral_Coupon__c.create({
|
174 |
-
"Name": referrer_name,
|
175 |
"Referral_Email__c": email,
|
|
|
176 |
"Coupon_Code__c": new_coupon_code
|
177 |
})
|
178 |
-
print(f"Created new coupon record for {email}. Coupon: {new_coupon_code}")
|
179 |
|
180 |
# Subtract 500 reward points from user's account
|
181 |
new_reward_points = reward_points - 500
|
|
|
130 |
print(f"Login attempt with email: {email}") # Debug log
|
131 |
|
132 |
try:
|
133 |
+
# Fetch user details, including Name and Reward_Points__c
|
134 |
query = f"SELECT Id, Name, Email__c, Reward_Points__c FROM Customer_Login__c WHERE Email__c='{email}' AND Password__c='{password}'"
|
135 |
result = sf.query(query)
|
|
|
136 |
|
137 |
if result["records"]:
|
138 |
user = result["records"][0]
|
|
|
140 |
session['user_email'] = email
|
141 |
print(f"Session variables set: user_id={session['user_id']}, user_email={session['user_email']}")
|
142 |
|
143 |
+
user_name = user.get("Name", "") # Get the user's name
|
144 |
reward_points = user.get("Reward_Points__c", 0)
|
145 |
|
146 |
if reward_points >= 500:
|
|
|
169 |
})
|
170 |
print(f"Updated existing coupon record for {email}. New Coupon: {new_coupon_code}")
|
171 |
else:
|
172 |
+
# If no record exists, create a new one with Referral_Name__c
|
173 |
sf.Referral_Coupon__c.create({
|
|
|
174 |
"Referral_Email__c": email,
|
175 |
+
"Name": user_name, # Store user's name in Referral_Coupon__c
|
176 |
"Coupon_Code__c": new_coupon_code
|
177 |
})
|
178 |
+
print(f"Created new coupon record for {email} with name {user_name}. Coupon: {new_coupon_code}")
|
179 |
|
180 |
# Subtract 500 reward points from user's account
|
181 |
new_reward_points = reward_points - 500
|