nagasurendra commited on
Commit
2c776f8
·
verified ·
1 Parent(s): ce1d604

Update app.py

Browse files
Files changed (1) hide show
  1. app.py +1 -84
app.py CHANGED
@@ -166,91 +166,8 @@ def generate_custom_dish():
166
  except Exception as e:
167
  return jsonify({"success": False, "error": str(e)}), 500
168
 
169
- @app.route("/customer_details", methods=["GET"])
170
- def customer_details():
171
- email = session.get('user_email') # Get logged-in user's email
172
- if not email:
173
- return redirect(url_for("login"))
174
-
175
- try:
176
- # Fetch customer details from Salesforce based on the email
177
- customer_record = sf.query(f"""
178
- SELECT Id, Name, Email__c, Phone_Number__c, Referral__c, Reward_Points__c
179
- FROM Customer_Login__c
180
- WHERE Email__c = '{email}'
181
- LIMIT 1
182
- """)
183
-
184
- if not customer_record.get("records"):
185
- flash("Customer not found", "danger")
186
- return redirect(url_for("login"))
187
-
188
- customer = customer_record["records"][0]
189
-
190
- # Prepare the data to return to the frontend
191
- customer_data = {
192
- "name": customer.get("Name", ""),
193
- "email": customer.get("Email__c", ""),
194
- "phone": customer.get("Phone_Number__c", ""),
195
- "referral_code": customer.get("Referral__c", ""),
196
- "reward_points": customer.get("Reward_Points__c", 0)
197
- }
198
-
199
- return render_template("customer_details.html", customer=customer_data)
200
-
201
- except Exception as e:
202
- flash(f"Error fetching customer details: {str(e)}", "danger")
203
- return redirect(url_for("login"))
204
-
205
- @app.route("/update_profile", methods=["POST"])
206
- def update_profile():
207
- email = session.get('user_email') # Get logged-in user's email
208
- if not email:
209
- return jsonify({'status': 'error', 'message': 'User not logged in'})
210
-
211
- try:
212
- # Fetch user details from Salesforce
213
- result = sf.query(f"""
214
- SELECT Id, Name, Email__c, Phone_Number__c, Referral__c, Reward_Points__c
215
- FROM Customer_Login__c
216
- WHERE Email__c = '{email}'
217
- """)
218
-
219
- if not result['records']:
220
- return jsonify({'status': 'error', 'message': 'User not found'})
221
-
222
- user = result['records'][0]
223
- user_id = user.get("Id")
224
-
225
- # Get updated profile data from the form
226
- new_name = request.form.get('customerName')
227
- new_email = request.form.get('email')
228
- new_phone = request.form.get('phone')
229
- new_referral_code = request.form.get('referralCode')
230
- new_reward_points = request.form.get('rewardPoints')
231
-
232
- # Prepare data for Salesforce update
233
- update_data = {
234
- 'Name': new_name,
235
- 'Email__c': new_email,
236
- 'Phone_Number__c': new_phone,
237
- 'Referral__c': new_referral_code,
238
- 'Reward_Points__c': new_reward_points
239
- }
240
-
241
- # Update Salesforce record
242
- sf.Customer_Login__c.update(user_id, update_data)
243
-
244
- return jsonify({
245
- 'status': 'success',
246
- 'message': 'Profile updated successfully!',
247
- 'data': update_data
248
- })
249
-
250
- except Exception as e:
251
- return jsonify({'status': 'error', 'message': str(e)})
252
-
253
 
 
254
 
255
  from datetime import datetime
256
  import pytz # Library to handle timezone conversions
 
166
  except Exception as e:
167
  return jsonify({"success": False, "error": str(e)}), 500
168
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
169
 
170
+
171
 
172
  from datetime import datetime
173
  import pytz # Library to handle timezone conversions