Last active
December 28, 2015 10:19
-
-
Save nikolaygit/7485797 to your computer and use it in GitHub Desktop.
Add python_social_auth in a Django project Created with the help of http://psa.matiasaguirre.net/docs/configuration/django.html#django-framework and https://github.com/omab/python-social-auth/tree/master/examples/django_example
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
{% load url from future %} | |
{% block content %} | |
<p>You are logged in as {{ user.username }}!</p> | |
{% endblock %} |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
{% 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 %} |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
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/' |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
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')), | |
... | |
) |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
# -*- 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