Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

feat(Utils):🦺 Add New Function to Verify Account #406

Open
wants to merge 2 commits into
base: master
Choose a base branch
from
Open
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
18 changes: 15 additions & 3 deletions lib/gravatar/utils.py
Original file line number Diff line number Diff line change
Expand Up @@ -2,6 +2,7 @@
import hashlib

# Third Party (PyPI) Imports
import requests
import six.moves.urllib as urllib

# Django Imports
Expand All @@ -11,7 +12,7 @@
# http://en.gravatar.com/site/implement/images/
GRAVATAR_URL_PROTOCOL = 'https' if settings.SECURE_SSL_HOST or settings.SECURE_SSL_REDIRECT else 'http'
GRAVATAR_URL_PREFIX = getattr(settings, 'GRAVATAR_URL_PREFIX', '%s://%s' % (GRAVATAR_URL_PROTOCOL, 'www.gravatar.com',))
GRAVATAR_DEFAULT_IMAGE = getattr(settings, 'GRAVATAR_DEFAULT_IMAGE', 'mm')
GRAVATAR_DEFAULT_IMAGE = getattr(settings, 'GRAVATAR_DEFAULT_IMAGE', 'mp')
GRAVATAR_DEFAULT_SIZE = 80


Expand All @@ -24,7 +25,11 @@ def get_gravatar_hash(email):
return gravatar_hash


def get_gravatar_for_email(email, size=GRAVATAR_DEFAULT_SIZE):
def get_gravatar_for_email(email, size=GRAVATAR_DEFAULT_SIZE, default=GRAVATAR_DEFAULT_IMAGE):
return build_gravatar_url_for_email(email, size=GRAVATAR_DEFAULT_SIZE, default=GRAVATAR_DEFAULT_IMAGE)


def build_gravatar_url_for_email(email, size=GRAVATAR_DEFAULT_SIZE, default=GRAVATAR_DEFAULT_IMAGE):
lleung030 marked this conversation as resolved.
Show resolved Hide resolved
"""
https://en.gravatar.com/site/implement/images/
"""
Expand All @@ -40,7 +45,14 @@ def get_gravatar_for_email(email, size=GRAVATAR_DEFAULT_SIZE):
url += urllib.parse.urlencode(
{
's': str(size),
'default': GRAVATAR_DEFAULT_IMAGE,
'default': default,
}
)
return url


def has_gravatar(email):
url = get_gravatar_for_email(email, default='404')
response = requests.get(url)
has_gravatar = response.status_code == 200
return has_gravatar