Spaces:
Sleeping
Sleeping
Update app.py
Browse files
app.py
CHANGED
@@ -1,8 +1,7 @@
|
|
1 |
from flask import Flask, render_template, request, jsonify, redirect, url_for, session
|
2 |
-
import random
|
3 |
-
from salesforce import get_salesforce_connection
|
4 |
import os
|
5 |
from flask_session import Session
|
|
|
6 |
|
7 |
# Initialize Flask app and Salesforce connection
|
8 |
print("Starting app...")
|
@@ -17,7 +16,7 @@ print("Salesforce connection established.")
|
|
17 |
app.secret_key = os.getenv("SECRET_KEY", "sSSjyhInIsUohKpG8sHzty2q") # Replace with a secure key
|
18 |
app.config["SESSION_TYPE"] = "filesystem"
|
19 |
|
20 |
-
#
|
21 |
Session(app)
|
22 |
print("Session configured.")
|
23 |
|
@@ -49,7 +48,7 @@ def login():
|
|
49 |
if request.method == "POST":
|
50 |
email = request.form.get("email")
|
51 |
password = request.form.get("password")
|
52 |
-
print(f"Login attempt with email: {email}") #
|
53 |
|
54 |
try:
|
55 |
query = f"SELECT Id, Name, Email__c FROM Customer_Login__c WHERE Email__c='{email}' AND Password__c='{password}'"
|
@@ -58,22 +57,26 @@ def login():
|
|
58 |
if result["records"]:
|
59 |
session['user_id'] = result["records"][0]['Id']
|
60 |
session['user_email'] = email
|
61 |
-
print(f"Session variables: {session}")
|
62 |
return redirect(url_for("menu"))
|
63 |
else:
|
|
|
64 |
return render_template("login.html", error="Invalid credentials!")
|
65 |
except Exception as e:
|
|
|
66 |
return render_template("login.html", error=f"Error: {str(e)}")
|
67 |
|
68 |
return render_template("login.html")
|
69 |
|
70 |
-
|
71 |
@app.route("/menu", methods=["GET", "POST"])
|
72 |
def menu():
|
73 |
selected_category = request.args.get("category", "All")
|
74 |
user_id = session.get('user_id')
|
|
|
|
|
75 |
if not user_id:
|
76 |
-
|
|
|
77 |
|
78 |
try:
|
79 |
query = "SELECT Name, Price__c, Image1__c, Category__c, Description__c FROM Menu_Item__c"
|
@@ -83,6 +86,7 @@ def menu():
|
|
83 |
if selected_category != "All":
|
84 |
food_items = [item for item in food_items if item.get("Category__c") == selected_category]
|
85 |
except Exception as e:
|
|
|
86 |
food_items = []
|
87 |
categories = []
|
88 |
return render_template("menu.html", food_items=food_items, categories=categories, selected_category=selected_category)
|
|
|
1 |
from flask import Flask, render_template, request, jsonify, redirect, url_for, session
|
|
|
|
|
2 |
import os
|
3 |
from flask_session import Session
|
4 |
+
from salesforce import get_salesforce_connection
|
5 |
|
6 |
# Initialize Flask app and Salesforce connection
|
7 |
print("Starting app...")
|
|
|
16 |
app.secret_key = os.getenv("SECRET_KEY", "sSSjyhInIsUohKpG8sHzty2q") # Replace with a secure key
|
17 |
app.config["SESSION_TYPE"] = "filesystem"
|
18 |
|
19 |
+
# Initialize session
|
20 |
Session(app)
|
21 |
print("Session configured.")
|
22 |
|
|
|
48 |
if request.method == "POST":
|
49 |
email = request.form.get("email")
|
50 |
password = request.form.get("password")
|
51 |
+
print(f"Login attempt with email: {email}") # Debug log
|
52 |
|
53 |
try:
|
54 |
query = f"SELECT Id, Name, Email__c FROM Customer_Login__c WHERE Email__c='{email}' AND Password__c='{password}'"
|
|
|
57 |
if result["records"]:
|
58 |
session['user_id'] = result["records"][0]['Id']
|
59 |
session['user_email'] = email
|
60 |
+
print(f"Session variables set: user_id={session['user_id']}, user_email={session['user_email']}")
|
61 |
return redirect(url_for("menu"))
|
62 |
else:
|
63 |
+
print("Invalid credentials!")
|
64 |
return render_template("login.html", error="Invalid credentials!")
|
65 |
except Exception as e:
|
66 |
+
print(f"Error during login: {str(e)}")
|
67 |
return render_template("login.html", error=f"Error: {str(e)}")
|
68 |
|
69 |
return render_template("login.html")
|
70 |
|
|
|
71 |
@app.route("/menu", methods=["GET", "POST"])
|
72 |
def menu():
|
73 |
selected_category = request.args.get("category", "All")
|
74 |
user_id = session.get('user_id')
|
75 |
+
print(f"Session check in /menu: user_id={user_id}")
|
76 |
+
|
77 |
if not user_id:
|
78 |
+
print("Session missing, redirecting to login.")
|
79 |
+
return redirect(url_for('login'))
|
80 |
|
81 |
try:
|
82 |
query = "SELECT Name, Price__c, Image1__c, Category__c, Description__c FROM Menu_Item__c"
|
|
|
86 |
if selected_category != "All":
|
87 |
food_items = [item for item in food_items if item.get("Category__c") == selected_category]
|
88 |
except Exception as e:
|
89 |
+
print(f"Error fetching menu data: {str(e)}")
|
90 |
food_items = []
|
91 |
categories = []
|
92 |
return render_template("menu.html", food_items=food_items, categories=categories, selected_category=selected_category)
|