mirror of
https://git.linux-kernel.at/oliver/ivatar.git
synced 2025-11-17 13:38:03 +00:00
Merge branch 'devel' into 'master'
Merge in latest devel See merge request oliver/ivatar!37
This commit is contained in:
@@ -102,7 +102,7 @@ if 'test' not in sys.argv and 'collectstatic' not in sys.argv:
|
|||||||
'MAILGUN_SENDER_DOMAIN': os.environ['IVATAR_MAILGUN_SENDER_DOMAIN'],
|
'MAILGUN_SENDER_DOMAIN': os.environ['IVATAR_MAILGUN_SENDER_DOMAIN'],
|
||||||
}
|
}
|
||||||
EMAIL_BACKEND = 'anymail.backends.mailgun.EmailBackend' # pragma: no cover
|
EMAIL_BACKEND = 'anymail.backends.mailgun.EmailBackend' # pragma: no cover
|
||||||
DEFAULT_FROM_EMAIL = 'ivatar@linux-kernel.at'
|
DEFAULT_FROM_EMAIL = 'ivatar@mg.linux-kernel.at'
|
||||||
|
|
||||||
try:
|
try:
|
||||||
from ivatar.settings import DATABASES
|
from ivatar.settings import DATABASES
|
||||||
|
|||||||
@@ -1124,12 +1124,52 @@ class Tester(TestCase): # pylint: disable=too-many-public-methods
|
|||||||
self.user.confirmedemail_set.first().delete()
|
self.user.confirmedemail_set.first().delete()
|
||||||
url = '%s?%s' % (urlobj.path, urlobj.query)
|
url = '%s?%s' % (urlobj.path, urlobj.query)
|
||||||
response = self.client.get(url, follow=True)
|
response = self.client.get(url, follow=True)
|
||||||
self.assertEqual(
|
self.assertRedirects(
|
||||||
response['Content-Type'],
|
response=response,
|
||||||
'image/png',
|
expected_url='/static/img/mm/80.png',
|
||||||
'Content type wrong!?')
|
msg_prefix='Why does this not redirect to the default img?')
|
||||||
# Eventually one should check if the data is the same
|
# Eventually one should check if the data is the same
|
||||||
|
|
||||||
|
def test_avatar_url_default(self): # pylint: disable=invalid-name
|
||||||
|
'''
|
||||||
|
Test fetching avatar for not existing mail with default specified
|
||||||
|
'''
|
||||||
|
urlobj = urlsplit(
|
||||||
|
libravatar_url(
|
||||||
|
'xxx@xxx.xxx',
|
||||||
|
size=80,
|
||||||
|
default='/static/img/nobody.png',
|
||||||
|
)
|
||||||
|
)
|
||||||
|
url = '%s?%s' % (urlobj.path, urlobj.query)
|
||||||
|
response = self.client.get(url, follow=True)
|
||||||
|
self.assertRedirects(
|
||||||
|
response=response,
|
||||||
|
expected_url='/static/img/nobody.png',
|
||||||
|
msg_prefix='Why does this not redirect to the default img?')
|
||||||
|
|
||||||
|
def test_avatar_url_default_external(self): # pylint: disable=invalid-name
|
||||||
|
'''
|
||||||
|
Test fetching avatar for not existing mail with external default specified
|
||||||
|
'''
|
||||||
|
default = 'http://host.tld/img.png'
|
||||||
|
urlobj = urlsplit(
|
||||||
|
libravatar_url(
|
||||||
|
'xxx@xxx.xxx',
|
||||||
|
size=80,
|
||||||
|
default=default,
|
||||||
|
)
|
||||||
|
)
|
||||||
|
url = '%s?%s' % (urlobj.path, urlobj.query)
|
||||||
|
response = self.client.get(url, follow=False)
|
||||||
|
print(response)
|
||||||
|
print(response.content)
|
||||||
|
self.assertRedirects(
|
||||||
|
response=response,
|
||||||
|
expected_url=default,
|
||||||
|
fetch_redirect_response=False,
|
||||||
|
msg_prefix='Why does this not redirect to the default img?')
|
||||||
|
|
||||||
def test_crop_photo(self):
|
def test_crop_photo(self):
|
||||||
'''
|
'''
|
||||||
Test cropping photo
|
Test cropping photo
|
||||||
|
|||||||
@@ -23,33 +23,20 @@
|
|||||||
<p>
|
<p>
|
||||||
This is what the avatars will look like depending on the hash and protocol you use:<br/>
|
This is what the avatars will look like depending on the hash and protocol you use:<br/>
|
||||||
|
|
||||||
{% if mail_hash %}
|
<div class="d-none d-lg-block">
|
||||||
MD5 hash (mail): {{ mail_hash }}<br/>
|
{% if mail_hash %}
|
||||||
SHA256 hash (mail): {{ mail_hash256 }}<br/>
|
MD5 hash (mail): {{ mail_hash }}<br/>
|
||||||
{% endif %}
|
SHA256 hash (mail): {{ mail_hash256 }}<br/>
|
||||||
|
{% endif %}
|
||||||
|
|
||||||
{% if openid_hash %}
|
{% if openid_hash %}
|
||||||
SHA256 hash (OpenID): {{ openid_hash }}<br/>
|
SHA256 hash (OpenID): {{ openid_hash }}<br/>
|
||||||
{% endif %}
|
{% endif %}
|
||||||
|
</div>
|
||||||
</p>
|
</p>
|
||||||
|
|
||||||
<ul class="horizontal-list avatar-list centered" style="font-size:smaller;">
|
<ul class="horizontal-list avatar-list centered" style="font-size:smaller;">
|
||||||
{% if mailurl %}
|
{% if mailurl %}
|
||||||
{% if not request.is_secure %}
|
|
||||||
<li>
|
|
||||||
<div style="float:left;">
|
|
||||||
<a href="{{ mailurl }}">
|
|
||||||
<img src="{{ mailurl }}" style="max-width: {{ size }}px; max-height: {{ size }}px;">
|
|
||||||
</a>
|
|
||||||
<div style="padding-left:2px; float:inline-end; font-size:{% widthratio size 3 1 %}px;">
|
|
||||||
<i class="fa fa-unlock-alt" title="None-SSL connection (http)"></i>
|
|
||||||
<br/>
|
|
||||||
<i class="fa fa-at" title="mail: {{ form.mail.value }}"></i>
|
|
||||||
</div>
|
|
||||||
</div>
|
|
||||||
<br/>MD5
|
|
||||||
</li>
|
|
||||||
{% endif %}
|
|
||||||
<li>
|
<li>
|
||||||
<div style="float:left;">
|
<div style="float:left;">
|
||||||
<a href="{{ mailurl_secure }}">
|
<a href="{{ mailurl_secure }}">
|
||||||
@@ -63,21 +50,6 @@
|
|||||||
</div>
|
</div>
|
||||||
<br/>MD5
|
<br/>MD5
|
||||||
</li>
|
</li>
|
||||||
{% if not request.is_secure %}
|
|
||||||
<li>
|
|
||||||
<div style="float:left;">
|
|
||||||
<a href="{{ BASE_URL }}{{ mail_hash256 }}?s={{ size }}">
|
|
||||||
<img src="{{ BASE_URL }}{{ mail_hash256 }}?s={{ size }}" style="max-width: {{ size }}px; max-height: {{ size }}px;">
|
|
||||||
</a>
|
|
||||||
<div style="padding-left:2px; float:inline-end; font-size:{% widthratio size 3 1 %}px;">
|
|
||||||
<i class="fa fa-unlock-alt" title="None-SSL connection (http)"></i>
|
|
||||||
<br/>
|
|
||||||
<i class="fa fa-at" title="mail: {{ form.mail.value }}"></i>
|
|
||||||
</div>
|
|
||||||
</div>
|
|
||||||
<br/>SHA256
|
|
||||||
</li>
|
|
||||||
{% endif %}
|
|
||||||
<li>
|
<li>
|
||||||
<div style="float:left;">
|
<div style="float:left;">
|
||||||
<a href="{{ SECURE_BASE_URL }}{{ mail_hash256 }}?s={{ size }}">
|
<a href="{{ SECURE_BASE_URL }}{{ mail_hash256 }}?s={{ size }}">
|
||||||
@@ -94,21 +66,6 @@
|
|||||||
{% endif %}
|
{% endif %}
|
||||||
|
|
||||||
{% if openidurl %}
|
{% if openidurl %}
|
||||||
{% if not request.is_secure %}
|
|
||||||
<li>
|
|
||||||
<div style="float:left;">
|
|
||||||
<a href="{{ openidurl }}">
|
|
||||||
<img src="{{ openidurl }}" style="max-width: {{ size }}px; max-height: {{ size }}px;">
|
|
||||||
</a>
|
|
||||||
<div style="padding-left:2px; float:inline-end; font-size:{% widthratio size 3 1 %}px">
|
|
||||||
<i class="fa fa-unlock-alt" title="None-SSL connection (http)"></i>
|
|
||||||
<br/>
|
|
||||||
<i class="fa fa-openid" title="openid: {{ form.openid.value }}"></i>
|
|
||||||
</div>
|
|
||||||
</div>
|
|
||||||
<br/>SHA256
|
|
||||||
</li>
|
|
||||||
{% endif %}
|
|
||||||
<li>
|
<li>
|
||||||
<div style="float:left;">
|
<div style="float:left;">
|
||||||
<a href="{{ openidurl_secure }}">
|
<a href="{{ openidurl_secure }}">
|
||||||
|
|||||||
@@ -5,7 +5,7 @@ from io import BytesIO
|
|||||||
from os import path
|
from os import path
|
||||||
from PIL import Image
|
from PIL import Image
|
||||||
from django.views.generic.base import TemplateView
|
from django.views.generic.base import TemplateView
|
||||||
from django.http import HttpResponse
|
from django.http import HttpResponse, HttpResponseRedirect
|
||||||
from django.core.exceptions import ObjectDoesNotExist
|
from django.core.exceptions import ObjectDoesNotExist
|
||||||
from ivatar.settings import AVATAR_MAX_SIZE, JPEG_QUALITY
|
from ivatar.settings import AVATAR_MAX_SIZE, JPEG_QUALITY
|
||||||
from . ivataraccount.models import ConfirmedEmail, ConfirmedOpenId
|
from . ivataraccount.models import ConfirmedEmail, ConfirmedOpenId
|
||||||
@@ -26,6 +26,11 @@ class AvatarImageView(TemplateView):
|
|||||||
size = 80
|
size = 80
|
||||||
imgformat = 'png'
|
imgformat = 'png'
|
||||||
obj = None
|
obj = None
|
||||||
|
default = None
|
||||||
|
|
||||||
|
if 'd' in request.GET:
|
||||||
|
default = request.GET['d']
|
||||||
|
|
||||||
if 's' in request.GET:
|
if 's' in request.GET:
|
||||||
size = request.GET['s']
|
size = request.GET['s']
|
||||||
size = int(size)
|
size = int(size)
|
||||||
@@ -51,13 +56,19 @@ class AvatarImageView(TemplateView):
|
|||||||
except ObjectDoesNotExist:
|
except ObjectDoesNotExist:
|
||||||
pass
|
pass
|
||||||
|
|
||||||
|
# If that mail/openid doesn't exist, or has no photo linked to it
|
||||||
if not obj or not obj.photo:
|
if not obj or not obj.photo:
|
||||||
static_img = path.join('static', 'img', 'mm', '%s%s' % (str(size), '.png'))
|
# Return the default URL, as specified
|
||||||
if path.isfile(static_img):
|
if default:
|
||||||
photodata = Image.open(static_img)
|
return HttpResponseRedirect(default)
|
||||||
|
# Return our default URl
|
||||||
else:
|
else:
|
||||||
# TODO: Resize it!?
|
static_img = path.join('static', 'img', 'mm', '%s%s' % (str(size), '.png'))
|
||||||
static_img = path.join('static', 'img', 'mm', '512.png')
|
if not path.isfile(static_img):
|
||||||
|
# We trust this exists!!!
|
||||||
|
static_img = path.join('static', 'img', 'mm', '512.png')
|
||||||
|
# We trust static/ is mapped to /static/
|
||||||
|
return HttpResponseRedirect('/' + static_img)
|
||||||
else:
|
else:
|
||||||
imgformat = obj.photo.format
|
imgformat = obj.photo.format
|
||||||
photodata = Image.open(BytesIO(obj.photo.data))
|
photodata = Image.open(BytesIO(obj.photo.data))
|
||||||
@@ -70,5 +81,3 @@ class AvatarImageView(TemplateView):
|
|||||||
return HttpResponse(
|
return HttpResponse(
|
||||||
data,
|
data,
|
||||||
content_type='image/%s' % imgformat)
|
content_type='image/%s' % imgformat)
|
||||||
# One eventually also wants to check if the DATA is correct,
|
|
||||||
# not only the size
|
|
||||||
|
|||||||
@@ -19,9 +19,17 @@
|
|||||||
{% block topbar %}
|
{% block topbar %}
|
||||||
{% block site_brand %}
|
{% block site_brand %}
|
||||||
<div id="logo">
|
<div id="logo">
|
||||||
<a class="navbar-brand d-none d-lg-block" href="/">
|
{% if user.is_anonymous %}
|
||||||
<img src="{% static 'img/logo.png' %}" width="60" height="60" class="d-inline-block align-top" alt="{% trans 'Home' %}">
|
<a class="navbar-brand d-none d-lg-block" href="/">
|
||||||
</a>
|
<img src="{% static 'img/logo.png' %}" width="60" height="60" class="d-inline-block align-top"
|
||||||
|
alt="{% trans 'Home' %}">
|
||||||
|
</a>
|
||||||
|
{% else %}
|
||||||
|
<a class="navbar-brand d-none d-lg-block" href="{% url 'profile' %}">
|
||||||
|
<img src="{% static 'img/logo.png' %}" width="60" height="60" class="d-inline-block align-top"
|
||||||
|
alt="{% trans 'Profile' %}">
|
||||||
|
</a>
|
||||||
|
{% endif %}
|
||||||
</div>
|
</div>
|
||||||
<span class="d-none d-lg-block">
|
<span class="d-none d-lg-block">
|
||||||
<div id="site-branding">
|
<div id="site-branding">
|
||||||
@@ -36,6 +44,13 @@
|
|||||||
{% block nav %}
|
{% block nav %}
|
||||||
<div class="collapse navbar-collapse" id="navbarNavDropdown">
|
<div class="collapse navbar-collapse" id="navbarNavDropdown">
|
||||||
<ul class="navbar-nav mr-auto nav">
|
<ul class="navbar-nav mr-auto nav">
|
||||||
|
{% if not user.is_anonymous %}
|
||||||
|
<li class="nav-item" style="margin-left: 5px;">
|
||||||
|
<a class="nav-link" href="/" target="_new"><i class="fa fa-home" aria-hidden="true"></i>
|
||||||
|
{% trans 'Home' %}
|
||||||
|
</a>
|
||||||
|
</li>
|
||||||
|
{% endif %}
|
||||||
<li class="nav-item" style="margin-left: 5px;">
|
<li class="nav-item" style="margin-left: 5px;">
|
||||||
<a class="nav-link" href="TODO contact" target="_new"><i class="fa fa-envelope" aria-hidden="true"></i>
|
<a class="nav-link" href="TODO contact" target="_new"><i class="fa fa-envelope" aria-hidden="true"></i>
|
||||||
{% trans 'Contact' %}
|
{% trans 'Contact' %}
|
||||||
|
|||||||
Reference in New Issue
Block a user