Skip to content

Instantly share code, notes, and snippets.

@nikolaygit
Last active December 28, 2015 10:19
Show Gist options
  • Save nikolaygit/7485797 to your computer and use it in GitHub Desktop.
Save nikolaygit/7485797 to your computer and use it in GitHub Desktop.
{% load url from future %}
{% block content %}
<p>You are logged in as {{ user.username }}!</p>
{% endblock %}
{% load url from future %}
{% block content %}
<a href="{% url 'social:begin' "google" %}">Google OpenId</a> <br />
<form action="{% url 'social:begin' "openid" %}" method="post">{% csrf_token %}
<div>
<label for="openid_identifier">OpenId provider</label>
<input id="openid_identifier" type="text" value="" name="openid_identifier" />
<input type="submit" value="Login" />
</div>
</form>
{% endblock %}
INSTALLED_APPS = (
...
'social.apps.django_app.default',
...
)
TEMPLATE_CONTEXT_PROCESSORS = (
...
# app: social.apps.django_app.default
'social.apps.django_app.context_processors.backends',
'social.apps.django_app.context_processors.login_redirect',
)
# app: social.apps.django_app.default
AUTHENTICATION_BACKENDS = (
'social.backends.open_id.OpenIdAuth',
'social.backends.google.GoogleOpenId',
'django.contrib.auth.backends.ModelBackend'
)
SOCIAL_AUTH_LOGIN_URL = '/login/'
LOGIN_URL = '/login/'
LOGIN_REDIRECT_URL = '/done/'
urlpatterns = patterns('',
...
# app: social.apps.django_app.default
url(r'^$', 'yourapp.views.home'),
url(r'^login/$', 'yourapp.views.home'),
url(r'^done/$', TemplateView.as_view(template_name="done.html"), name='done'),
url(r'^', include('social.apps.django_app.urls', namespace='social')),
...
)
# -*- coding: utf-8 -*-
from django.template import RequestContext
from django.shortcuts import render_to_response, redirect
from django.contrib.auth.decorators import login_required
def home(request):
"""Home view, displays login mechanism"""
if request.user.is_authenticated():
return redirect('done')
return render_to_response('home.html', {}, RequestContext(request))
@login_required
def done(request):
"""Login complete view, displays user data"""
return render_to_response('done.html', {
'user': request.user,
}, RequestContext(request))
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment