# Path: m2core/data_schemes/db_system_scheme.py
# class CreatedMixin:
# class SortMixin:
# class M2PermissionCheckMixin:
# class M2Permission(BaseModel):
# class M2Role(BaseModel):
# class M2RolePermission(BaseModel):
# class M2UserMixin:
# class M2UserRole(BaseModel):
#     def can(self, permission_rule: Permission) -> bool:
#     def enum_member(self):
#     def from_enum_member(cls, member: Permission):
#     def get_role_permissions(self) -> List[str]:
#     def dump_role_permissions(self):
#     def set_permissions(self, permissions: list):
#     def add_permission(self, permission_system_name: str):


from sqlalchemy import Column, BigInteger, Integer, String, func
from m2core.data_schemes.db_system_scheme import M2UserRole, M2Role, M2Error, BaseModel, CreatedMixin
import bcrypt
        if not user_obj:
            return None

        # check authorization via python bcrypt, not postgres bcrypt
        if not bcrypt.checkpw(str.encode(_password), str.encode(user_obj.get('password'))):
            return None

        access_token = cls.sh.generate_token(user_obj.get('id'))
        access_token['user_info'] = user_obj.data('password')
        return access_token

    def add_role(self, _role_name: str):
        """
        Adds new role for user. User can have unlimited number of roles. If he already has this role - do nothing
        :param _role_name: role name
        """
        role = M2Role.load_by_params(name=_role_name)
        if not role:
            raise M2Error('Trying to add non-existent role', True)

        M2UserRole.load_or_create(user_id=self.get('id'), role_id=role.get('id'))

        roles = [role.get('role_id') for role in self.get_roles()]
        self.sh.dump_user_roles(self.get('id'), roles)

    def get_roles(self) -> list:
        """
        Returns all user roles list
        :return: list of roles
        """

# Path: m2core/data_schemes/db_system_scheme.py
# class CreatedMixin:
# class SortMixin:
# class M2PermissionCheckMixin:
# class M2Permission(BaseModel):
# class M2Role(BaseModel):
# class M2RolePermission(BaseModel):
# class M2UserMixin:
# class M2UserRole(BaseModel):
#     def can(self, permission_rule: Permission) -> bool:
#     def enum_member(self):
#     def from_enum_member(cls, member: Permission):
#     def get_role_permissions(self) -> List[str]:
#     def dump_role_permissions(self):
#     def set_permissions(self, permissions: list):
#     def add_permission(self, permission_system_name: str):


# Path: example/models/users.py
from sqlalchemy import Column, BigInteger, Integer, String, func
from m2core.data_schemes.db_system_scheme import M2UserRole, M2Role, M2Error, BaseModel, CreatedMixin
import bcrypt

        if not user_obj:
            return None

        # check authorization via python bcrypt, not postgres bcrypt
        if not bcrypt.checkpw(str.encode(_password), str.encode(user_obj.get('password'))):
            return None

        access_token = cls.sh.generate_token(user_obj.get('id'))
        access_token['user_info'] = user_obj.data('password')
        return access_token

    def add_role(self, _role_name: str):
        """
        Adds new role for user. User can have unlimited number of roles. If he already has this role - do nothing
        :param _role_name: role name
        """
        role = M2Role.load_by_params(name=_role_name)
        if not role:
            raise M2Error('Trying to add non-existent role', True)

        M2UserRole.load_or_create(user_id=self.get('id'), role_id=role.get('id'))

        roles = [role.get('role_id') for role in self.get_roles()]
        self.sh.dump_user_roles(self.get('id'), roles)

    def get_roles(self) -> list:
        """
        Returns all user roles list
        :return: list of roles
        """

        user_roles = M2UserRole.all(user_id=self.get('id'))