Merge pull request #86 from ngoduykhanh/gravatar

Add Gravatar
This commit is contained in:
Khanh Ngo 2016-07-14 00:09:04 +07:00 committed by GitHub
commit 198f934138
4 changed files with 12 additions and 4 deletions

View File

@ -3,6 +3,8 @@ import sys
import json
import requests
import urlparse
import hashlib
from app import app
from distutils.version import StrictVersion
@ -145,3 +147,7 @@ def pdns_api_extended_uri(version):
return "/api/v1"
else:
return ""
def email_to_gravatar_url(email, size=100):
hash_string = hashlib.md5(email).hexdigest()
return "https://s.gravatar.com/avatar/%s?s=%s" % (hash_string, size)

View File

@ -65,7 +65,7 @@
{% if current_user.avatar %}
<img src="{{ url_for('user_avatar', filename=current_user.avatar) }}" class="user-image" alt="User Image"/>
{% else %}
<img src="{{ url_for('static', filename='adminlte2/dist/img/avatar.png') }}" class="user-image" alt="User Image"/>
<img src="{{ current_user.email|email_to_gravatar_url(size=80) }}" class="user-image" alt="User Image"/>
{% endif %}
<span class="hidden-xs">
{{ current_user.firstname }}
@ -76,7 +76,7 @@
{% if current_user.avatar %}
<img src="{{ url_for('user_avatar', filename=current_user.avatar) }}" class="img-circle" alt="User Image"/>
{% else %}
<img src="{{ url_for('static', filename='adminlte2/dist/img/avatar.png') }}" class="img-circle" alt="User Image"/>
<img src="{{ current_user.email|email_to_gravatar_url(size=160) }}" class="img-circle" alt="User Image"/>
{% endif %}
<p>
{{ current_user.firstname }} {{ current_user.lastname }}
@ -111,7 +111,7 @@
{% if current_user.avatar %}
<img src="{{ url_for('user_avatar', filename=current_user.avatar) }}" class="img-circle" alt="User Image"/>
{% else %}
<img src="{{ url_for('static', filename='adminlte2/dist/img/avatar.png') }}" class="img-circle" alt="User Image"/>
<img src="{{ current_user.email|email_to_gravatar_url(size=100) }}" class="img-circle" alt="User Image"/>
{% endif %}
</div>
<div class="pull-left info">

View File

@ -67,7 +67,7 @@
src="{{ url_for('user_avatar', filename=current_user.avatar) }}"
alt="" / style="width: 200px; height: 200px;"> {%
else %} <img
src="http://www.placehold.it/200x200/EFEFEF/AAAAAA&amp;text=no+image"
src="{{ current_user.email|email_to_gravatar_url(size=200) }}"
alt="" /> {% endif %}
</div>
<div>

View File

@ -22,6 +22,7 @@ from optparse import Values
jinja2.filters.FILTERS['display_record_name'] = utils.display_record_name
jinja2.filters.FILTERS['display_master_name'] = utils.display_master_name
jinja2.filters.FILTERS['display_second_to_time'] = utils.display_time
jinja2.filters.FILTERS['email_to_gravatar_url'] = utils.email_to_gravatar_url
# Flag for pdns v4.x.x
# TODO: Find another way to do this
@ -68,6 +69,7 @@ def before_request():
g.user = current_user
login_manager.anonymous_user = Anonymous
@login_manager.user_loader
def load_user(id):
"""