How to use the py4web.request.json function in py4web

To help you get started, we’ve selected a few py4web examples, based on popular ways it is used in public projects.

Secure your code as it's written. Use Snyk Code to scan source code in minutes - no build needed - and fix issues immediately.

github web2py / py4web / py4web / utils / auth.py View on Github external
def action(self, path, method, get_vars, post_vars, env=None):
        """action that handles all the HTTP requests for Auth"""
        env = env or {}
        if path.startswith("plugin/"):
            parts = path.split("/", 2)
            plugin = self.plugins.get(parts[1])
            if plugin:
                return plugin.handle_request(
                    self, parts[2], request.query, request.json
                )
            else:
                abort(404)
        if path.startswith("api/"):
            data = {}
            if method == "GET":
                # Should we use the username?
                if path == "api/use_username":
                    return {"use_username": self.use_username}
                # Otherwise, we assume the user exists.
                user = self.get_user(safe=True)
                if not user:
                    data = self._error("not authorized", 401)
                if path == "api/profile":
                    return {"user": user}
            elif method == "POST" and self.db:
github web2py / py4web / py4web / utils / publisher.py View on Github external
def api(self, tablename, id=None):
        policy = self.policy
        data = self.restapi(request.method, tablename, id, request.query, request.json)
        response.status = data["code"]
        return data
github web2py / py4web / apps / _dashboard / __init__.py View on Github external
def login():
        if MODE == "demo":
            valid = True
        else:
            valid = False
            password = request.json.get("password")
            password_file = os.environ.get("PY4WEB_PASSWORD_FILE")
            if password and password_file and os.path.exists(password_file):
                with open(password_file, "r") as fp:
                    encrypted_password = fp.read().strip()
                    valid = CRYPT()(password)[0] == encrypted_password
        if valid:
            session["user"] = dict(id=1)
        return dict(user=valid, mode=MODE)
github web2py / py4web / apps / todo / __init__.py View on Github external
def todo():
    return dict(id=db.todo.insert(info=request.json.get("info")))
github web2py / py4web / apps / _dashboard / __init__.py View on Github external
def new_app():
        form = request.json
        # Directory for zipped assets
        assets_dir = os.path.join(os.path.dirname(py4web.__file__), "assets")
        target_dir = safe_join(FOLDER, form["name"])
        if form["type"] == "minimal":
            source = os.path.join(assets_dir, "py4web.app._minimal.zip")
            source_dir = safe_join(FOLDER, "_minimal")
            prepare_target_dir(form, target_dir)
            install_by_unzip_or_treecopy(source, source_dir, target_dir)
        elif form["type"] == "scaffold":
            source = os.path.join(assets_dir, "py4web.app._scaffold.zip")
            source_dir = safe_join(FOLDER, "_scaffold")
            prepare_target_dir(form, target_dir)
            install_by_unzip_or_treecopy(source, source_dir, target_dir)
        elif form["type"] == "web":
            prepare_target_dir(form, target_dir)
            source = form["source"]
github web2py / py4web / apps / _dashboard / __init__.py View on Github external
lambda: RestAPI(db, policy)(
                    request.method, args[2], id, request.query, request.json
                )
github web2py / py4web / py4web / utils / auth.py View on Github external
def responder(path, env=env):
            return self.action(
                path, request.method, request.query, request.json, env=env
            )