How to use the py4web.abort 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:
                vars = dict(post_vars)
                user = self.get_user(safe=False)
                if path == "api/register":
github web2py / py4web / apps / _dashboard / __init__.py View on Github external
def save(path):
        """Saves a file"""
        path = safe_join(FOLDER, path) or abort()
        with open(path, "wb") as myfile:
            myfile.write(request.body.read())
        return {"status": "success"}
github web2py / py4web / apps / _dashboard / __init__.py View on Github external
def delete(path):
        """Deletes a file"""
        fullpath = safe_join(FOLDER, path) or abort()
        recursive_unlink(fullpath)
        return {"status": "success"}
github web2py / py4web / apps / _dashboard / __init__.py View on Github external
def load_bytes(path):
        """Loads a binary file"""
        path = safe_join(FOLDER, path) or abort()
        return open(path, "rb").read()
github web2py / py4web / py4web / utils / auth.py View on Github external
def abort_or_rediect(self, page):
        """
        return HTTP 403 if content_type is applicaitons/json
        else redirects to page"""
        if request.content_type == "application/json":
            abort(403)
        redirect(URL(self.auth.route, page))
github web2py / py4web / apps / _dashboard / __init__.py View on Github external
def prepare_target_dir(form, target_dir):
        """Prepares the target directory for the new app.
        If should_exist is False, leaves the directory blank."""
        if form["mode"] == "new":
            if os.path.exists(target_dir):
                abort(500)  # already validated client side
        elif form["mode"] == "replace":
            if os.path.exists(target_dir):
                shutil.rmtree(target_dir)
            else:
                abort(500)  # not a replacement
github web2py / py4web / apps / _dashboard / __init__.py View on Github external
def on_request(self):
        user = self.session.get("user")
        if not user or not user.get("id"):
            abort(403)
github web2py / py4web / apps / _dashboard / __init__.py View on Github external
def load(path):
        """Loads a text file"""
        path = safe_join(FOLDER, path) or abort()
        content = open(path, "rb").read().decode("utf8")
        return {"payload": content, "status": "success"}