Commit aacb65d1 authored by Michal Čihař's avatar Michal Čihař

Introduce login wrapper

- shows only reasonable login backends
- redirects logged in users to profile to manage identities
parent c950cb27
......@@ -73,13 +73,7 @@ urlpatterns = patterns(
name='registration_activate'
),
url(
r'^login/$',
auth_views.login,
{
'template_name': 'registration/login.html',
'extra_context': {'title': _('Login')},
},
name='auth_login'
r'^login/$', 'accounts.views.weblate_login', name='login',
),
url(
r'^logout/$',
......
......@@ -27,9 +27,13 @@ from django.contrib.auth.decorators import login_required
from django.core.mail.message import EmailMultiAlternatives
from django.utils import translation
from django.contrib.auth.models import User
from django.contrib.auth.views import login
from django.views.generic import TemplateView
from urllib import urlencode
from social.backends.utils import load_backends
from social.apps.django_app.utils import BACKENDS
from accounts.models import set_lang, Profile
from trans.models import Change, Project
from accounts.forms import (
......@@ -210,3 +214,24 @@ def user_page(request, user):
}
)
)
def weblate_login(request):
'''
Login handler, just wrapper around login.
'''
# Redirect logged in users to profile
if request.user.is_authenticated():
return redirect('profile')
return login(
request,
template_name='registration/login.html',
extra_context={
'login_backends': [
x for x in load_backends(BACKENDS).keys() if x != 'email'
],
'title': _('Login'),
}
)
......@@ -95,7 +95,7 @@ class SeleniumTests(LiveServerTestCase):
cls.driver.quit()
def test_login(self):
self.driver.get('%s%s' % (self.live_server_url, reverse('auth_login')))
self.driver.get('%s%s' % (self.live_server_url, reverse('login')))
username_input = self.driver.find_element_by_name('username')
username_input.send_keys("myuser")
......
......@@ -43,7 +43,7 @@
{% if registration_open %}
<li><a class="button" href="{% url 'registration_register' %}">{% trans "Register" %}</a></li>
{% endif %}
<li><a class="button" href="{% url 'auth_login' %}{% if not skip_next %}?next={{ current_url }}{% endif %}">{% trans "Login" %}</a></li>
<li><a class="button" href="{% url 'login' %}{% if not skip_next %}?next={{ current_url }}{% endif %}">{% trans "Login" %}</a></li>
{% endif %}
</ul>
......
......@@ -16,7 +16,7 @@
<h2>{% trans "Password log in" %}</h2>
<form method="post" action="{% url 'django.contrib.auth.views.login' %}">
<form method="post" action="{% url 'login' %}">
{% csrf_token %}
<table>
<tr>
......@@ -45,10 +45,14 @@
{% blocktrans %}Forgot your password? You can <a href="{{ reset_url }}">reset it</a>.{% endblocktrans %}
</p>
{% if login_backends %}
<h2>{% trans "Third party log in" %}</h2>
{% for name in backends.not_associated %}
{% for name in login_backends %}
<a class="button" href="{% url 'social:begin' name %}?next={% url 'profile' %}">{{ name }}</a>
{% endfor %}
{% endif %}
{% endblock %}
......@@ -6,7 +6,7 @@
<p>{% blocktrans %}Thanks for using Weblate!{% endblocktrans %}</p>
<p><a href="{% url 'django.contrib.auth.views.login' %}">{% trans "Log in again" %}</a></p>
<p><a href="{% url 'login' %}">{% trans "Log in again" %}</a></p>
{% endblock %}
......@@ -154,7 +154,7 @@
{% if perms.trans.save_translation %}
<input class="button" type="submit" value="{% trans "Save" %}" name="save" tabindex="150" {% if locked %}disabled="disabled"{% endif %} />
{% else %}
{% url 'django.contrib.auth.views.login' as login_url %}
{% url 'login' as login_url %}
{% with unit.translation.get_translate_url as translate_url %}
{% blocktrans %}<a href="{{ login_url }}?next={{ translate_url }}">Log in</a> for saving translations.{% endblocktrans %}
{% endwith %}
......
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