]> git.parisson.com Git - django-social-auth.git/commitdiff
Make use of context processors on example app. Refs gh-113
authorMatías Aguirre <matiasaguirre@gmail.com>
Sun, 14 Aug 2011 09:03:22 +0000 (06:03 -0300)
committerMatías Aguirre <matiasaguirre@gmail.com>
Sun, 14 Aug 2011 09:03:22 +0000 (06:03 -0300)
example/app/views.py
example/settings.py
example/templates/done.html
example/templates/home.html

index 8033c23b4ff34f9b87e74db32e825b831b25af0a..c1046621bf3cfc564916f358bcf629832317b7fc 100644 (file)
@@ -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
index c55fdfbc1283d06dd6e198cc744ae1b0dbb80bbe..93267dfa4aef73ffcdece7f12f34ba7289eaf364 100644 (file)
@@ -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 = '/'
index 1c99150ee04687cc7521c7e99309f35279aef038..6b12fd974c265a8ce47a46ee255592d327f83910 100644 (file)
 </div>
 
 <div>
-{% if accounts %}
+{% if social_auth.associated %}
   <h3>Disconnect accounts</h3>
   <ul>
-  {% for account in accounts %}
+  {% for type, accounts in social_auth.associated.items %}
+    {% for account in accounts %}
     <li>
         <span class="disconnect"><a href={% url socialauth_disconnect_individual account.provider account.id %}>{{ account.provider|title }} (ID {{ account.id }})</a></span>
     </li>
+    {% endfor %}
   {% endfor %}
   </ul>
 {% endif %}
 
   <h3>Associate new <a href="http://oauth.net/" title="OAuth">OAuth</a> credentials:</h3>
   <ul>
-  {% for name, backend in backends.oauth %}
+  {% for name in social_auth.backends.oauth %}
     <li><a rel="nofollow" href="{% url socialauth_associate_begin name %}">{{ name|title }}</a></li>
   {% endfor %}
   </ul>
 
   <h3>Associate new <a href="http://tools.ietf.org/html/draft-ietf-oauth-v2-10" title="OAuth2">OAuth2</a> credentials:</h3>
   <ul>
-  {% for name, backend in backends.oauth2 %}
+  {% for name in social_auth.backends.oauth2 %}
     <li><a rel="nofollow" href="{% url socialauth_associate_begin name %}">{{ name|title }}</a></li>
   {% endfor %}
   </ul>
 
   <h3>Associate new <a href="http://openid.net/" title="OpenId">OpenId</a> credentials:</h3>
   <ul>
-    {% for name, backend in backends.openid %}
-      {% if name != "livejournal" and name != "openid" %}
-      <li>
-        <a rel="nofollow" href="{% url socialauth_begin name %}">{{ name|title }}</a>
-      </li>
-      {% endif %}
-    {% endfor %}
+  {% for name in social_auth.backends.openid %}
     <li>
+    {% if name != "livejournal" and name != "openid" %}
+      <a rel="nofollow" href="{% url socialauth_associate_begin name %}">{{ name|title }}</a>
+    {% else %}
+      {% if name == "livejournal" %}
       <form action="{% url socialauth_associate_begin "livejournal" %}" method="post">{% csrf_token %}
         <div>
-          <label for="openid_lj_user">LiveJournal user
-          </label>
+          <label for="openid_lj_user">LiveJournal user:</label>
           <input id="openid_lj_user" type="text" value="" name="openid_lj_user" />
           <input type="submit" value="Login"/>
         </div>
       </form>
+      {% else %}
+        {% if name == "openid" %}
+        <form action="{% url socialauth_associate_begin "openid" %}" method="post">{% csrf_token %}
+          <div>
+            <label for="openid_identifier">Other provider</label>
+            <input id="openid_identifier" type="text" value="" name="openid_identifier" />
+            <input type="submit" value="Login" />
+          </div>
+          <p class="helptext">Like your personal <a href="https://www.myopenid.com/" title="My OpenId">myopenid</a></p>
+        </form>
+        {% endif %}
+      {% endif %}
+    {% endif %}
     </li>
-    <li>
-      <form action="{% url socialauth_associate_begin "openid" %}" method="post">{% csrf_token %}
-        <div>
-          <label for="openid_identifier">Other provider:</label>
-          <input id="openid_identifier" type="text" value="" name="openid_identifier" />
-          <input type="submit" />
-        </div>
-      </form>
-    </li>
+  {% endfor %}
   </ul>
 </div>
 
index d72bc6be094f978c09f4014e67c3c7ca2003c9b1..1a39af4d174451fd76c850026717ee91e2afcbc9 100644 (file)
@@ -6,7 +6,7 @@
 <div>
   <h3>Login using <a href="http://oauth.net/" title="OAuth">OAuth</a> from:</h3>
   <ul>
-  {% for name, backend in backends.oauth %}
+  {% for name in social_auth.backends.oauth %}
     <li><a rel="nofollow" href="{% url socialauth_begin name %}">{{ name|title }}</a></li>
   {% endfor %}
   </ul>
@@ -15,7 +15,7 @@
 <div>
   <h3>Login using <a href="http://tools.ietf.org/html/draft-ietf-oauth-v2-10" title="OAuth2">OAuth2</a> from:</h3>
   <ul>
-  {% for name, backend in backends.oauth2 %}
+  {% for name in social_auth.backends.oauth2 %}
     <li><a rel="nofollow" href="{% url socialauth_begin name %}">{{ name|title }}</a></li>
   {% endfor %}
   </ul>
 <div>
   <h3>Login using <a href="http://openid.net/" title="OpenId">OpenId</a> from:</h3>
   <ul>
-    {% for name, backend in backends.openid %}
-      {% if name != "livejournal" and name != "openid" %}
-      <li>
-        <a rel="nofollow" href="{% url socialauth_begin name %}">{{ name|title }}</a>
-      </li>
-      {% endif %}
-    {% endfor %}
+  {% for name in social_auth.backends.openid %}
     <li>
+    {% if name != "livejournal" and name != "openid" %}
+      <a rel="nofollow" href="{% url socialauth_begin name %}">{{ name|title }}</a>
+    {% else %}
+      {% if name == "livejournal" %}
       <form action="{% url socialauth_begin "livejournal" %}" method="post">{% csrf_token %}
         <div>
           <label for="openid_lj_user">LiveJournal user:</label>
           <input type="submit" value="Login"/>
         </div>
       </form>
+      {% else %}
+        {% if name == "openid" %}
+        <form action="{% url socialauth_begin "openid" %}" method="post">{% csrf_token %}
+          <div>
+            <label for="openid_identifier">Other provider</label>
+            <input id="openid_identifier" type="text" value="" name="openid_identifier" />
+            <input type="submit" value="Login" />
+          </div>
+          <p class="helptext">Like your personal <a href="https://www.myopenid.com/" title="My OpenId">myopenid</a></p>
+        </form>
+        {% endif %}
+      {% endif %}
+    {% endif %}
     </li>
-    <li>
-      <form action="{% url socialauth_begin "openid" %}" method="post">{% csrf_token %}
-        <div>
-          <label for="openid_identifier">Other provider</label>
-          <input id="openid_identifier" type="text" value="" name="openid_identifier" />
-          <input type="submit" value="Login" />
-        </div>
-        <p class="helptext">Like your personal <a href="https://www.myopenid.com/" title="My OpenId">myopenid</a></p>
-      </form>
-    </li>
+  {% endfor %}
   </ul>
 </div>
 {% endblock %}