Skip to content

Commit

Permalink
[AdminTL#83] server: send error to user client when got error status
Browse files Browse the repository at this point in the history
  • Loading branch information
mathben committed Mar 19, 2018
1 parent 7f39157 commit c425a4e
Showing 1 changed file with 12 additions and 0 deletions.
12 changes: 12 additions & 0 deletions src/web/handlers.py
Original file line number Diff line number Diff line change
Expand Up @@ -33,6 +33,7 @@ def get(self):
print("Error, the path %s not exist." % path_acme_challenge, file=sys.stderr)
# Not found
self.set_status(404)
self.send_error(404)
raise tornado.web.Finish()

# check file exist
Expand All @@ -41,6 +42,7 @@ def get(self):
print("Error, no files in path %s" % path_acme_challenge, file=sys.stderr)
# Not found
self.set_status(404)
self.send_error(404)
raise tornado.web.Finish()

first_file_path = os.path.join(path_acme_challenge, files[0])
Expand Down Expand Up @@ -87,6 +89,7 @@ def post(self):
print("Need to logout before login or sign up from %s" % self.request.remote_ip, file=sys.stderr)
# Bad request
self.set_status(400)
self.send_error(400)
raise tornado.web.Finish()

# EXTREMELY IMPORTANT to prevent accessing accounts that do not yet have a password.
Expand Down Expand Up @@ -327,6 +330,7 @@ def get(self):
if self._global_arg["disable_login"]:
# Not found
self.set_status(404)
self.send_error(404)
raise tornado.web.Finish()
if self.current_user:
self.clear_cookie("user")
Expand All @@ -344,13 +348,15 @@ def get(self):
if self._global_arg["disable_admin"]:
# Not Found
self.set_status(404)
self.send_error(404)
raise tornado.web.Finish()
if self.current_user.get("permission") == "Admin":
self.render('admin_character.html', **self._global_arg)
else:
print("Insufficient permissions from %s" % self.request.remote_ip, file=sys.stderr)
# Forbidden
self.set_status(403)
self.send_error(403)
raise tornado.web.Finish()


Expand All @@ -361,6 +367,7 @@ def get(self, user_id=None):
if self._global_arg["disable_character"]:
# Not Found
self.set_status(404)
self.send_error(404)
raise tornado.web.Finish()
if user_id:
user = self._db.get_user(user_id=user_id)
Expand All @@ -375,6 +382,7 @@ def get(self):
if self._global_arg["disable_character"]:
# Not Found
self.set_status(404)
self.send_error(404)
raise tornado.web.Finish()

self.render('character.html', **self._global_arg)
Expand All @@ -386,13 +394,15 @@ def get(self):
if self._global_arg["disable_character"]:
# Not Found
self.set_status(404)
self.send_error(404)
raise tornado.web.Finish()

user_id = self.request.query[len("user_id="):]
is_admin = self.request.query == "is_admin"
if user_id == "" and not is_admin:
# Forbidden
self.set_status(403)
self.send_error(403)
raise tornado.web.Finish()

# TODO manage what we get and user management permission
Expand All @@ -409,6 +419,7 @@ def post(self):
if self._global_arg["disable_character"]:
# Not Found
self.set_status(404)
self.send_error(404)
raise tornado.web.Finish()
self.prepare_json()

Expand Down Expand Up @@ -465,5 +476,6 @@ def get(self):
# TODO need to test this line with a unittest
# self.get_argument("username or email")
self.set_status(400)
self.send_error(400)
raise tornado.web.Finish()
self.finish()

0 comments on commit c425a4e

Please sign in to comment.