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):
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
"""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):
"""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
</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>
<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>