Marthee commited on
Commit
fb7e6dd
·
verified ·
1 Parent(s): 227ea23

Update app.py

Browse files
Files changed (1) hide show
  1. app.py +11 -29
app.py CHANGED
@@ -44,17 +44,6 @@ 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()
56
- sess.init_app(app)
57
-
58
  prjnamesURL = 'https://docs.google.com/spreadsheets/d/1nsIgi9o9VSBKQlNxbxihPzG_N7s4um0eNVfgL4gaGPc/export?format=csv&gid=0'
59
  prjpartsURL = 'https://docs.google.com/spreadsheets/d/1nsIgi9o9VSBKQlNxbxihPzG_N7s4um0eNVfgL4gaGPc/export?format=csv&gid=34865056'
60
  prjsectionsURL = 'https://docs.google.com/spreadsheets/d/1nsIgi9o9VSBKQlNxbxihPzG_N7s4um0eNVfgL4gaGPc/export?format=csv&gid=1751466819'
@@ -65,51 +54,44 @@ global pdflink
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"] = 'authenticated' # 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:
90
  return jsonify({"authenticated": False}), 200
91
 
92
- # Main GUI Route (Checks Authentication)
93
  @app.route("/mainGUI", methods=["GET", "POST"])
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"))
107
 
108
- # If authenticated, render the main GUI
109
  return render_template("proposed-GUI.html")
110
 
111
 
112
-
113
 
114
  @app.route("/WordSearch",methods=["GET", "POST"])
115
  def getInfo2toMeasure():
 
44
  from flask_session import Session # Capital "S"
45
  app = Flask(__name__)
46
 
 
 
 
 
 
 
 
 
 
 
 
47
  prjnamesURL = 'https://docs.google.com/spreadsheets/d/1nsIgi9o9VSBKQlNxbxihPzG_N7s4um0eNVfgL4gaGPc/export?format=csv&gid=0'
48
  prjpartsURL = 'https://docs.google.com/spreadsheets/d/1nsIgi9o9VSBKQlNxbxihPzG_N7s4um0eNVfgL4gaGPc/export?format=csv&gid=34865056'
49
  prjsectionsURL = 'https://docs.google.com/spreadsheets/d/1nsIgi9o9VSBKQlNxbxihPzG_N7s4um0eNVfgL4gaGPc/export?format=csv&gid=1751466819'
 
54
  # For 2.7
55
  global hatched_areas2_7
56
 
57
+ # Configure Flask-Session for server-side session storage
58
+ app.config["SESSION_TYPE"] = "filesystem"
59
+ app.config["SESSION_PERMANENT"] = False
60
+ app.config["SESSION_FILE_DIR"] = "./flask_session_files"
61
+ app.secret_key = "your_secret_key"
62
+
63
+ # Initialize Flask-Session
64
+ sess = Session()
65
+ sess.init_app(app)
66
+
67
  @app.route("/", methods=["GET", "POST"])
68
  def getInfotoMeasure():
69
  return render_template("gui2.html")
70
 
 
71
  @app.route("/password", methods=["GET", "POST"])
72
  def password_page():
73
  return render_template("gui2.html")
74
 
 
75
  @app.route("/check_password", methods=["POST"])
76
  def check_password():
77
  password = request.form.get("password")
78
  correct_password = "c900"
79
 
80
  if password == correct_password:
81
+ session["authenticated"] = True # Store authentication in session
82
  session.modified = True # Mark session as modified to ensure it is saved
 
83
  return jsonify({"authenticated": True}), 200
84
  else:
85
  return jsonify({"authenticated": False}), 200
86
 
 
87
  @app.route("/mainGUI", methods=["GET", "POST"])
88
  def main_gui():
 
 
 
 
 
 
 
 
 
89
  if "authenticated" not in session or not session["authenticated"]:
 
90
  return redirect(url_for("password_page"))
91
 
 
92
  return render_template("proposed-GUI.html")
93
 
94
 
 
95
 
96
  @app.route("/WordSearch",methods=["GET", "POST"])
97
  def getInfo2toMeasure():