I am working on building some basic functions. One of them what I am doing now is timeout-session. I set PERMANENT_SESSION_LIFETIME = timedelta(minutes=20) and I found it works well.
But what I am confused is How to tell users that the user's session was expired because of session lifetime using flash?
Or is there a way to redirect when the user's session was expired?
Below is Specifics
tree
.
├── __init__.py
├── admin
│ ├── __init__.py
│ ├── forms.py
│ └── views.py
├── app.py
├── commands.py
├── compat.py
├── database.py
├── dataset
│ ├── __init__.py
│ ├── forms.py
│ ├── models.py
│ └── views.py
├── decorators.py
├── extensions.py
├── public
│ ├── __init__.py
│ ├── __pycache__
│ ├── forms.py
│ └── views.py
├── settings.py
settings.py
from datetime import timedelta
from environs import Env
env = Env()
env.read_env()
ENV = env.str("FLASK_ENV", default="production")
DEBUG = ENV == "development"
SQLALCHEMY_DATABASE_URI = env.str("DATABASE_URL")
SECRET_KEY = env.str("SECRET_KEY")
SEND_FILE_MAX_AGE_DEFAULT = env.int("SEND_FILE_MAX_AGE_DEFAULT")
BCRYPT_LOG_ROUNDS = env.int("BCRYPT_LOG_ROUNDS", default=13)
DEBUG_TB_ENABLED = DEBUG
DEBUG_TB_INTERCEPT_REDIRECTS = False
CACHE_TYPE = "simple" # Can be "memcached", "redis", etc.
SQLALCHEMY_TRACK_MODIFICATIONS = False
MONGODB_URI = env.str("MONGODB_URI")
MONGODB_DATABASE_NAME = env.str("MONGODB_DATABASE_NAME")
UPLOAD_FOLDER = env.str("UPLOAD_FOLDER")
PERMANENT_SESSION_LIFETIME = timedelta(minutes=100)
app.py
# -*- coding: utf-8 -*-
"""The app module, containing the app factory function."""
import logging
import sys
from flask import Flask, render_template
from web import admin, commands, public, user, dataset
from web.extensions import (
bcrypt,
cache,
csrf_protect,
db,
debug_toolbar,
flask_static_digest,
login_manager,
migrate,
)
def create_app(config_object="web.settings"):
"""Create application factory
:param config_object: The configuration object to use.
"""
app = Flask(__name__.split(".")[0])
app.config.from_object(config_object)
register_extensions(app)
register_blueprints(app)
register_errorhandlers(app)
register_shellcontext(app)
register_commands(app)
configure_logger(app)
return app
``