Spaces:
Running
Running
Update app.py
Browse files
app.py
CHANGED
@@ -11,7 +11,8 @@ app = Flask(__name__)
|
|
11 |
sf = get_salesforce_connection()
|
12 |
|
13 |
# Set the secret key to handle sessions securely
|
14 |
-
app.secret_key = os.getenv("
|
|
|
15 |
|
16 |
@app.route("/")
|
17 |
def home():
|
@@ -41,41 +42,50 @@ def login():
|
|
41 |
if request.method == "POST":
|
42 |
email = request.form.get("email")
|
43 |
password = request.form.get("password")
|
44 |
-
|
|
|
45 |
try:
|
46 |
query = f"SELECT Id, Name, Email__c FROM Customer_Login__c WHERE Email__c='{email}' AND Password__c='{password}'"
|
47 |
result = sf.query(query)
|
|
|
48 |
if result["records"]:
|
49 |
session['user_id'] = result["records"][0]['Id']
|
50 |
session['user_email'] = email
|
|
|
51 |
return redirect(url_for("menu"))
|
52 |
-
print(f"Session variables: {session}")
|
53 |
else:
|
54 |
return render_template("login.html", error="Invalid credentials!")
|
55 |
except Exception as e:
|
56 |
return render_template("login.html", error=f"Error: {str(e)}")
|
|
|
57 |
return render_template("login.html")
|
58 |
|
|
|
59 |
@app.route("/menu", methods=["GET", "POST"])
|
60 |
def menu():
|
61 |
selected_category = request.args.get("category", "All")
|
62 |
user_id = session.get('user_id')
|
|
|
63 |
if not user_id:
|
|
|
64 |
return redirect(url_for('login'))
|
65 |
-
|
66 |
try:
|
67 |
query = "SELECT Name, Price__c, Image1__c, Category__c, Description__c FROM Menu_Item__c"
|
68 |
result = sf.query(query)
|
69 |
food_items = result['records'] if 'records' in result else []
|
70 |
categories = {item['Category__c'] for item in food_items if 'Category__c' in item}
|
|
|
71 |
if selected_category != "All":
|
72 |
food_items = [item for item in food_items if item.get("Category__c") == selected_category]
|
73 |
except Exception as e:
|
74 |
food_items = []
|
75 |
categories = []
|
76 |
print(f"Error fetching data: {e}")
|
|
|
77 |
return render_template("menu.html", food_items=food_items, categories=categories, selected_category=selected_category)
|
78 |
|
|
|
79 |
@app.route("/cart", methods=["GET"])
|
80 |
def cart():
|
81 |
email = session.get('user_email') # Get logged-in user's email
|
@@ -271,6 +281,4 @@ def checkout():
|
|
271 |
return jsonify({"success": False, "error": str(e)})
|
272 |
|
273 |
if __name__ == "__main__":
|
274 |
-
|
275 |
-
port = int(os.environ.get("PORT", 7860)) # Default to 7860
|
276 |
-
app.run(host="0.0.0.0", port=port, debug=False)
|
|
|
11 |
sf = get_salesforce_connection()
|
12 |
|
13 |
# Set the secret key to handle sessions securely
|
14 |
+
app.secret_key = os.getenv("SECRET_KEY", "sSSjyhInIsUohKpG8sHzty2q") # Replace with a secure key
|
15 |
+
|
16 |
|
17 |
@app.route("/")
|
18 |
def home():
|
|
|
42 |
if request.method == "POST":
|
43 |
email = request.form.get("email")
|
44 |
password = request.form.get("password")
|
45 |
+
print(f"Login attempt with email: {email}") # Correctly indented print statement
|
46 |
+
|
47 |
try:
|
48 |
query = f"SELECT Id, Name, Email__c FROM Customer_Login__c WHERE Email__c='{email}' AND Password__c='{password}'"
|
49 |
result = sf.query(query)
|
50 |
+
|
51 |
if result["records"]:
|
52 |
session['user_id'] = result["records"][0]['Id']
|
53 |
session['user_email'] = email
|
54 |
+
print(f"Session variables: {session}") # Moved print statement before return
|
55 |
return redirect(url_for("menu"))
|
|
|
56 |
else:
|
57 |
return render_template("login.html", error="Invalid credentials!")
|
58 |
except Exception as e:
|
59 |
return render_template("login.html", error=f"Error: {str(e)}")
|
60 |
+
|
61 |
return render_template("login.html")
|
62 |
|
63 |
+
|
64 |
@app.route("/menu", methods=["GET", "POST"])
|
65 |
def menu():
|
66 |
selected_category = request.args.get("category", "All")
|
67 |
user_id = session.get('user_id')
|
68 |
+
|
69 |
if not user_id:
|
70 |
+
print(f"Session data: {session}") # Moved print statement before return
|
71 |
return redirect(url_for('login'))
|
72 |
+
|
73 |
try:
|
74 |
query = "SELECT Name, Price__c, Image1__c, Category__c, Description__c FROM Menu_Item__c"
|
75 |
result = sf.query(query)
|
76 |
food_items = result['records'] if 'records' in result else []
|
77 |
categories = {item['Category__c'] for item in food_items if 'Category__c' in item}
|
78 |
+
|
79 |
if selected_category != "All":
|
80 |
food_items = [item for item in food_items if item.get("Category__c") == selected_category]
|
81 |
except Exception as e:
|
82 |
food_items = []
|
83 |
categories = []
|
84 |
print(f"Error fetching data: {e}")
|
85 |
+
|
86 |
return render_template("menu.html", food_items=food_items, categories=categories, selected_category=selected_category)
|
87 |
|
88 |
+
|
89 |
@app.route("/cart", methods=["GET"])
|
90 |
def cart():
|
91 |
email = session.get('user_email') # Get logged-in user's email
|
|
|
281 |
return jsonify({"success": False, "error": str(e)})
|
282 |
|
283 |
if __name__ == "__main__":
|
284 |
+
app.run(debug=True, host="0.0.0.0", port=8000))
|
|
|
|