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'],
|
||||
}
|
||||
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:
|
||||
from ivatar.settings import DATABASES
|
||||
|
||||
@@ -1124,12 +1124,52 @@ class Tester(TestCase): # pylint: disable=too-many-public-methods
|
||||
self.user.confirmedemail_set.first().delete()
|
||||
url = '%s?%s' % (urlobj.path, urlobj.query)
|
||||
response = self.client.get(url, follow=True)
|
||||
self.assertEqual(
|
||||
response['Content-Type'],
|
||||
'image/png',
|
||||
'Content type wrong!?')
|
||||
self.assertRedirects(
|
||||
response=response,
|
||||
expected_url='/static/img/mm/80.png',
|
||||
msg_prefix='Why does this not redirect to the default img?')
|
||||
# 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):
|
||||
'''
|
||||
Test cropping photo
|
||||
|
||||
@@ -23,33 +23,20 @@
|
||||
<p>
|
||||
This is what the avatars will look like depending on the hash and protocol you use:<br/>
|
||||
|
||||
{% if mail_hash %}
|
||||
MD5 hash (mail): {{ mail_hash }}<br/>
|
||||
SHA256 hash (mail): {{ mail_hash256 }}<br/>
|
||||
{% endif %}
|
||||
<div class="d-none d-lg-block">
|
||||
{% if mail_hash %}
|
||||
MD5 hash (mail): {{ mail_hash }}<br/>
|
||||
SHA256 hash (mail): {{ mail_hash256 }}<br/>
|
||||
{% endif %}
|
||||
|
||||
{% if openid_hash %}
|
||||
SHA256 hash (OpenID): {{ openid_hash }}<br/>
|
||||
{% endif %}
|
||||
{% if openid_hash %}
|
||||
SHA256 hash (OpenID): {{ openid_hash }}<br/>
|
||||
{% endif %}
|
||||
</div>
|
||||
</p>
|
||||
|
||||
<ul class="horizontal-list avatar-list centered" style="font-size:smaller;">
|
||||
{% 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>
|
||||
<div style="float:left;">
|
||||
<a href="{{ mailurl_secure }}">
|
||||
@@ -63,21 +50,6 @@
|
||||
</div>
|
||||
<br/>MD5
|
||||
</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>
|
||||
<div style="float:left;">
|
||||
<a href="{{ SECURE_BASE_URL }}{{ mail_hash256 }}?s={{ size }}">
|
||||
@@ -94,21 +66,6 @@
|
||||
{% endif %}
|
||||
|
||||
{% 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>
|
||||
<div style="float:left;">
|
||||
<a href="{{ openidurl_secure }}">
|
||||
|
||||
@@ -5,7 +5,7 @@ from io import BytesIO
|
||||
from os import path
|
||||
from PIL import Image
|
||||
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 ivatar.settings import AVATAR_MAX_SIZE, JPEG_QUALITY
|
||||
from . ivataraccount.models import ConfirmedEmail, ConfirmedOpenId
|
||||
@@ -26,6 +26,11 @@ class AvatarImageView(TemplateView):
|
||||
size = 80
|
||||
imgformat = 'png'
|
||||
obj = None
|
||||
default = None
|
||||
|
||||
if 'd' in request.GET:
|
||||
default = request.GET['d']
|
||||
|
||||
if 's' in request.GET:
|
||||
size = request.GET['s']
|
||||
size = int(size)
|
||||
@@ -51,13 +56,19 @@ class AvatarImageView(TemplateView):
|
||||
except ObjectDoesNotExist:
|
||||
pass
|
||||
|
||||
# If that mail/openid doesn't exist, or has no photo linked to it
|
||||
if not obj or not obj.photo:
|
||||
static_img = path.join('static', 'img', 'mm', '%s%s' % (str(size), '.png'))
|
||||
if path.isfile(static_img):
|
||||
photodata = Image.open(static_img)
|
||||
# Return the default URL, as specified
|
||||
if default:
|
||||
return HttpResponseRedirect(default)
|
||||
# Return our default URl
|
||||
else:
|
||||
# TODO: Resize it!?
|
||||
static_img = path.join('static', 'img', 'mm', '512.png')
|
||||
static_img = path.join('static', 'img', 'mm', '%s%s' % (str(size), '.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:
|
||||
imgformat = obj.photo.format
|
||||
photodata = Image.open(BytesIO(obj.photo.data))
|
||||
@@ -70,5 +81,3 @@ class AvatarImageView(TemplateView):
|
||||
return HttpResponse(
|
||||
data,
|
||||
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 site_brand %}
|
||||
<div id="logo">
|
||||
<a class="navbar-brand d-none d-lg-block" href="/">
|
||||
<img src="{% static 'img/logo.png' %}" width="60" height="60" class="d-inline-block align-top" alt="{% trans 'Home' %}">
|
||||
</a>
|
||||
{% if user.is_anonymous %}
|
||||
<a class="navbar-brand d-none d-lg-block" href="/">
|
||||
<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>
|
||||
<span class="d-none d-lg-block">
|
||||
<div id="site-branding">
|
||||
@@ -36,6 +44,13 @@
|
||||
{% block nav %}
|
||||
<div class="collapse navbar-collapse" id="navbarNavDropdown">
|
||||
<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;">
|
||||
<a class="nav-link" href="TODO contact" target="_new"><i class="fa fa-envelope" aria-hidden="true"></i>
|
||||
{% trans 'Contact' %}
|
||||
|
||||
Reference in New Issue
Block a user