Add Oauth support (with django-social-auth)

This commit is contained in:
Yohan Boniface 2013-01-11 22:24:48 +01:00
parent 6346cddf2b
commit 1409f17979
10 changed files with 87 additions and 5 deletions

View file

@ -40,6 +40,23 @@ Add database connexion informations in `local.py`, for example::
}
}
uMap uses `django-social-auth <http://django-social-auth.readthedocs.org/>`_ for user authentication. So you will need to configure it according to your
needs. For example::
AUTHENTICATION_BACKENDS = (
'social_auth.backends.contrib.github.GithubBackend',
'social_auth.backends.contrib.bitbucket.BitbucketBackend',
'social_auth.backends.twitter.TwitterBackend',
'django.contrib.auth.backends.ModelBackend',
)
GITHUB_APP_ID = 'xxx'
GITHUB_API_SECRET = 'zzz'
BITBUCKET_CONSUMER_KEY = 'xxx'
BITBUCKET_CONSUMER_SECRET = 'zzz'
TWITTER_CONSUMER_KEY = "xxx"
TWITTER_CONSUMER_SECRET = "yyy"
Create the tables::
python manage.py syncdb --migrate
@ -56,4 +73,3 @@ Go to the admin (http://localhost:8000/admin/) and add:
- almost one licence
- almost one tilelayer
- maybe some users to play with

View file

@ -9,6 +9,7 @@ south
django-leaflet-storage
django_compressor
django-foundation
django-social-auth
git+git://github.com/yohanboniface/vectorformats.git@leafletstorage
git+git://github.com/frankban/django-endless-pagination.git
hg+https://bitbucket.org/liberation/sesql

View file

@ -3,6 +3,7 @@
"""Base settings shared by all environments"""
# Import global settings to make it easier to extend settings.
from django.conf.global_settings import * # pylint: disable=W0614,W0401
from django.template.defaultfilters import slugify
#==============================================================================
# Generic Django project settings
@ -34,6 +35,7 @@ INSTALLED_APPS = (
'umap',
'sesql',
'compressor',
'social_auth',
'south',
@ -113,6 +115,7 @@ TEMPLATE_DIRS = (
TEMPLATE_CONTEXT_PROCESSORS += (
'django.core.context_processors.request',
'social_auth.context_processors.social_auth_backends',
)
#==============================================================================
@ -139,3 +142,19 @@ AUTHENTICATION_BACKENDS += (
#==============================================================================
COMPRESS_ENABLED = True
COMPRESS_OFFLINE = True
SOCIAL_AUTH_ASSOCIATE_URL_NAME = "associate_complete"
SOCIAL_AUTH_DEFAULT_USERNAME = lambda u: slugify(u)
SOCIAL_AUTH_EXTRA_DATA = False
SOCIAL_AUTH_ASSOCIATE_BY_EMAIL = True
LOGIN_URL = "login"
SOCIAL_AUTH_LOGIN_REDIRECT_URL = "/login/popup/end/"
SOCIAL_AUTH_PIPELINE = (
'social_auth.backends.pipeline.social.social_auth_user',
'social_auth.backends.pipeline.associate.associate_by_email',
'social_auth.backends.pipeline.user.get_username',
'social_auth.backends.pipeline.user.create_user',
'social_auth.backends.pipeline.social.associate_user',
'social_auth.backends.pipeline.social.load_extra_data',
'social_auth.backends.pipeline.user.update_user_details'
)

Binary file not shown.

After

Width:  |  Height:  |  Size: 8.9 KiB

BIN
umap/static/umap/github.png Normal file

Binary file not shown.

After

Width:  |  Height:  |  Size: 1.5 KiB

Binary file not shown.

After

Width:  |  Height:  |  Size: 3.1 KiB

View file

@ -88,3 +88,31 @@ input:-moz-placeholder, :-moz-placeholder {
margin-right: 10px;
border: 1px solid #000;
}
/* **************** */
/* Login icons */
/* **************** */
/*.login-grid li {
}
*/
.login-grid a {
border: 1px solid #e5e5e5;
padding: 5px;
color: #000;
background-position: center bottom;
background-repeat: no-repeat;
background-size: 92px 92px;
height: 92px;
width: 92px;
display: inline-block;
margin-right: 10px;
}
.login-grid .login-github {
background-image: url("./github.png");
}
.login-grid .login-bitbucket {
background-image: url("./bitbucket.png");
}
.login-grid .login-twitter {
background-image: url("./twitter.png");
}

View file

@ -0,0 +1,14 @@
{% load i18n %}
{% load url from future %}
<h5>{% trans "Please choose a provider" %}</h5>
<div>
<ul class="login-grid block-grid">
{% for name in social_auth.backends %}
<li>
<a rel="nofollow" href="{% url "socialauth_begin" name %}" class="storage-login-popup login-{{ name }}" title="{{ name|title }}"></a>
</li>
{% endfor %}
</ul>
</div>

View file

@ -68,11 +68,14 @@
<strong>{% trans "Fork it" %}</strong>
</div>
</a>
<div class="panel">
<p>
{% trans "Users to play with" %} (password: <span class="label">123123</span>): {% for u in users %}<a href="{% url user_maps u.username %}">{{ u }}</a>{% if not forloop.last %}, {% endif %}{% endfor %}
</p>
{% if not user.is_authenticated %}
<a href="{% url login %}" class="login_button">
<div class="panel radius callout" align="center">
<strong>{% trans "Log in" %} / {% trans "Sign in" %}</strong>
</div>
</a>
{% endif %}
</div>

View file

@ -15,6 +15,7 @@ urlpatterns = patterns('',
url(r'^$', views.home, name="home"),
url(r'^search/$', views.search, name="search"),
url(r'^user/(?P<username>[-_\w]+)/$', views.user_maps, name='user_maps'),
url(r'', include('social_auth.urls')),
(r'', include('leaflet_storage.urls')),
)