diff --git a/default_config.py b/default_config.py index 481464a..881039f 100644 --- a/default_config.py +++ b/default_config.py @@ -16,3 +16,6 @@ DISABLE_REGISTER=False # Front URL of the application (for QRCodes generation) BASE_URL="http://localhost:5000" + +# Session expiration, in days +MAX_AGE=31 diff --git a/partitioncloud/__init__.py b/partitioncloud/__init__.py index ee05b3b..b7283c2 100644 --- a/partitioncloud/__init__.py +++ b/partitioncloud/__init__.py @@ -3,6 +3,7 @@ Main file """ import os +import datetime import subprocess from flask import Flask, g, redirect, render_template, request, send_file, flash, session, abort @@ -105,6 +106,12 @@ def search_thumbnail(uuid): return send_file(os.path.join(app.static_folder, "search-thumbnails", f"{uuid}.jpg")) +@app.before_request +def before_request(): + """Set cookie max age to 31 days""" + session.permanent = True + app.permanent_session_lifetime = datetime.timedelta(days=int(app.config["MAX_AGE"])) + @app.context_processor def inject_default_variables(): """Inject the version number in the template variables"""