Exemplo n.º 1
0
 def logout():
     """
     Logout current user
     """
     if current_user.is_authenticated:
         logout_user()
         logger.info(f'{current_user.username} has logout')
     return True
Exemplo n.º 2
0
    def login(cls, username, password, remember=True):
        """
        Attempts to login in a user with provided credentials
        """
        found = cls.find_with_password(username, password)
        if not found:
            logger.warning(f'Failed login attempt with username {username}')
            return None

        login_user(found, remember=remember)
        logger.info(f'{found.username} successfully logged in')
        return found
Exemplo n.º 3
0
def commit_or_null(session=None):
    if not session:
        session = db.session

    try:
        yield
        session.commit()
    except ValueError as exception:
        logger.info("Database transaction was rolled back due to: %r",
                    exception)

    except IntegrityError as exception:
        logger.error("Database transaction was rolled back due to: %r",
                     exception)
Exemplo n.º 4
0
def get_namespaces(path):
    """
    Dynamically import namespaces from API directory.
    Files must contain an api variable
    """
    directories = sorted(os.listdir(path))
    namespaces = []
    modules = []

    for namespace in directories:
        if '__pycache__' in namespace:
            continue

        namespace_path = os.path.join(path, namespace)
        if os.path.isdir(namespace_path):
            import_string = namespace_path.replace('/', '.')[2:]
            module = importlib.import_module(import_string)
            namespaces.append(module.api)
            modules.append(f'/{namespace}')

    logger.info(
        f"API {path.split('/')[-1]} loaded modules {', '.join(modules)}")
    return namespaces
Exemplo n.º 5
0
def init_app():
    # Touch underlying modules
    logger.info(f'Loading database models')
Exemplo n.º 6
0
def disconnect():
    """
    Call when client disconnects from SocketIO
    """
    logger.info(f'{current_user.username} has disconnected')
Exemplo n.º 7
0
def connect():
    """
    Intial connection call when client connects to SocketIO
    """
    logger.info(f'{current_user.username} has connected')
    current_user.join_project_rooms()
Exemplo n.º 8
0
def init_app():
    # Touch underlying modules
    logger.info('Loading schema module')