Spaces:
Sleeping
Sleeping
Update app.py
Browse files
app.py
CHANGED
|
@@ -43,13 +43,13 @@ import ezdxf
|
|
| 43 |
from flask import Flask, render_template, session, redirect, url_for
|
| 44 |
from flask_session import Session # Capital "S"
|
| 45 |
app = Flask(__name__)
|
| 46 |
-
|
| 47 |
|
| 48 |
# Configure Flask-Session for server-side session storage
|
| 49 |
-
app.config["SESSION_TYPE"] = "filesystem"
|
| 50 |
-
app.config["SESSION_PERMANENT"] = False
|
| 51 |
-
app.config["SESSION_FILE_DIR"] = "
|
| 52 |
-
app.secret_key = "your_secret_key" # Replace with a secure key
|
| 53 |
|
| 54 |
# Initialize Flask-Session
|
| 55 |
sess = Session()
|
|
@@ -65,24 +65,25 @@ global pdflink
|
|
| 65 |
# For 2.7
|
| 66 |
global hatched_areas2_7
|
| 67 |
|
|
|
|
| 68 |
@app.route("/", methods=["GET", "POST"])
|
| 69 |
def getInfotoMeasure():
|
| 70 |
return render_template("gui2.html")
|
| 71 |
|
| 72 |
-
# Password Page Route
|
| 73 |
@app.route("/password", methods=["GET", "POST"])
|
| 74 |
def password_page():
|
| 75 |
return render_template("gui2.html")
|
| 76 |
|
| 77 |
-
# Check Password Route
|
| 78 |
@app.route("/check_password", methods=["POST"])
|
| 79 |
def check_password():
|
| 80 |
password = request.form.get("password")
|
| 81 |
-
correct_password = "c900"
|
| 82 |
|
| 83 |
-
# Check if the entered password matches the correct password
|
| 84 |
if password == correct_password:
|
| 85 |
session["authenticated"] = True # Store authentication in session
|
|
|
|
| 86 |
print("Password correct. Session data set:", session) # Debugging: Print session after setting it
|
| 87 |
return jsonify({"authenticated": True}), 200
|
| 88 |
else:
|
|
@@ -93,13 +94,13 @@ def check_password():
|
|
| 93 |
def main_gui():
|
| 94 |
print("Session data at mainGUI:", session) # Debugging: Check session data
|
| 95 |
|
| 96 |
-
#
|
| 97 |
-
if "authenticated"
|
| 98 |
-
print("Session
|
| 99 |
else:
|
| 100 |
-
print(
|
| 101 |
|
| 102 |
-
# If
|
| 103 |
if "authenticated" not in session or not session["authenticated"]:
|
| 104 |
print("User not authenticated, redirecting to password page.") # Debugging
|
| 105 |
return redirect(url_for("password_page"))
|
|
|
|
| 43 |
from flask import Flask, render_template, session, redirect, url_for
|
| 44 |
from flask_session import Session # Capital "S"
|
| 45 |
app = Flask(__name__)
|
| 46 |
+
|
| 47 |
|
| 48 |
# Configure Flask-Session for server-side session storage
|
| 49 |
+
app.config["SESSION_TYPE"] = "filesystem"
|
| 50 |
+
app.config["SESSION_PERMANENT"] = False
|
| 51 |
+
app.config["SESSION_FILE_DIR"] = "./flask_session_files" # Local directory for session files (use a persistent directory)
|
| 52 |
+
app.secret_key = "your_secret_key" # Replace with a secure key
|
| 53 |
|
| 54 |
# Initialize Flask-Session
|
| 55 |
sess = Session()
|
|
|
|
| 65 |
# For 2.7
|
| 66 |
global hatched_areas2_7
|
| 67 |
|
| 68 |
+
# Home Route (Displays password page initially)
|
| 69 |
@app.route("/", methods=["GET", "POST"])
|
| 70 |
def getInfotoMeasure():
|
| 71 |
return render_template("gui2.html")
|
| 72 |
|
| 73 |
+
# Password Page Route (For entering the password)
|
| 74 |
@app.route("/password", methods=["GET", "POST"])
|
| 75 |
def password_page():
|
| 76 |
return render_template("gui2.html")
|
| 77 |
|
| 78 |
+
# Check Password Route (Validates the password)
|
| 79 |
@app.route("/check_password", methods=["POST"])
|
| 80 |
def check_password():
|
| 81 |
password = request.form.get("password")
|
| 82 |
+
correct_password = "c900"
|
| 83 |
|
|
|
|
| 84 |
if password == correct_password:
|
| 85 |
session["authenticated"] = True # Store authentication in session
|
| 86 |
+
session.modified = True # Mark session as modified to ensure it is saved
|
| 87 |
print("Password correct. Session data set:", session) # Debugging: Print session after setting it
|
| 88 |
return jsonify({"authenticated": True}), 200
|
| 89 |
else:
|
|
|
|
| 94 |
def main_gui():
|
| 95 |
print("Session data at mainGUI:", session) # Debugging: Check session data
|
| 96 |
|
| 97 |
+
# Check if the session contains 'authenticated' and its value
|
| 98 |
+
if "authenticated" in session:
|
| 99 |
+
print(f"Session contains 'authenticated': {session['authenticated']}") # Debugging
|
| 100 |
else:
|
| 101 |
+
print("Session does not contain 'authenticated'") # Debugging
|
| 102 |
|
| 103 |
+
# If session does not have "authenticated" or it's False, redirect to password page
|
| 104 |
if "authenticated" not in session or not session["authenticated"]:
|
| 105 |
print("User not authenticated, redirecting to password page.") # Debugging
|
| 106 |
return redirect(url_for("password_page"))
|