WMGZON/utils/user_utils.py

27 lines
632 B
Python

from flask import session
from models.users.user import User
from controllers.database.user import UserController
def is_logged_in() -> User | None:
""" Returns the user object if the user is logged in
Otherwise returns a None type
"""
user_id = session.get('user_id')
if user_id is not None:
db = UserController()
return db.read_id(user_id)
return None
def is_role(role: str) -> bool:
""" Function that returns true if the user is logged in as"""
user = is_logged_in()
if user is not None:
return user.role == role
# User isn't logged in
return False