summaryrefslogtreecommitdiffstats
path: root/hyperkitty/views/accounts.py
diff options
context:
space:
mode:
authorAurélien Bompard <aurelien@bompard.org>2013-04-26 18:59:42 +0200
committerAurélien Bompard <aurelien@bompard.org>2013-04-26 18:59:42 +0200
commite3707c5b5326468a75ee8d983ff77fded1995d83 (patch)
treea32f5e03a0a142738f9d1d1db58a3edfcb2d9521 /hyperkitty/views/accounts.py
parentbf0271104e16ae44aac6d6393f98bc9f60e5ca4d (diff)
downloadhyperkitty-e3707c5b5326468a75ee8d983ff77fded1995d83.tar.gz
hyperkitty-e3707c5b5326468a75ee8d983ff77fded1995d83.tar.xz
hyperkitty-e3707c5b5326468a75ee8d983ff77fded1995d83.zip
Autodetect the enabled authentication backends
Diffstat (limited to 'hyperkitty/views/accounts.py')
-rw-r--r--hyperkitty/views/accounts.py18
1 files changed, 17 insertions, 1 deletions
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():