Spaces:
Sleeping
Sleeping
Update app.py
Browse files
app.py
CHANGED
@@ -49,20 +49,46 @@ def signup():
|
|
49 |
phone = request.form.get("phone")
|
50 |
email = request.form.get("email")
|
51 |
password = request.form.get("password")
|
52 |
-
referral_code =
|
|
|
|
|
53 |
try:
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
54 |
sf.Customer_Login__c.create({
|
55 |
"Name": name,
|
56 |
"Phone_Number__c": phone,
|
57 |
"Email__c": email,
|
58 |
"Password__c": password,
|
59 |
-
"Referral__c":
|
60 |
})
|
61 |
return redirect(url_for("login"))
|
|
|
62 |
except Exception as e:
|
63 |
return render_template("signup.html", error=f"Error: {str(e)}")
|
64 |
return render_template("signup.html")
|
65 |
|
|
|
66 |
@app.route("/login", methods=["GET", "POST"])
|
67 |
def login():
|
68 |
if request.method == "POST":
|
|
|
49 |
phone = request.form.get("phone")
|
50 |
email = request.form.get("email")
|
51 |
password = request.form.get("password")
|
52 |
+
referral_code = request.form.get("referral") # Fetch referral code from the form
|
53 |
+
generated_referral_code = generate_referral_code()
|
54 |
+
|
55 |
try:
|
56 |
+
# Check if a referral code is entered
|
57 |
+
if referral_code:
|
58 |
+
# Query Salesforce to check if the referral code exists
|
59 |
+
referral_query = f"SELECT Id, Reward_Points__c FROM Customer_Login__c WHERE Referral__c = '{referral_code}'"
|
60 |
+
referral_result = sf.query(referral_query)
|
61 |
+
|
62 |
+
if not referral_result['records']:
|
63 |
+
# If referral code does not exist, show an error message
|
64 |
+
return render_template("signup.html", error="Invalid referral code!")
|
65 |
+
|
66 |
+
# If referral exists, get the first matching record
|
67 |
+
referrer = referral_result['records'][0]
|
68 |
+
referrer_id = referrer['Id']
|
69 |
+
existing_reward_points = referrer.get('Reward_Points__c', 0)
|
70 |
+
|
71 |
+
# Add 100 points to the referrer's Reward_Points__c field
|
72 |
+
updated_reward_points = existing_reward_points + 100
|
73 |
+
sf.Customer_Login__c.update(referrer_id, {
|
74 |
+
"Reward_Points__c": updated_reward_points
|
75 |
+
})
|
76 |
+
|
77 |
+
# Create the new customer record in Salesforce
|
78 |
sf.Customer_Login__c.create({
|
79 |
"Name": name,
|
80 |
"Phone_Number__c": phone,
|
81 |
"Email__c": email,
|
82 |
"Password__c": password,
|
83 |
+
"Referral__c": generated_referral_code
|
84 |
})
|
85 |
return redirect(url_for("login"))
|
86 |
+
|
87 |
except Exception as e:
|
88 |
return render_template("signup.html", error=f"Error: {str(e)}")
|
89 |
return render_template("signup.html")
|
90 |
|
91 |
+
|
92 |
@app.route("/login", methods=["GET", "POST"])
|
93 |
def login():
|
94 |
if request.method == "POST":
|