Commit 6894110c by James Henstridge

Move the OPENID_USE_AS_ADMIN_LOGIN code to django_openid_auth.admin so

it only gets imported if the application is actually using 
django.contrib.admin.
parent 5bc9cb7a
...@@ -2,7 +2,6 @@ ...@@ -2,7 +2,6 @@
# #
# Copyright (C) 2007 Simon Willison # Copyright (C) 2007 Simon Willison
# Copyright (C) 2008-2009 Canonical Ltd. # Copyright (C) 2008-2009 Canonical Ltd.
# Copyright (C) 2010 Dave Walker
# #
# Redistribution and use in source and binary forms, with or without # Redistribution and use in source and binary forms, with or without
# modification, are permitted provided that the following conditions # modification, are permitted provided that the following conditions
...@@ -28,25 +27,3 @@ ...@@ -28,25 +27,3 @@
# ANY WAY OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE # ANY WAY OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE
# POSSIBILITY OF SUCH DAMAGE. # POSSIBILITY OF SUCH DAMAGE.
""" Support for allowing openid authentication for /admin (django.contrib.admin) """
from django.conf import settings
if getattr(settings, 'OPENID_USE_AS_ADMIN_LOGIN', False):
from django.http import HttpResponseRedirect
from django.contrib.admin import sites
from django_openid_auth import views
def _openid_login(self, request, error_message='', extra_context=None):
if request.user.is_authenticated():
if not request.user.is_staff:
return views.render_failure(request, "User %s does not have admin access."
% request.user.username)
return views.render_failure(request, "Unknown Error: %s" % error_message)
else:
# Redirect to openid login path,
return HttpResponseRedirect(settings.LOGIN_URL+"?next="+request.get_full_path())
# Overide the standard admin login form.
sites.AdminSite.display_login_form = _openid_login
# django-openid-auth - OpenID integration for django.contrib.auth # django-openid-auth - OpenID integration for django.contrib.auth
# #
# Copyright (C) 2008-2009 Canonical Ltd. # Copyright (C) 2008-2009 Canonical Ltd.
# Copyright (C) 2010 Dave Walker
# #
# Redistribution and use in source and binary forms, with or without # Redistribution and use in source and binary forms, with or without
# modification, are permitted provided that the following conditions # modification, are permitted provided that the following conditions
...@@ -26,6 +27,7 @@ ...@@ -26,6 +27,7 @@
# ANY WAY OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE # ANY WAY OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE
# POSSIBILITY OF SUCH DAMAGE. # POSSIBILITY OF SUCH DAMAGE.
from django.conf import settings
from django.contrib import admin from django.contrib import admin
from django_openid_auth.models import Nonce, Association, UserOpenID from django_openid_auth.models import Nonce, Association, UserOpenID
from django_openid_auth.store import DjangoOpenIDStore from django_openid_auth.store import DjangoOpenIDStore
...@@ -64,3 +66,25 @@ class UserOpenIDAdmin(admin.ModelAdmin): ...@@ -64,3 +66,25 @@ class UserOpenIDAdmin(admin.ModelAdmin):
search_fields = ('claimed_id',) search_fields = ('claimed_id',)
admin.site.register(UserOpenID, UserOpenIDAdmin) admin.site.register(UserOpenID, UserOpenIDAdmin)
# Support for allowing openid authentication for /admin (django.contrib.admin)
if getattr(settings, 'OPENID_USE_AS_ADMIN_LOGIN', False):
from django.http import HttpResponseRedirect
from django_openid_auth import views
def _openid_login(self, request, error_message='', extra_context=None):
if request.user.is_authenticated():
if not request.user.is_staff:
return views.render_failure(
request, "User %s does not have admin access."
% request.user.username)
return views.render_failure(
request, "Unknown Error: %s" % error_message)
else:
# Redirect to openid login path,
return HttpResponseRedirect(
settings.LOGIN_URL + "?next=" + request.get_full_path())
# Overide the standard admin login form.
admin.sites.AdminSite.display_login_form = _openid_login
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