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

FIX: AJAX, + many #36

Open
wants to merge 10 commits into
base: master
Choose a base branch
from
2 changes: 1 addition & 1 deletion django_ulogin/templates/django_ulogin/ulogin_media.html
Original file line number Diff line number Diff line change
@@ -1 +1 @@
<script src="{{ WIDGET_URL }}"></script>
<script {%if RAND %}onload="uLogin.customInit('uLogin-{{ RAND }}')" {% endif %}src="{{ WIDGET_URL }}"></script>
3 changes: 2 additions & 1 deletion django_ulogin/templates/django_ulogin/ulogin_widget.html
Original file line number Diff line number Diff line change
Expand Up @@ -5,7 +5,7 @@
{% if SCHEME_NOT_FOUND %}
<div>[ulogin]: scheme {{ NAME }} not found</div>
{% else %}
{% ulogin_media %}
{% ulogin_media RAND %}

{% if DISPLAY == 'button' %}
<a id="uLogin-b{{ RAND }}" href="#" data-ulogin="display=window;fields={{ FIELDS }};optional={{ OPTIONAL }};providers={{ PROVIDERS }};hidden={{ HIDDEN }};redirect_uri={{ REDIRECT_URL }}{% if CALLBACK %};callback={{ CALLBACK }}{% endif %}">
Expand All @@ -14,5 +14,6 @@
{% else %}
<div id="uLogin-{{ RAND }}" data-ulogin="display={{ DISPLAY }};fields={{ FIELDS }};optional={{ OPTIONAL }};providers={{ PROVIDERS }};hidden={{ HIDDEN }};redirect_uri={{ REDIRECT_URL }}{% if CALLBACK %};callback={{ CALLBACK }}{% endif %}"></div>
{% endif %}
<script>(typeof(uLogin)!='undefined')&&(uLogin.customInit('uLogin-{{ RAND }}'));</script>
{% endif %}
{% endspaceless %}
8 changes: 6 additions & 2 deletions django_ulogin/templatetags/ulogin_tags.py
Original file line number Diff line number Diff line change
Expand Up @@ -50,7 +50,10 @@ def ulogin_widget(context, name="default"):
'SCHEME_NOT_FOUND': True,
'NAME': name
}
glue = lambda key: ','.join([p for p in scheme.get(key, getattr(s, key))])

def glue(key):
return ','.join([p for p in scheme.get(key, getattr(s, key))])

rand = ''.join(random.choice(string.ascii_lowercase) for x in range(5))

return {
Expand All @@ -72,9 +75,10 @@ def ulogin_widget(context, name="default"):
takes_context=True)(ulogin_widget)


def ulogin_media(context):
def ulogin_media(context, rand=None):
return {
'WIDGET_URL': s.WIDGET_URL,
'RAND': rand
}
register.inclusion_tag('django_ulogin/ulogin_media.html',
takes_context=True)(ulogin_media)
18 changes: 14 additions & 4 deletions django_ulogin/views.py
Original file line number Diff line number Diff line change
Expand Up @@ -17,6 +17,7 @@
import requests
import json
import logging
import sys


logger = logging.getLogger('django_ulogin.views')
Expand Down Expand Up @@ -149,10 +150,19 @@ def ulogin_response(self, token, host):
"""
Makes a request to ULOGIN
"""
return json.loads(requests.get(settings.TOKEN_URL, params={
'token': token,
'host': host
}).content)
response = requests.get(
settings.TOKEN_URL,
params={
'token': token,
'host': host
}
)
content = response.content

if sys.version_info >= (3, 0):
content = content.decode('utf8')

return json.loads(content)


class CrossDomainView(TemplateView):
Expand Down