# Path: mass_flask_config/app.py
# BASE_DIR = os.path.dirname(os.path.dirname(__file__))
# SECRET_FILE = os.path.join(BASE_DIR, 'secret.txt')
# def setup_session_auth(user_loader):
# def setup_key_based_auth(key_loader):
# def unauthorized_callback():
# 
# Path: mass_flask_core/models/tlp_level.py
# class TLPLevelField(IntField):
#     TLP_LEVEL_WHITE = 0  # Access without login
#     TLP_LEVEL_GREEN = 1  # Access with login
#     TLP_LEVEL_AMBER = 2  # Access only for especially authorized users of same group
#     TLP_LEVEL_RED = 3    # Access only for explicitly mentioned users/groups
# 
#     def __init__(self, *args, **kwargs):
#         kwargs['choices'] = [
#             TLPLevelField.TLP_LEVEL_WHITE,
#             TLPLevelField.TLP_LEVEL_GREEN,
#             TLPLevelField.TLP_LEVEL_AMBER,
#             TLPLevelField.TLP_LEVEL_RED
#         ]
#         super(TLPLevelField, self).__init__(*args, **kwargs)


from flask_modular_auth import AbstractAuthEntity
from mongoengine import StringField, BooleanField, IntField
from werkzeug.security import generate_password_hash, check_password_hash
from bson import ObjectId
from mass_flask_config.app import db, setup_session_auth, auth_manager
from .tlp_level import TLPLevelField

    def set_password(self, password):
        self.password_hash = generate_password_hash(password)

    def check_password(self, password):
        return check_password_hash(self.password_hash, password)

    def get_id(self):
        return str(self.id)

    @staticmethod
    def user_loader(**kwargs):
        if 'username' in kwargs and 'password' in kwargs:
            user = User.objects(username=kwargs['username']).first()
            if user and user.check_password(kwargs['password']):
                return user
            else:
                return None
        elif 'id' in kwargs and kwargs['id']:
            return User.objects(id=ObjectId(kwargs['id'])).first()
        else:
            raise RuntimeError('This access method is not supported by the user loader.')


class AnonymousUser(UserMixin):
    @property
    def is_authenticated(self):
        return False



# Path: mass_flask_config/app.py
# BASE_DIR = os.path.dirname(os.path.dirname(__file__))
# SECRET_FILE = os.path.join(BASE_DIR, 'secret.txt')
# def setup_session_auth(user_loader):
# def setup_key_based_auth(key_loader):
# def unauthorized_callback():
# 
# Path: mass_flask_core/models/tlp_level.py
# class TLPLevelField(IntField):
#     TLP_LEVEL_WHITE = 0  # Access without login
#     TLP_LEVEL_GREEN = 1  # Access with login
#     TLP_LEVEL_AMBER = 2  # Access only for especially authorized users of same group
#     TLP_LEVEL_RED = 3    # Access only for explicitly mentioned users/groups
# 
#     def __init__(self, *args, **kwargs):
#         kwargs['choices'] = [
#             TLPLevelField.TLP_LEVEL_WHITE,
#             TLPLevelField.TLP_LEVEL_GREEN,
#             TLPLevelField.TLP_LEVEL_AMBER,
#             TLPLevelField.TLP_LEVEL_RED
#         ]
#         super(TLPLevelField, self).__init__(*args, **kwargs)


# Path: mass_flask_core/models/user.py
from flask_modular_auth import AbstractAuthEntity
from mongoengine import StringField, BooleanField, IntField
from werkzeug.security import generate_password_hash, check_password_hash
from bson import ObjectId
from mass_flask_config.app import db, setup_session_auth, auth_manager
from .tlp_level import TLPLevelField


    def set_password(self, password):
        self.password_hash = generate_password_hash(password)

    def check_password(self, password):
        return check_password_hash(self.password_hash, password)

    def get_id(self):
        return str(self.id)

    @staticmethod
    def user_loader(**kwargs):
        if 'username' in kwargs and 'password' in kwargs:
            user = User.objects(username=kwargs['username']).first()
            if user and user.check_password(kwargs['password']):
                return user
            else:
                return None
        elif 'id' in kwargs and kwargs['id']:
            return User.objects(id=ObjectId(kwargs['id'])).first()
        else:
            raise RuntimeError('This access method is not supported by the user loader.')


class AnonymousUser(UserMixin):
    @property
    def is_authenticated(self):
        return False



auth_manager.set_unauthenticated_entity_class(AnonymousUser)