From: Matías Aguirre Date: Sun, 14 Aug 2011 09:03:22 +0000 (-0300) Subject: Make use of context processors on example app. Refs gh-113 X-Git-Url: https://git.parisson.com/?a=commitdiff_plain;h=3c4e91829c95d44e4dca0841c5341fe4c29a7d88;p=django-social-auth.git Make use of context processors on example app. Refs gh-113 --- diff --git a/example/app/views.py b/example/app/views.py index 8033c23..c104662 100644 --- a/example/app/views.py +++ b/example/app/views.py @@ -6,7 +6,6 @@ from django.template import RequestContext from django.shortcuts import render_to_response from social_auth import __version__ as version -from social_auth.backends import BACKENDS, OpenIdAuth, BaseOAuth, BaseOAuth2 def home(request): @@ -14,18 +13,14 @@ def home(request): if request.user.is_authenticated(): return HttpResponseRedirect('done') else: - backends = grouped_backends() - return render_to_response('home.html', {'version': version, - 'backends': backends}, + return render_to_response('home.html', {'version': version}, RequestContext(request)) @login_required def done(request): """Login complete view, displays user data""" - ctx = {'accounts': request.user.social_auth.all(), - 'version': version, - 'last_login': request.session.get('social_auth_last_login_backend'), - 'backends': grouped_backends()} + ctx = {'version': version, + 'last_login': request.session.get('social_auth_last_login_backend')} return render_to_response('done.html', ctx, RequestContext(request)) def error(request): @@ -39,22 +34,3 @@ def logout(request): """Logs out user""" auth_logout(request) return HttpResponseRedirect('/') - - -def grouped_backends(): - """Group backends by type""" - backends = {'oauth': [], - 'oauth2': [], - 'openid': []} - - for name, backend in BACKENDS.iteritems(): - if issubclass(backend, BaseOAuth2): - key = 'oauth2' - elif issubclass(backend, BaseOAuth): - key = 'oauth' - elif issubclass(backend, OpenIdAuth): - key = 'openid' - else: - print name, backend - backends[key].append((name, backend)) - return backends diff --git a/example/settings.py b/example/settings.py index c55fdfb..93267df 100644 --- a/example/settings.py +++ b/example/settings.py @@ -74,6 +74,16 @@ AUTHENTICATION_BACKENDS = ( 'django.contrib.auth.backends.ModelBackend', ) +TEMPLATE_CONTEXT_PROCESSORS = ( + 'django.contrib.auth.context_processors.auth', + 'django.core.context_processors.debug', + 'django.core.context_processors.i18n', + 'django.core.context_processors.media', + 'django.core.context_processors.static', + 'django.contrib.messages.context_processors.messages', + 'social_auth.context_processors.social_auth_by_type_backends', +) + #SOCIAL_AUTH_ENABLED_BACKENDS = ('google', 'google-oauth', 'facebook') LOGIN_REDIRECT_URL = '/' diff --git a/example/templates/done.html b/example/templates/done.html index 1c99150..6b12fd9 100644 --- a/example/templates/done.html +++ b/example/templates/done.html @@ -16,59 +16,63 @@
-{% if accounts %} +{% if social_auth.associated %}

Disconnect accounts

{% endif %}

Associate new OAuth credentials:

Associate new OAuth2 credentials:

Associate new OpenId credentials:

diff --git a/example/templates/home.html b/example/templates/home.html index d72bc6b..1a39af4 100644 --- a/example/templates/home.html +++ b/example/templates/home.html @@ -6,7 +6,7 @@

Login using OAuth from:

@@ -15,7 +15,7 @@

Login using OAuth2 from:

    - {% for name, backend in backends.oauth2 %} + {% for name in social_auth.backends.oauth2 %}
  • {{ name|title }}
  • {% endfor %}
@@ -24,14 +24,12 @@

Login using OpenId from:

    - {% for name, backend in backends.openid %} - {% if name != "livejournal" and name != "openid" %} -
  • - {{ name|title }} -
  • - {% endif %} - {% endfor %} + {% for name in social_auth.backends.openid %}
  • + {% if name != "livejournal" and name != "openid" %} + {{ name|title }} + {% else %} + {% if name == "livejournal" %}
    {% csrf_token %}
    @@ -39,17 +37,21 @@
    + {% else %} + {% if name == "openid" %} +
    {% csrf_token %} +
    + + + +
    +

    Like your personal myopenid

    +
    + {% endif %} + {% endif %} + {% endif %}
  • -
  • -
    {% csrf_token %} -
    - - - -
    -

    Like your personal myopenid

    -
    -
  • + {% endfor %}
{% endblock %}