Commit 26dc726f authored by Michal Čihař's avatar Michal Čihař

Initial support for social authentication

Right now only basic login works and is not really integrated into rest
of Weblate.

Issue #170
parent acb227ca
......@@ -5,6 +5,7 @@ locale/*/*/*.mo
/weblate/whoosh-index/
weblate-*.tar.*
/translate
/social
/*.db
/weblate/settings.py
/weblate/test-repos/
......
# -*- coding: utf-8 -*-
#
# Copyright © 2012 - 2013 Michal Čihař <michal@cihar.com>
#
# This file is part of Weblate <http://weblate.org/>
#
# This program is free software: you can redistribute it and/or modify
# it under the terms of the GNU General Public License as published by
# the Free Software Foundation, either version 3 of the License, or
# (at your option) any later version.
#
# This program is distributed in the hope that it will be useful,
# but WITHOUT ANY WARRANTY; without even the implied warranty of
# MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
# GNU General Public License for more details.
#
# You should have received a copy of the GNU General Public License
# along with this program. If not, see <http://www.gnu.org/licenses/>.
#
from django.shortcuts import redirect
from social.pipeline.partial import partial
@partial
def require_email(strategy, details, user=None, is_new=False,
*args, **kwargs):
if user and user.email:
return
elif is_new and not details.get('email'):
if strategy.session_get('saved_email'):
details['email'] = strategy.session_pop('saved_email')
else:
return redirect('require_email')
......@@ -18,7 +18,7 @@
# along with this program. If not, see <http://www.gnu.org/licenses/>.
#
from django.conf.urls import patterns, url
from django.conf.urls import patterns, url, include
from django.utils.translation import ugettext_lazy as _
from django.contrib.auth import views as auth_views
from django.conf import settings
......@@ -131,4 +131,5 @@ urlpatterns = patterns(
'accounts.views.user_profile',
name='profile',
),
url(r'', include('social.apps.django_app.urls', namespace='social')),
)
......@@ -16,6 +16,8 @@ GitPython (>= 0.3.2)
https://github.com/gitpython-developers/GitPython
Git (>= 1.0)
http://git-scm.com/
python-social-auth (>= 0.1)
http://psa.matiasaguirre.net/
Django-registration (= 0.8, 0.9 or newer are not supported)
https://bitbucket.org/ubernostrum/django-registration/
Whoosh (>= 2.5, 2.5.2 is recommended)
......
......@@ -103,6 +103,16 @@ def get_versions():
'0.8',
))
name = 'python-social-auth'
url = 'http://psa.matiasaguirre.net/'
mod = get_version_module('social', name, url)
result.append((
name,
url,
mod.__version__,
'0.1',
))
name = 'Translate Toolkit'
url = 'http://toolkit.translatehouse.org/'
mod = get_version_module('translate', name, url)
......
......@@ -43,4 +43,13 @@
{% blocktrans %}Forgot your password? You can <a href="{{ reset_url }}">reset it</a>.{% endblocktrans %}
</p>
<ul>
{% for name in backends.not_associated %}
<li>
<a href="{% url 'social:begin' name %}">{{ name }}</a>
</li>
{% endfor %}
</ul>
{% endblock %}
......@@ -167,9 +167,32 @@ TEMPLATE_LOADERS = (
# Authentication configuration
AUTHENTICATION_BACKENDS = (
'social.backends.google.GoogleOpenId',
#'social.backends.github.GithubOAuth2',
#'social.backends.open_id.OpenIdAuth',
'accounts.auth.AnonymousUserBackend',
)
# Social auth backends setup
SOCIAL_AUTH_GITHUB_KEY = ''
SOCIAL_AUTH_GITHUB_SECRET = ''
SOCIAL_AUTH_GITHUB_SCOPE = ['user:email']
# Social auth settings
SOCIAL_AUTH_PIPELINE = (
'social.pipeline.social_auth.social_details',
'social.pipeline.social_auth.social_uid',
'social.pipeline.social_auth.auth_allowed',
'social.pipeline.social_auth.social_user',
'social.pipeline.user.get_username',
'accounts.pipeline.require_email',
'social.pipeline.mail.mail_validation',
'social.pipeline.user.create_user',
'social.pipeline.social_auth.associate_user',
'social.pipeline.social_auth.load_extra_data',
'social.pipeline.user.user_details'
)
# Middleware
MIDDLEWARE_CLASSES = (
'django.middleware.common.CommonMiddleware',
......@@ -201,6 +224,7 @@ INSTALLED_APPS = (
'django.contrib.admin',
'django.contrib.admindocs',
'django.contrib.sitemaps',
'social.apps.django_app.default',
'registration',
'south',
'trans',
......@@ -221,6 +245,7 @@ TEMPLATE_CONTEXT_PROCESSORS = (
'django.core.context_processors.request',
'django.core.context_processors.csrf',
'django.contrib.messages.context_processors.messages',
'social.apps.django_app.context_processors.backends',
'trans.context_processors.weblate_context',
)
......
Markdown is supported
0%
or
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment