Overhauled the way in which user details are passed to the frontend

This commit is contained in:
2024-01-19 11:57:53 +00:00
parent 19165220fa
commit b2e32d720c
5 changed files with 55 additions and 10 deletions

View File

@@ -1,5 +1,7 @@
from flask import redirect
from flask import Blueprint
from models.users.user import User
from controllers.database.user import UserController
from flask import redirect, Blueprint, session
from . import user
from . import product
@@ -9,6 +11,24 @@ blueprint = Blueprint('main', __name__)
blueprint.register_blueprint(user.blueprint)
blueprint.register_blueprint(product.blueprint)
### CONTEXTS ###
# Function that returns a given user class based on the ID in the session
@blueprint.context_processor
def get_user() -> dict[User|None]:
# Get the user based on the user ID
user_id = session.get('user_id')
user = None
if user_id != None:
db = UserController()
user = db.read_id(user_id)
print(user)
return dict(user=user)
# Function responsible for displaying the main landing page of the site
@blueprint.route('/')
def index():