Repository navigation
Expand file tree
/
Copy pathapplication.py
More file actions
83 lines (67 loc) · 2.52 KB
/
Copy pathapplication.py
File metadata and controls
83 lines (67 loc) · 2.52 KB
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
import os
import dash
import logging
from datetime import timedelta
from flask import Flask, redirect, session, url_for, request
from movieRatingSystem.logging_config import setup_logging
from movieRatingSystem.dash_main.dash_pages import dashMain as dash_blueprint
from movieRatingSystem.dash_main.dash_pages import sales_tool
from movieRatingSystem.auth.auth import auth as auth_blueprint
from main import main as main_blueprint
def create_app(name=None):
app = Flask(__name__,
static_folder='movieRatingSystem/static',
template_folder='movieRatingSystem/templates')
app.secret_key = "super-secret-key"
# Enable debug mode
# app.debug = True
app.logger.disabled = True
log = logging.getLogger('werkzeug')
# Set this to False to enable logging
log.disabled = True
# Session config
app.config.update(
SESSION_COOKIE_SECURE=False,
SESSION_COOKIE_HTTPONLY=True,
SESSION_COOKIE_SAMESITE='Lax',
PERMANENT_SESSION_LIFETIME=timedelta(minutes=30),
SEND_FILE_MAX_AGE_DEFAULT=0
)
with app.app_context():
# Set up logging
app = setup_logging(app)
# Register blueprints
app.register_blueprint(auth_blueprint, url_prefix="/auth")
app.register_blueprint(main_blueprint)
app.register_blueprint(dash_blueprint)
app = sales_tool(app)
@app.route("/")
def index():
return redirect(url_for("auth.login"))
@app.before_request
def check_login():
exempt_paths = [
"/auth/login",
"/auth/register",
"/auth/logout",
"/auth/",
"/static/",
"/favicon.ico"
]
if any(request.path.startswith(path) for path in exempt_paths):
return None
if 'user_id' not in session:
if request.path.startswith('/movies/_dash-') or request.path.startswith('/movies/assets/'):
if request.headers.get('Accept') == 'application/json':
return '', 204
return redirect(url_for('auth.login'))
return None
@app.errorhandler(Exception)
def handle_exception(e):
app.logger.error(f"Unhandled exception: {str(e)}", exc_info=True)
return str(e), 500
return app
if __name__ == "__main__":
app = create_app()
app.logger.info("Running app...")
app.run(debug=True)