summaryrefslogtreecommitdiffstats
diff options
context:
space:
mode:
-rw-r--r--hyperkitty/templates/login.html57
-rw-r--r--hyperkitty/urls.py3
-rw-r--r--hyperkitty/views/accounts.py18
3 files changed, 52 insertions, 26 deletions
diff --git a/hyperkitty/templates/login.html b/hyperkitty/templates/login.html
index 4a27031..fb82c44 100644
--- a/hyperkitty/templates/login.html
+++ b/hyperkitty/templates/login.html
@@ -15,36 +15,45 @@
<h2>Login with your email</h2>
<ul class="social-login inline">
- <li class="browserid">
- <form method="post" action="{% url 'socialauth_complete' "browserid" %}?next={{ next }}">
- {% csrf_token %}
- <input type="hidden" name="assertion" value="" />
- <a rel="nofollow" id="browserid" href="#" class="disabled"><img src="{{ STATIC_URL }}img/login/persona-large-disabled.png" alt="Login using Persona" /></a>
- </form>
- </li>
-
- <li><a title="Google" class="socialaccount_provider google" href="{% url 'socialauth_begin' backend='google' %}?next={{ next }}"><img src="{{ STATIC_URL }}img/login/google.png" alt="Google" /></a></li>
-
- <li><a title="Yahoo" class="socialaccount_provider yahoo" href="{% url 'socialauth_begin' backend='yahoo' %}?next={{ next }}"><img src="{{ STATIC_URL }}img/login/yahoo.png" alt="Yahoo" /></a></li>
-
- <li><a title="Fedora" class="socialaccount_provider fedora" href="{% url 'socialauth_begin' backend='fedora' %}?next={{ next }}"><img src="{{ STATIC_URL }}img/login/fedora.png" alt="Fedora" /></a></li>
-
- <li><a class="socialaccount_provider openid" href="#"><img src="{{ STATIC_URL }}img/login/openid.png" alt="OpenID" /></a>
- <form method="post" action="{% url 'socialauth_begin' "openid" %}?next={{ next }}" class="form-inline openid">
- {% csrf_token %}
- <div class="input-append">
- <input type="text" class="input-large" name="openid_identifier" placeholder="OpenID URL" />
- <button type="submit" class="btn">Login with OpenID</button>
- </div>
- </form>
- </li>
+ {% for backend in backends %}
+ <li class="{{ backend }}">
+ {% if backend == "browserid" %}
+ <form method="post"
+ action="{% url 'socialauth_complete' "browserid" %}?next={{ next }}">
+ {% csrf_token %}
+ <input type="hidden" name="assertion" value="" />
+ <a rel="nofollow" id="browserid" href="#" class="disabled"><img
+ src="{{ STATIC_URL }}img/login/persona-large-disabled.png"
+ alt="Login using Persona" /></a>
+ </form>
+ {% elif backend == "openid" %}
+ <a class="socialaccount_provider openid" title="OpenID" href="#"><img
+ src="{{ STATIC_URL }}img/login/openid.png" alt="OpenID" /></a>
+ <form method="post" class="form-inline openid"
+ action="{% url 'socialauth_begin' "openid" %}?next={{ next }}">
+ {% csrf_token %}
+ <div class="input-append">
+ <input type="text" class="input-large" name="openid_identifier"
+ placeholder="OpenID URL" />
+ <button type="submit" class="btn">Login with OpenID</button>
+ </div>
+ </form>
+ {% else %}
+ <a title="{{ backend|title }}" class="socialaccount_provider {{ backend }}"
+ href="{% url 'socialauth_begin' backend=backend %}?next={{ next }}"><img
+ src="{{ STATIC_URL }}img/login/{{ backend }}.png"
+ alt="{{ backend|title }}" /></a>
+ {% endif %}
+ </li>
+ {% endfor %}
</ul>
{% if use_internal_auth %}
<h2>Login with username and password</h2>
-<form action="{{ request.path }}?next={{ next|urlencode }}" method="post" class="form-horizontal">
+<form action="{{ request.path }}?next={{ next|urlencode }}"
+ method="post" class="form-horizontal">
{% csrf_token %}
{{ form|crispy }}
<div class="control-group">
diff --git a/hyperkitty/urls.py b/hyperkitty/urls.py
index 1a2e945..2ec92c9 100644
--- a/hyperkitty/urls.py
+++ b/hyperkitty/urls.py
@@ -43,7 +43,8 @@ urlpatterns = patterns('hyperkitty.views',
url(r'^$', 'pages.index', name='root'),
# Account
- url(r'^accounts/login/$', login_view, {'template_name': 'login.html', 'SSL': True}, name='user_login'),
+ #url(r'^accounts/login/$', login_view, {'template_name': 'login.html', 'SSL': True}, name='user_login'),
+ url(r'^accounts/login/$', 'accounts.login_view', {'template_name': 'login.html', 'SSL': True}, name='user_login'),
url(r'^accounts/logout/$', logout_view, {'next_page': '/'}, name='user_logout'),
url(r'^accounts/profile/$', 'accounts.user_profile', name='user_profile'),
url(r'^accounts/register/$', 'accounts.user_registration', {'SSL': True}, name='user_registration'),
diff --git a/hyperkitty/views/accounts.py b/hyperkitty/views/accounts.py
index 8e5dc03..284eb15 100644
--- a/hyperkitty/views/accounts.py
+++ b/hyperkitty/views/accounts.py
@@ -24,12 +24,14 @@ import logging
from django.conf import settings
from django.core.urlresolvers import reverse
from django.core.exceptions import SuspiciousOperation
-from django.contrib.auth import logout, authenticate, login
+from django.contrib.auth import logout, authenticate, login, get_backends
from django.contrib.auth.decorators import login_required
from django.contrib.auth.models import User
+from django.contrib.auth.views import login as django_login_view
from django.shortcuts import render, redirect
from django.utils.http import is_safe_url
from django.utils.translation import gettext as _
+from social_auth.backends import SocialAuthBackend
from hyperkitty.models import UserProfile, Rating, Favorite
from hyperkitty.views.forms import RegistrationForm, UserProfileForm
@@ -44,6 +46,20 @@ FLASH_MESSAGES = {
}
+def login_view(request, *args, **kwargs):
+ if "extra_context" not in kwargs:
+ kwargs["extra_context"] = {}
+ if "backends" not in kwargs["extra_context"]:
+ kwargs["extra_context"]["backends"] = []
+ # Note: sorry but I really find the .setdefault() method non-obvious and
+ # harder to re-read that the lines above.
+ for backend in get_backends():
+ if not isinstance(backend, SocialAuthBackend):
+ continue # It should be checked using duck-typing instead
+ kwargs["extra_context"]["backends"].append(backend.name)
+ return django_login_view(request, *args, **kwargs)
+
+
@login_required
def user_profile(request, user_email=None):
if not request.user.is_authenticated():