From: Michael Tremer Date: Thu, 11 Oct 2018 11:12:48 +0000 (+0100) Subject: accounts: Tidy up code for avatar generation and add some debug logging X-Git-Url: http://git.ipfire.org/?a=commitdiff_plain;h=0cddf22010fd764bdf6f646841ec96a2b4501591;p=ipfire.org.git accounts: Tidy up code for avatar generation and add some debug logging Signed-off-by: Michael Tremer --- diff --git a/src/web/accounts.py b/src/web/accounts.py index 105255fe..de2ac8bd 100644 --- a/src/web/accounts.py +++ b/src/web/accounts.py @@ -6,7 +6,7 @@ import tornado.web from . import handlers_base as base class AvatarHandler(base.BaseHandler): - def get(self, who): + def get(self, uid): # Get the desired size of the avatar file size = self.get_argument("size", 0) @@ -15,12 +15,12 @@ class AvatarHandler(base.BaseHandler): except (TypeError, ValueError): size = None - logging.debug("Querying for avatar of %s" % who) + logging.debug("Querying for avatar of %s" % uid) # Fetch user account - account = self.backend.accounts.get_by_uid(who) + account = self.backend.accounts.get_by_uid(uid) if not account: - raise tornado.web.HTTPError(404) + raise tornado.web.HTTPError(404, "Could not find account %s" % uid) # Allow downstream to cache this for 60 minutes self.set_expires(3600) @@ -30,10 +30,12 @@ class AvatarHandler(base.BaseHandler): # If there is no avatar, we serve a default image if not avatar: + logging.debug("No avatar uploaded for %s" % account) + return self.redirect("https://static.ipfire.org%s" % self.static_url("img/default-avatar.jpg")) # Set headers about content - self.set_header("Content-Disposition", "inline; filename=\"%s.jpg\"" % who) + self.set_header("Content-Disposition", "inline; filename=\"%s.jpg\"" % account.uid) self.set_header("Content-Type", "image/jpeg") # Deliver payload