]> git.ipfire.org Git - ipfire.org.git/blob - src/web/people.py
Drop admin.ipfire.org
[ipfire.org.git] / src / web / people.py
1 #!/usr/bin/python
2
3 import logging
4 import tornado.web
5
6 from . import handlers_base as base
7
8 class AvatarHandler(base.BaseHandler):
9 def get(self, uid):
10 # Get the desired size of the avatar file
11 size = self.get_argument("size", 0)
12
13 try:
14 size = int(size)
15 except (TypeError, ValueError):
16 size = None
17
18 logging.debug("Querying for avatar of %s" % uid)
19
20 # Fetch user account
21 account = self.backend.accounts.get_by_uid(uid)
22 if not account:
23 raise tornado.web.HTTPError(404, "Could not find account %s" % uid)
24
25 # Allow downstream to cache this for 60 minutes
26 self.set_expires(3600)
27
28 # Resize avatar
29 avatar = account.get_avatar(size)
30
31 # If there is no avatar, we serve a default image
32 if not avatar:
33 logging.debug("No avatar uploaded for %s" % account)
34
35 return self.redirect("https://static.ipfire.org%s" % self.static_url("img/default-avatar.jpg"))
36
37 # Set headers about content
38 self.set_header("Content-Disposition", "inline; filename=\"%s.jpg\"" % account.uid)
39 self.set_header("Content-Type", "image/jpeg")
40
41 # Deliver payload
42 self.finish(avatar)