feat: ability to change the session lifetime, now stay for 7 days (fix #4)
All checks were successful
ci/woodpecker/push/publish Pipeline was successful

This commit is contained in:
Mylloon 2023-12-24 18:13:48 +01:00
parent 43bbd79f87
commit 5de76b2da5
Signed by: Anri
GPG key ID: A82D63DFF8D1317F
2 changed files with 15 additions and 1 deletions

View file

@ -1,7 +1,8 @@
from datetime import timedelta
from glob import glob from glob import glob
from os import mkdir, urandom from os import mkdir, urandom
from flask import Flask from flask import Flask, session
from utils.config import Config from utils.config import Config
app = Flask(__name__, static_url_path="/") app = Flask(__name__, static_url_path="/")
@ -14,6 +15,13 @@ for file in glob("*/routes/*.py"):
app.secret_key = urandom(12) app.secret_key = urandom(12)
@app.before_request
def make_session_permanent():
session.permanent = True
app.permanent_session_lifetime = timedelta(days=Config.session_lifetime)
# create data directory where posts are stored # create data directory where posts are stored
try: try:
mkdir(Config.data_dir) mkdir(Config.data_dir)

View file

@ -5,6 +5,7 @@ from flask import session
VAR_USERNAME = "TD_USERNAME" VAR_USERNAME = "TD_USERNAME"
VAR_USERPASS = "TD_USERPASS" VAR_USERPASS = "TD_USERPASS"
VAR_PRIVATE = "TD_PRIVATE" VAR_PRIVATE = "TD_PRIVATE"
VAR_LOGLIFETIME = "TD_LOGINLIFETIME"
class User: class User:
@ -41,6 +42,11 @@ class Config:
# turn posts private # turn posts private
private = True if VAR_PRIVATE in envar else False private = True if VAR_PRIVATE in envar else False
# session duration in days
session_lifetime = (
float(envar[VAR_LOGLIFETIME]) if VAR_LOGLIFETIME in envar else 7.0
)
@staticmethod @staticmethod
def is_logged() -> bool: def is_logged() -> bool:
"""where the info about connection is stored""" """where the info about connection is stored"""