Update app.py
Browse files
    	
        app.py
    CHANGED
    
    | @@ -1,7 +1,7 @@ | |
| 1 | 
             
            from flask import Flask, render_template, request, jsonify, redirect, url_for, session
         | 
| 2 | 
            -
            import os
         | 
| 3 | 
            -
            from salesforce import get_salesforce_connection
         | 
| 4 | 
             
            from flask.sessions import SecureCookieSessionInterface
         | 
|  | |
|  | |
| 5 |  | 
| 6 | 
             
            # Initialize Flask app and Salesforce connection
         | 
| 7 | 
             
            print("Starting app...")
         | 
| @@ -15,6 +15,14 @@ print("Salesforce connection established.") | |
| 15 | 
             
            # Set the secret key to handle sessions securely
         | 
| 16 | 
             
            app.secret_key = os.getenv("SECRET_KEY", "sSSjyhInIsUohKpG8sHzty2q")  # Replace with a secure key
         | 
| 17 |  | 
|  | |
|  | |
|  | |
|  | |
|  | |
|  | |
|  | |
|  | |
| 18 | 
             
            # Ensure secure session handling for environments like Hugging Face
         | 
| 19 | 
             
            app.session_interface = SecureCookieSessionInterface()
         | 
| 20 | 
             
            print("Session interface configured.")
         | 
| @@ -57,7 +65,6 @@ def login(): | |
| 57 | 
             
                            session['user_id'] = result["records"][0]['Id']
         | 
| 58 | 
             
                            session['user_email'] = email
         | 
| 59 | 
             
                            print(f"Session variables set: user_id={session['user_id']}, user_email={session['user_email']}")
         | 
| 60 | 
            -
                            print(f"Cookies after login: {request.cookies}")  # Correctly indented print statement
         | 
| 61 | 
             
                            return redirect(url_for("menu"))
         | 
| 62 | 
             
                        else:
         | 
| 63 | 
             
                            print("Invalid credentials!")
         | 
| @@ -70,6 +77,7 @@ def login(): | |
| 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}")
         | 
|  | |
| 1 | 
             
            from flask import Flask, render_template, request, jsonify, redirect, url_for, session
         | 
|  | |
|  | |
| 2 | 
             
            from flask.sessions import SecureCookieSessionInterface
         | 
| 3 | 
            +
            from salesforce import get_salesforce_connection
         | 
| 4 | 
            +
            import os
         | 
| 5 |  | 
| 6 | 
             
            # Initialize Flask app and Salesforce connection
         | 
| 7 | 
             
            print("Starting app...")
         | 
|  | |
| 15 | 
             
            # Set the secret key to handle sessions securely
         | 
| 16 | 
             
            app.secret_key = os.getenv("SECRET_KEY", "sSSjyhInIsUohKpG8sHzty2q")  # Replace with a secure key
         | 
| 17 |  | 
| 18 | 
            +
            # Session configuration
         | 
| 19 | 
            +
            app.config["SESSION_TYPE"] = "filesystem"
         | 
| 20 | 
            +
            app.config["SESSION_COOKIE_NAME"] = "biryanihub_session"
         | 
| 21 | 
            +
            app.config["SESSION_PERMANENT"] = False
         | 
| 22 | 
            +
            app.config["SESSION_USE_SIGNER"] = True
         | 
| 23 | 
            +
            app.config["SESSION_COOKIE_SECURE"] = False  # Change to True if using HTTPS
         | 
| 24 | 
            +
            app.config["SESSION_COOKIE_HTTPONLY"] = True
         | 
| 25 | 
            +
             | 
| 26 | 
             
            # Ensure secure session handling for environments like Hugging Face
         | 
| 27 | 
             
            app.session_interface = SecureCookieSessionInterface()
         | 
| 28 | 
             
            print("Session interface configured.")
         | 
|  | |
| 65 | 
             
                            session['user_id'] = result["records"][0]['Id']
         | 
| 66 | 
             
                            session['user_email'] = email
         | 
| 67 | 
             
                            print(f"Session variables set: user_id={session['user_id']}, user_email={session['user_email']}")
         | 
|  | |
| 68 | 
             
                            return redirect(url_for("menu"))
         | 
| 69 | 
             
                        else:
         | 
| 70 | 
             
                            print("Invalid credentials!")
         | 
|  | |
| 77 |  | 
| 78 | 
             
            @app.route("/menu", methods=["GET", "POST"])
         | 
| 79 | 
             
            def menu():
         | 
| 80 | 
            +
                print(f"Cookies on /menu: {request.cookies}")
         | 
| 81 | 
             
                selected_category = request.args.get("category", "All")
         | 
| 82 | 
             
                user_id = session.get('user_id')
         | 
| 83 | 
             
                print(f"Session check in /menu: user_id={user_id}")
         | 
