]> git.parisson.com Git - django-social-auth.git/commitdiff
Dynamic backend list on example app
authorMatías Aguirre <matiasaguirre@gmail.com>
Sun, 3 Jul 2011 20:43:53 +0000 (17:43 -0300)
committerMatías Aguirre <matiasaguirre@gmail.com>
Sun, 3 Jul 2011 20:43:53 +0000 (17:43 -0300)
example/app/views.py
example/templates/done.html
example/templates/home.html

index 2e17cd620c3ebf8ad2fdc8d8174d215eff7c44cc..8033c23b4ff34f9b87e74db32e825b831b25af0a 100644 (file)
@@ -6,6 +6,7 @@ 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):
@@ -13,7 +14,9 @@ def home(request):
     if request.user.is_authenticated():
         return HttpResponseRedirect('done')
     else:
-        return render_to_response('home.html', {'version': version},
+        backends = grouped_backends()
+        return render_to_response('home.html', {'version': version,
+                                                'backends': backends},
                                   RequestContext(request))
 
 @login_required
@@ -21,7 +24,8 @@ 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')}
+           'last_login': request.session.get('social_auth_last_login_backend'),
+           'backends': grouped_backends()}
     return render_to_response('done.html', ctx, RequestContext(request))
 
 def error(request):
@@ -35,3 +39,22 @@ 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 74e2c34a3b8bf024f3dccac99a560fce6f8d5908..1c99150ee04687cc7521c7e99309f35279aef038 100644 (file)
   </ul>
 {% endif %}
 
-  <h3>Associate new OAuth credentials:</h3>
+  <h3>Associate new <a href="http://oauth.net/" title="OAuth">OAuth</a> credentials:</h3>
   <ul>
-    <li>
-      <a rel="nofollow" href="{% url socialauth_associate_begin "twitter" %}">Twitter</a>
-    </li>
-    <li>
-      <a rel="nofollow" href="{% url socialauth_associate_begin "facebook" %}">Facebook</a>
-    </li>
-    <li>
-      <a rel="nofollow" href="{% url socialauth_associate_begin "linkedin" %}">LinkedIn</a>
-    </li>
-    <li>
-      <a rel="nofollow" href="{% url socialauth_associate_begin "orkut" %}">Orkut</a>
-    </li>
-    <li>
-      <a rel="nofollow" href="{% url socialauth_associate_begin "google-oauth" %}">Google OAuth</a>
-    </li>
+  {% for name, backend in backends.oauth %}
+    <li><a rel="nofollow" href="{% url socialauth_associate_begin name %}">{{ name|title }}</a></li>
+  {% endfor %}
   </ul>
 
-  <h3>Associate new OAuth2 credentials:</h3>
+  <h3>Associate new <a href="http://tools.ietf.org/html/draft-ietf-oauth-v2-10" title="OAuth2">OAuth2</a> credentials:</h3>
   <ul>
-    <li>
-      <a rel="nofollow" href="{% url socialauth_associate_begin "google-oauth2" %}">Google OAuth2</a>
-    </li>
-    <li>
-      <a rel="nofollow" href="{% url socialauth_associate_begin "foursquare" %}">Foursquare</a>
-    </li>
+  {% for name, backend in backends.oauth2 %}
+    <li><a rel="nofollow" href="{% url socialauth_associate_begin name %}">{{ name|title }}</a></li>
+  {% endfor %}
   </ul>
 
-  <h3>Associate new OpenID credentials:</h3>
+  <h3>Associate new <a href="http://openid.net/" title="OpenId">OpenId</a> credentials:</h3>
   <ul>
-    <li>
-      <a rel="nofollow" href="{% url socialauth_associate_begin "google" %}">Google OpenID</a>
-    </li>
-    <li>
-      <a rel="nofollow" href="{% url socialauth_associate_begin "yahoo" %}">Yahoo</a>
-    </li>
+    {% 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 %}
     <li>
       <form action="{% url socialauth_associate_begin "livejournal" %}" method="post">{% csrf_token %}
         <div>
index 14b0edf38102a9112842e02448a02e1b999bbc06..d72bc6be094f978c09f4014e67c3c7ca2003c9b1 100644 (file)
@@ -6,27 +6,31 @@
 <div>
   <h3>Login using <a href="http://oauth.net/" title="OAuth">OAuth</a> from:</h3>
   <ul>
-    <li><a rel="nofollow" href="{% url socialauth_begin "twitter" %}">Twitter</a></li>
-    <li><a rel="nofollow" href="{% url socialauth_begin "facebook" %}">Facebook</a></li>
-    <li><a rel="nofollow" href="{% url socialauth_begin "linkedin" %}">Linkedin</a></li>
-    <li><a rel="nofollow" href="{% url socialauth_begin "orkut" %}">Orkut</a></li>
-    <li><a rel="nofollow" href="{% url socialauth_begin "google-oauth" %}">Google OAuth</a></li>
+  {% for name, backend in backends.oauth %}
+    <li><a rel="nofollow" href="{% url socialauth_begin name %}">{{ name|title }}</a></li>
+  {% endfor %}
   </ul>
 </div>
 
 <div>
   <h3>Login using <a href="http://tools.ietf.org/html/draft-ietf-oauth-v2-10" title="OAuth2">OAuth2</a> from:</h3>
   <ul>
-    <li><a rel="nofollow" href="{% url socialauth_begin "google-oauth2" %}">Google OAuth2</a></li>
-    <li><a rel="nofollow" href="{% url socialauth_begin "foursquare" %}">Foursquare</a></li>
+  {% for name, backend in backends.oauth2 %}
+    <li><a rel="nofollow" href="{% url socialauth_begin name %}">{{ name|title }}</a></li>
+  {% endfor %}
   </ul>
 </div>
 
 <div>
   <h3>Login using <a href="http://openid.net/" title="OpenId">OpenId</a> from:</h3>
   <ul>
-    <li><a rel="nofollow" href="{% url socialauth_begin "google" %}">Google</a></li>
-    <li><a rel="nofollow" href="{% url socialauth_begin "yahoo" %}">Yahoo</a></li>
+    {% 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 %}
     <li>
       <form action="{% url socialauth_begin "livejournal" %}" method="post">{% csrf_token %}
         <div>