mirror of
https://git.linux-kernel.at/oliver/ivatar.git
synced 2025-11-17 13:38:03 +00:00
Fetch image via hash for OpenID and email
This commit is contained in:
34
ivatar/views.py
Normal file
34
ivatar/views.py
Normal file
@@ -0,0 +1,34 @@
|
||||
'''
|
||||
views under /
|
||||
'''
|
||||
import io
|
||||
from django.views.generic.base import TemplateView
|
||||
from django.http import HttpResponse
|
||||
from . ivataraccount.models import ConfirmedEmail, ConfirmedOpenId
|
||||
|
||||
|
||||
class AvatarImageView(TemplateView):
|
||||
'''
|
||||
View to return (binary) image, based for OpenID/Email (both by digest)
|
||||
'''
|
||||
|
||||
def get(self, *args, **kwargs):
|
||||
'''
|
||||
Override get from parent class
|
||||
'''
|
||||
model = ConfirmedEmail
|
||||
if len(kwargs['digest']) == 32:
|
||||
# Fetch by digest from mail
|
||||
pass
|
||||
elif len(kwargs['digest']) == 64:
|
||||
# Fetch by digest from OpenID
|
||||
model = ConfirmedOpenId
|
||||
else:
|
||||
raise Exception('Digest provided is wrong: %s' % kwargs['digest'])
|
||||
|
||||
email = model.objects.get(digest=kwargs['digest'])
|
||||
if not email.photo:
|
||||
raise Exception('No photo assigned to "%s"' % email.email)
|
||||
|
||||
return HttpResponse(
|
||||
io.BytesIO(email.photo.data), content_type='image/%s' % email.photo.format)
|
||||
Reference in New Issue
Block a user