36 lines
911 B
Python
36 lines
911 B
Python
from my_modules.app.logger import logger
|
|
from my_modules.functions import get_ip
|
|
from my_modules.app.setup import app
|
|
|
|
from quart import request, render_template, current_app, session
|
|
from datetime import datetime
|
|
|
|
@app.before_request
|
|
async def custom_middleware():
|
|
if session.get('user'): # only if session already has data, update redis expire time
|
|
session.permanent = True
|
|
|
|
client_ip = get_ip()
|
|
path = request.path
|
|
method = request.method
|
|
|
|
# Skip allowed IPs or non-critical assets
|
|
if (
|
|
"favicon" in path
|
|
or "static" in path
|
|
):
|
|
return
|
|
|
|
await logger.info(f"{method} | {client_ip} had accessed the Side {path}")
|
|
|
|
@app.context_processor
|
|
async def inject_context_data():
|
|
user = session.get("user")
|
|
current_year = datetime.now().year
|
|
|
|
await logger.debug(f"Inject Context Data | User: {user}, Year: {current_year}")
|
|
return {
|
|
"user": user,
|
|
"year": current_year,
|
|
}
|