def logout(): """ Logout current user """ if current_user.is_authenticated: logout_user() logger.info(f'{current_user.username} has logout') return True
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
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)
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
def init_app(): # Touch underlying modules logger.info(f'Loading database models')
def disconnect(): """ Call when client disconnects from SocketIO """ logger.info(f'{current_user.username} has disconnected')
def connect(): """ Intial connection call when client connects to SocketIO """ logger.info(f'{current_user.username} has connected') current_user.join_project_rooms()
def init_app(): # Touch underlying modules logger.info('Loading schema module')