示例#1
0
 def logout():
     """
     Logout current user
     """
     if current_user.is_authenticated:
         logout_user()
         logger.info(f'{current_user.username} has logout')
     return True
示例#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
示例#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)
示例#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
示例#5
0
文件: __init__.py 项目: jsbroks/lista
def init_app():
    # Touch underlying modules
    logger.info(f'Loading database models')
示例#6
0
def disconnect():
    """
    Call when client disconnects from SocketIO
    """
    logger.info(f'{current_user.username} has disconnected')
示例#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()
示例#8
0
def init_app():
    # Touch underlying modules
    logger.info('Loading schema module')