from flask import Flask, session, redirect, url_for import secrets import os # Get the directory where this script is located basedir = os.path.abspath(os.path.dirname(__file__)) # Initialize Flask with explicit paths app = Flask(__name__, template_folder=os.path.join(basedir, 'templates'), static_folder=os.path.join(basedir, 'static')) # Configure session - generate a random secret key app.secret_key = secrets.token_hex(32) app.config['SESSION_COOKIE_HTTPONLY'] = True app.config['SESSION_COOKIE_SAMESITE'] = 'Lax' # Import and register blueprints from blueprints.auth import auth_bp from blueprints.users import users_bp app.register_blueprint(auth_bp) app.register_blueprint(users_bp) # Home route @app.route('/') def home(): """Redirect to login if not authenticated, otherwise show home""" if 'user_id' not in session: return redirect(url_for('auth.login_page')) # If user hasn't selected a location yet, redirect to selection if not session.get('currentLocation') and len(session.get('accessibleLocations', [])) > 1: return redirect(url_for('auth.select_location_page')) return f""" Home

Welcome, {session.get('username', 'User')}!

Current Location: {session.get('currentLocation', 'Not selected')}

""" @app.route('/test') def test(): """Test route to verify app is running""" import sys return f""" Test Page

Flask App is Running!

Login

""" # Error handlers @app.errorhandler(404) def page_not_found(e): return "

404 - Page Not Found

", 404 @app.errorhandler(500) def internal_error(e): return "

500 - Internal Server Error

", 500 # This is the critical line for Passenger application = app if __name__ == '__main__': # Create necessary directories os.makedirs(os.path.join(basedir, 'templates'), exist_ok=True) os.makedirs(os.path.join(basedir, 'data'), exist_ok=True) # Run the application app.run(debug=True, host='0.0.0.0', port=8080)