Secure your code as it's written. Use Snyk Code to scan source code in minutes - no build needed - and fix issues immediately.
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":
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"}
def delete(path):
"""Deletes a file"""
fullpath = safe_join(FOLDER, path) or abort()
recursive_unlink(fullpath)
return {"status": "success"}
def load_bytes(path):
"""Loads a binary file"""
path = safe_join(FOLDER, path) or abort()
return open(path, "rb").read()
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))
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
def on_request(self):
user = self.session.get("user")
if not user or not user.get("id"):
abort(403)
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"}