From e3707c5b5326468a75ee8d983ff77fded1995d83 Mon Sep 17 00:00:00 2001 From: Aurélien Bompard Date: Fri, 26 Apr 2013 18:59:42 +0200 Subject: Autodetect the enabled authentication backends --- hyperkitty/views/accounts.py | 18 +++++++++++++++++- 1 file changed, 17 insertions(+), 1 deletion(-) (limited to 'hyperkitty/views/accounts.py') 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(): -- cgit