from flaskapp.config.secret import secret from flaskapp.lib import csrf from flask import Flask, redirect, url_for, session from datetime import timedelta from flaskapp.blueprints import index, login, tournament app = Flask(__name__) @app.errorhandler(404) def page_not_found(e): return redirect(url_for('index.index')) @app.before_request def set_session_timeout(): session.permanent = True app.permanent_session_lifetime = timedelta(minutes=20) def configure_app(app): app.secret_key = secret['secret_key'] app.config['SESSION_COOKIE_SECURE'] = True app.config['SESSION_COOKIE_HTTPONLY'] = True app.config['SESSION_COOKIE_SAMESITE'] = 'Lax' def init_jinja(app): app.jinja_env.globals.update(len=len) app.jinja_env.globals.update(str=str) app.jinja_env.globals.update(enumerate=enumerate) def init_app(app): configure_app(app) csrf.csrf.init_app(app) init_jinja(app) def register_blueprints(): app.register_blueprint(index.bp) app.register_blueprint(tournament.bp) app.register_blueprint(login.bp) def start(): init_app(app) register_blueprints() start() if __name__ == '__main__': app.run()