]> git.ipfire.org Git - ipfire.org.git/commitdiff
accounts: Tidy up code for avatar generation and add some debug logging
authorMichael Tremer <michael.tremer@ipfire.org>
Thu, 11 Oct 2018 11:12:48 +0000 (12:12 +0100)
committerMichael Tremer <michael.tremer@ipfire.org>
Thu, 11 Oct 2018 11:12:48 +0000 (12:12 +0100)
Signed-off-by: Michael Tremer <michael.tremer@ipfire.org>
src/web/accounts.py

index 105255fec8350ddfdb6eea1c0335d28075e7e222..de2ac8bd97cddd983f45d520c08c9689bb4f5958 100644 (file)
@@ -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