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
All checks were successful
ci/woodpecker/push/publish Pipeline was successful
This commit is contained in:
parent
43bbd79f87
commit
5de76b2da5
2 changed files with 15 additions and 1 deletions
10
src/app.py
10
src/app.py
|
@ -1,7 +1,8 @@
|
|||
from datetime import timedelta
|
||||
from glob import glob
|
||||
from os import mkdir, urandom
|
||||
|
||||
from flask import Flask
|
||||
from flask import Flask, session
|
||||
from utils.config import Config
|
||||
|
||||
app = Flask(__name__, static_url_path="/")
|
||||
|
@ -14,6 +15,13 @@ for file in glob("*/routes/*.py"):
|
|||
|
||||
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
|
||||
try:
|
||||
mkdir(Config.data_dir)
|
||||
|
|
|
@ -5,6 +5,7 @@ from flask import session
|
|||
VAR_USERNAME = "TD_USERNAME"
|
||||
VAR_USERPASS = "TD_USERPASS"
|
||||
VAR_PRIVATE = "TD_PRIVATE"
|
||||
VAR_LOGLIFETIME = "TD_LOGINLIFETIME"
|
||||
|
||||
|
||||
class User:
|
||||
|
@ -41,6 +42,11 @@ class Config:
|
|||
# turn posts private
|
||||
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
|
||||
def is_logged() -> bool:
|
||||
"""where the info about connection is stored"""
|
||||
|
|
Loading…
Reference in a new issue