Function wrapper to signalize that a login is required.

def require_login(func):
    """
    Function wrapper to signalize that a login is required.
    """

    @wraps(func)
    def decorated(*args, **kwargs):
        auth = request.authorization
        if not auth:
            return authenticate()

        user = session.query(User).filter(
            User.name == auth.username
        ).first()
        if user and user.check(auth.password):
            g.user = user
            return func(*args, **kwargs)
        else:
            return authenticate()

    return decorated