File size: 3,762 Bytes
a7abf85 d3245ed 36d2eb6 b12f5e4 9bf1d7d 5324aa9 8369d3e 386c140 d8f342f 6218638 174e074 6218638 a7abf85 6218638 01b8424 a7abf85 6218638 a7abf85 c10dd2e d831144 a69087c d3245ed 13d210d 6218638 145b38f 6218638 d8f342f 174e074 d8f342f 6218638 3ad292c a7abf85 c096c2c 4ad81b7 c096c2c 4ad81b7 c096c2c 1fd9c90 c096c2c 7136825 4ad81b7 820dc7a 80bae4f 9bf1d7d f62a0a9 80f989c 0270ecb 80f989c 9de76b8 a7abf85 fcdec6b |
1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 24 25 26 27 28 29 30 31 32 33 34 35 36 37 38 39 40 41 42 43 44 45 46 47 48 49 50 51 52 53 54 55 56 57 58 59 60 61 62 63 64 65 66 67 68 69 70 71 72 73 74 75 76 77 78 79 80 81 82 83 84 85 86 87 88 89 90 91 92 93 94 95 96 97 98 99 100 |
from flask import Flask, render_template, request, jsonify, redirect, url_for, session
from flask_session import Session # Import the Session class
from flask.sessions import SecureCookieSessionInterface # Import the class
from salesforce import get_salesforce_connection
from datetime import timedelta
from email.mime.multipart import MIMEMultipart
from email.mime.text import MIMEText
from menu import menu_blueprint # Make sure this import is correct
from cart import cart_blueprint # Same for other blueprints
from order import order_blueprint # Same for user blueprint
from orderhistory import orderhistory_blueprint
from user_details import user_details_blueprint
from customdish import customdish_blueprint
from datetime import datetime
from datetime import datetime
import pytz # Library to handle timezone conversions
import os
import smtplib
import random
import string
app = Flask(__name__)
# Add debug logs in Salesforce connection setup
sf = get_salesforce_connection()
# Set the secret key to handle sessions securely
app.secret_key = os.getenv("SECRET_KEY", "xEr0cwgsiatzrzaeFewYrVA1O") # Replace with a secure key
app.config["SESSION_TYPE"] = "filesystem" # Storing sessions in filesystem
app.config["SESSION_COOKIE_SECURE"] = True # Enabling secure cookies (ensure your app is served over HTTPS)
app.config["SESSION_COOKIE_SAMESITE"] = "None" # Cross-site cookies allowed
# Initialize the session
Session(app) # Correctly initialize the Session object
app.session_interface = SecureCookieSessionInterface()
app.register_blueprint(cart_blueprint, url_prefix='/cart')
app.register_blueprint(user_details_blueprint, url_prefix='/user')
app.register_blueprint(menu_blueprint)
app.register_blueprint(order_blueprint)
app.register_blueprint(orderhistory_blueprint, url_prefix='/orderhistory')
app.register_blueprint(customdish_blueprint, url_prefix='/customdish')
@app.route("/")
def home():
# Fetch user details from URL parameters
user_email = request.args.get("email")
user_name = request.args.get("name")
table_number = request.args.get("table") # Capture table number
if user_email and user_name:
session["user_email"] = user_email
session["user_name"] = user_name
session["table_number"] = table_number # Store table number in session
print(f"User logged in: {user_email} - {user_name} - Table: {table_number}")
# Ensure session is saved before redirecting
session.modified = True
return redirect(url_for("menu.menu")) # Redirect to menu directly
return render_template("index.html")
app.permanent_session_lifetime = timedelta(minutes=5)
@app.before_request
def check_session_timeout():
if "last_activity" in session:
last_activity_time = session["last_activity"]
now = datetime.now().timestamp()
# Check if inactivity time has exceeded 5 minutes (300 seconds)
if now - last_activity_time > 300:
session.clear() # Clear session
return redirect(url_for("logout"))
# Update last activity timestamp on every request
session["last_activity"] = datetime.now().timestamp()
@app.route("/dashboard")
def dashboard():
return render_template("dashboard.html")
@app.route("/logout")
def logout():
# Retrieve table number before clearing session
table_number = session.get('table_number', '')
# Clear session variables
session.pop('name', None)
session.pop('email', None)
session.pop('rewardPoints', None)
session.pop('coupon', None)
# Pass table number to redirect page
return render_template("redirect_page.html", table_number=table_number)
if __name__ == "__main__":
app.run(debug=True, host="0.0.0.0", port=7860) |