Spaces:
Runtime error
Runtime error
Update app.py
Browse files
app.py
CHANGED
|
@@ -66,6 +66,60 @@ def generate_coupon_code(length=10):
|
|
| 66 |
|
| 67 |
|
| 68 |
import re
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
| 69 |
|
| 70 |
import re
|
| 71 |
@app.route("/customer_details", methods=["GET"])
|
|
|
|
| 66 |
|
| 67 |
|
| 68 |
import re
|
| 69 |
+
@app.route("/edit_profile", methods=["GET", "POST"])
|
| 70 |
+
def edit_profile():
|
| 71 |
+
user_email = session.get('user_email')
|
| 72 |
+
|
| 73 |
+
if not user_email:
|
| 74 |
+
return redirect(url_for('login')) # If user is not logged in, redirect to login page
|
| 75 |
+
|
| 76 |
+
try:
|
| 77 |
+
# Fetch current user details from Salesforce
|
| 78 |
+
user_query = f"SELECT Name, Email__c, Phone_Number__c FROM Customer_Login__c WHERE Email__c = '{user_email}'"
|
| 79 |
+
user_result = sf.query(user_query)
|
| 80 |
+
|
| 81 |
+
if not user_result['records']:
|
| 82 |
+
return redirect(url_for('login')) # If no user found, redirect to login
|
| 83 |
+
|
| 84 |
+
current_user = user_result['records'][0]
|
| 85 |
+
user_name = current_user.get('Name')
|
| 86 |
+
user_phone = current_user.get('Phone_Number__c')
|
| 87 |
+
user_email = current_user.get('Email__c')
|
| 88 |
+
|
| 89 |
+
except Exception as e:
|
| 90 |
+
print(f"Error fetching user data: {str(e)}")
|
| 91 |
+
return jsonify({"success": False, "message": "Error fetching user data"})
|
| 92 |
+
|
| 93 |
+
# Handle form submission if POST request
|
| 94 |
+
if request.method == 'POST':
|
| 95 |
+
new_name = request.form.get('name')
|
| 96 |
+
new_email = request.form.get('email')
|
| 97 |
+
new_phone = request.form.get('phone')
|
| 98 |
+
new_password = request.form.get('password') # Assuming password change is optional
|
| 99 |
+
|
| 100 |
+
# Update the customer details in Salesforce
|
| 101 |
+
try:
|
| 102 |
+
# Create the update dictionary
|
| 103 |
+
update_data = {
|
| 104 |
+
'Name': new_name,
|
| 105 |
+
'Email__c': new_email,
|
| 106 |
+
'Phone_Number__c': new_phone
|
| 107 |
+
}
|
| 108 |
+
|
| 109 |
+
# Only update password if provided
|
| 110 |
+
if new_password:
|
| 111 |
+
update_data['Password__c'] = new_password
|
| 112 |
+
|
| 113 |
+
# Update user details in Salesforce
|
| 114 |
+
sf.Customer_Login__c.update(current_user['Id'], update_data)
|
| 115 |
+
flash("Profile updated successfully!", "success")
|
| 116 |
+
return redirect(url_for('customer_details')) # Redirect back to profile page
|
| 117 |
+
|
| 118 |
+
except Exception as e:
|
| 119 |
+
flash(f"Error updating profile: {str(e)}", "danger")
|
| 120 |
+
return render_template('edit_profile.html', user_name=user_name, user_phone=user_phone, user_email=user_email)
|
| 121 |
+
|
| 122 |
+
return render_template('edit_profile.html', user_name=user_name, user_phone=user_phone, user_email=user_email)
|
| 123 |
|
| 124 |
import re
|
| 125 |
@app.route("/customer_details", methods=["GET"])
|