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:
- 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):
"""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
'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 = '/'
</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>
<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>
<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 %}