Ligare.platform.identity.user_loader

Classes

Role(value)

An enumeration.

UserId(user_id, username)

UserLoader(loader, roles, user_table, ...)

Class intended for user with FlaskLogin.

class Ligare.platform.identity.user_loader.Role(value)[source]

An enumeration.

class Ligare.platform.identity.user_loader.UserId(user_id, username)[source]
__init__(user_id, username)
user_id: int
username: str
class Ligare.platform.identity.user_loader.UserLoader(loader, roles, user_table, role_table, scoped_session, log)[source]

Class intended for user with FlaskLogin. FlaskLogin is not required.

__init__(loader, roles, user_table, role_table, scoped_session, log)[source]

Load and optionally create a user.

Parameters:
  • loader (Callable[[UserId, list[Enum]], None]) – A callback that receives the create user information including its roles.

  • roles (Type[Enum]) – An enum representing possible roles for a user.

  • user_table (Type[DbUser]) – The SQLAlchemy table type for a user.

  • role_table (Type[DbRole]) – The SQLAlchemy table type for a role.

  • scoped_session (ScopedSession) – The SQLAlchemy connection scope.

  • log (Logger) – A Logger instance.

user_loader(username, default_role, create_if_new_user=False)[source]

Load a user and its roles from the database.

Parameters:
  • username (str) – The users username.

  • default_role (Enum) – The default role assigned to the user when create_if_new_user is true and the user does not already exist.

  • create_if_new_user (bool) – Create the user in the database if it does not already exist, defaults to False.

Raises:

AssertionError – If a user is loaded from the database, but it is not of the type specified by user_table.

Return type:

Optional[TypeVar(TUserMixin, bound= UserMixin[Role])]

protocol Ligare.platform.identity.user_loader.UserMixin[source]

typing.Protocol.

Classes that implement this protocol must have the following methods / attributes:

id: UserId
property roles: Sequence[TRole]