Spaces:
Sleeping
Sleeping
Update app.py
Browse files
app.py
CHANGED
|
@@ -40,8 +40,13 @@ import Code_2_7
|
|
| 40 |
import Counting_Columns_2_1
|
| 41 |
import Find_Hyperlinking_text
|
| 42 |
import ezdxf
|
| 43 |
-
|
| 44 |
-
from
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
| 45 |
app = Flask(__name__)
|
| 46 |
|
| 47 |
prjnamesURL = 'https://docs.google.com/spreadsheets/d/1nsIgi9o9VSBKQlNxbxihPzG_N7s4um0eNVfgL4gaGPc/export?format=csv&gid=0'
|
|
@@ -54,16 +59,30 @@ global pdflink
|
|
| 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")
|
|
@@ -76,21 +95,27 @@ def password_page():
|
|
| 76 |
def check_password():
|
| 77 |
password = request.form.get("password")
|
| 78 |
correct_password = "c900"
|
|
|
|
| 79 |
|
| 80 |
if password == correct_password:
|
| 81 |
session["authenticated"] = True
|
|
|
|
| 82 |
return jsonify({"authenticated": True}), 200
|
| 83 |
else:
|
|
|
|
| 84 |
return jsonify({"authenticated": False}), 200
|
| 85 |
|
| 86 |
@app.route("/mainGUI", methods=["GET", "POST"])
|
| 87 |
def main_gui():
|
|
|
|
|
|
|
|
|
|
| 88 |
if "authenticated" not in session or not session["authenticated"]:
|
|
|
|
| 89 |
return redirect(url_for("password_page"))
|
|
|
|
| 90 |
return render_template("proposed-GUI.html")
|
| 91 |
|
| 92 |
-
|
| 93 |
-
|
| 94 |
@app.route("/WordSearch",methods=["GET", "POST"])
|
| 95 |
def getInfo2toMeasure():
|
| 96 |
# API.AppendtablestoSheets()
|
|
|
|
| 40 |
import Counting_Columns_2_1
|
| 41 |
import Find_Hyperlinking_text
|
| 42 |
import ezdxf
|
| 43 |
+
|
| 44 |
+
from flask import Flask, render_template, request, redirect, url_for, session, jsonify
|
| 45 |
+
from flask_session import Session
|
| 46 |
+
import redis
|
| 47 |
+
from flask_cors import CORS
|
| 48 |
+
import logging
|
| 49 |
+
|
| 50 |
app = Flask(__name__)
|
| 51 |
|
| 52 |
prjnamesURL = 'https://docs.google.com/spreadsheets/d/1nsIgi9o9VSBKQlNxbxihPzG_N7s4um0eNVfgL4gaGPc/export?format=csv&gid=0'
|
|
|
|
| 59 |
# For 2.7
|
| 60 |
global hatched_areas2_7
|
| 61 |
|
|
|
|
|
|
|
|
|
|
|
|
|
| 62 |
app.secret_key = "your_secret_key"
|
| 63 |
|
| 64 |
# Initialize Flask-Session
|
| 65 |
sess = Session()
|
| 66 |
sess.init_app(app)
|
| 67 |
|
| 68 |
+
|
| 69 |
+
# Initialize Flask app
|
| 70 |
+
app = Flask(__name__)
|
| 71 |
+
|
| 72 |
+
# Configure logging
|
| 73 |
+
logging.basicConfig(level=logging.DEBUG)
|
| 74 |
+
|
| 75 |
+
# Enable CORS for all routes
|
| 76 |
+
CORS(app)
|
| 77 |
+
|
| 78 |
+
# Configure Flask-Session to use Redis for session storage
|
| 79 |
+
app.config["SESSION_TYPE"] = "redis"
|
| 80 |
+
app.config["SESSION_PERMANENT"] = False
|
| 81 |
+
app.config["SESSION_USE_SIGNER"] = True
|
| 82 |
+
app.config["SESSION_KEY_PREFIX"] = "my_session:"
|
| 83 |
+
app.config["SESSION_REDIS"] = redis.StrictRedis(host='localhost', port=6379, db=0) # Change host if using a remote Redis instance
|
| 84 |
+
app.secret_key = "your_secret_key"
|
| 85 |
+
|
| 86 |
@app.route("/", methods=["GET", "POST"])
|
| 87 |
def getInfotoMeasure():
|
| 88 |
return render_template("gui2.html")
|
|
|
|
| 95 |
def check_password():
|
| 96 |
password = request.form.get("password")
|
| 97 |
correct_password = "c900"
|
| 98 |
+
app.logger.debug(f"Received password: {password}")
|
| 99 |
|
| 100 |
if password == correct_password:
|
| 101 |
session["authenticated"] = True
|
| 102 |
+
app.logger.debug(f"Session after authentication: {session}")
|
| 103 |
return jsonify({"authenticated": True}), 200
|
| 104 |
else:
|
| 105 |
+
app.logger.debug("Password incorrect.")
|
| 106 |
return jsonify({"authenticated": False}), 200
|
| 107 |
|
| 108 |
@app.route("/mainGUI", methods=["GET", "POST"])
|
| 109 |
def main_gui():
|
| 110 |
+
# Debugging session data
|
| 111 |
+
app.logger.debug(f"Session data at mainGUI: {session}")
|
| 112 |
+
|
| 113 |
if "authenticated" not in session or not session["authenticated"]:
|
| 114 |
+
app.logger.debug("User not authenticated, redirecting to password page.")
|
| 115 |
return redirect(url_for("password_page"))
|
| 116 |
+
|
| 117 |
return render_template("proposed-GUI.html")
|
| 118 |
|
|
|
|
|
|
|
| 119 |
@app.route("/WordSearch",methods=["GET", "POST"])
|
| 120 |
def getInfo2toMeasure():
|
| 121 |
# API.AppendtablestoSheets()
|