nagasurendra commited on
Commit
f781f94
·
verified ·
1 Parent(s): ea19960

Update app.py

Browse files
Files changed (1) hide show
  1. app.py +54 -0
app.py CHANGED
@@ -118,6 +118,60 @@ def login():
118
  return render_template("login.html", error=f"Error: {str(e)}")
119
 
120
  return render_template("login.html")
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
121
  @app.route("/logout")
122
  def logout():
123
  # Retrieve table number before clearing session
 
118
  return render_template("login.html", error=f"Error: {str(e)}")
119
 
120
  return render_template("login.html")
121
+ @app.route('/reward_status')
122
+ def reward_status():
123
+ # Get the user email from session (assuming the session is already set during checkout)
124
+ email = session.get('user_email')
125
+
126
+ if not email:
127
+ return "User not logged in", 400
128
+
129
+ # Query Salesforce to fetch the user's reward points
130
+ query = f"SELECT Id, Reward_Points__c FROM Customer_Login__c WHERE Email__c = '{email}'"
131
+ user_data = query_salesforce(query)
132
+
133
+ # Check if the user record was found
134
+ if not user_data.get("records"):
135
+ return "User not found", 400
136
+
137
+ # Get the user's reward points from Salesforce
138
+ user_points = user_data["records"][0].get("Reward_Points__c", 0)
139
+
140
+ # Define point ranges for each tier
141
+ tiers = {
142
+ "Bronze": 1,
143
+ "Silver": 100,
144
+ "Gold": 300,
145
+ "Platinum": 500
146
+ }
147
+
148
+ # Get the user's current tier and the points required for the next tier
149
+ current_tier = ""
150
+ points_needed_for_next_tier = 0
151
+
152
+ for tier, threshold in tiers.items():
153
+ if user_points < threshold:
154
+ current_tier = tier
155
+ points_needed_for_next_tier = threshold - user_points
156
+ break
157
+ else:
158
+ current_tier = tier
159
+ points_needed_for_next_tier = 0
160
+
161
+ # Progress bar logic (percentage for current tier progress)
162
+ if current_tier != "Platinum":
163
+ next_tier_threshold = tiers[current_tier] if current_tier else 0
164
+ progress_percentage = (user_points - next_tier_threshold) / (tiers.get(current_tier, 500) - next_tier_threshold) * 100
165
+ else:
166
+ progress_percentage = 100
167
+
168
+ return render_template(
169
+ 'reward_status.html',
170
+ user_points=user_points,
171
+ current_tier=current_tier,
172
+ points_needed_for_next_tier=points_needed_for_next_tier,
173
+ progress_percentage=progress_percentage
174
+ )
175
  @app.route("/logout")
176
  def logout():
177
  # Retrieve table number before clearing session