Commit 8eab59f1 by Michael Hall

Cleanup exception class heirarchy and imports, make overriding the login failure…

Cleanup exception class heirarchy and imports, make overriding the login failure handler a settings option, add additional test cases to veryfiy that overriding the handler works and that the proper exceptions are being passed
parent 57955026
...@@ -154,3 +154,15 @@ If your users should use a physical multi-factor authentication method, such as ...@@ -154,3 +154,15 @@ If your users should use a physical multi-factor authentication method, such as
If the user's OpenID provider supports the PAPE extension and provides the Physical Multifactor authentication policy, this will If the user's OpenID provider supports the PAPE extension and provides the Physical Multifactor authentication policy, this will
cause the OpenID login to fail if the user does not provide valid physical authentication to the provider. cause the OpenID login to fail if the user does not provide valid physical authentication to the provider.
== Override Login Failure Handling ==
You can optionally provide your own handler for login failures by adding the following setting:
OPENID_RENDER_FAILURE = failure_handler_function
Where failure_handler_function is a function reference that will take the following parameters:
def failure_handler_function(request, message, status=None, template_name=None, exception=None)
This function must return a Django.http.HttpResponse instance.
...@@ -38,7 +38,6 @@ from openid.extensions import ax, sreg, pape ...@@ -38,7 +38,6 @@ from openid.extensions import ax, sreg, pape
from django_openid_auth import teams from django_openid_auth import teams
from django_openid_auth.models import UserOpenID from django_openid_auth.models import UserOpenID
from django_openid_auth.exceptions import ( from django_openid_auth.exceptions import (
DjangoOpenIDException,
IdentityAlreadyClaimed, IdentityAlreadyClaimed,
DuplicateUsernameViolation, DuplicateUsernameViolation,
MissingUsernameViolation, MissingUsernameViolation,
......
...@@ -39,10 +39,7 @@ class IdentityAlreadyClaimed(DjangoOpenIDException): ...@@ -39,10 +39,7 @@ class IdentityAlreadyClaimed(DjangoOpenIDException):
else: else:
self.message = message self.message = message
class StrictUsernameViolation(DjangoOpenIDException): class DuplicateUsernameViolation(DjangoOpenIDException):
pass
class DuplicateUsernameViolation(StrictUsernameViolation):
def __init__(self, message=None): def __init__(self, message=None):
if message is None: if message is None:
...@@ -50,7 +47,7 @@ class DuplicateUsernameViolation(StrictUsernameViolation): ...@@ -50,7 +47,7 @@ class DuplicateUsernameViolation(StrictUsernameViolation):
else: else:
self.message = message self.message = message
class MissingUsernameViolation(StrictUsernameViolation): class MissingUsernameViolation(DjangoOpenIDException):
def __init__(self, message=None): def __init__(self, message=None):
if message is None: if message is None:
......
...@@ -55,13 +55,7 @@ from django_openid_auth.forms import OpenIDLoginForm ...@@ -55,13 +55,7 @@ from django_openid_auth.forms import OpenIDLoginForm
from django_openid_auth.models import UserOpenID from django_openid_auth.models import UserOpenID
from django_openid_auth.signals import openid_login_complete from django_openid_auth.signals import openid_login_complete
from django_openid_auth.store import DjangoOpenIDStore from django_openid_auth.store import DjangoOpenIDStore
from django_openid_auth.exceptions import ( from django_openid_auth.exceptions import DjangoOpenIDException
DjangoOpenIDException,
IdentityAlreadyClaimed,
DuplicateUsernameViolation,
MissingUsernameViolation,
MissingPhysicalMultiFactor,
)
next_url_re = re.compile('^/[-\w/]+$') next_url_re = re.compile('^/[-\w/]+$')
...@@ -248,8 +242,11 @@ def login_begin(request, template_name='openid/login.html', ...@@ -248,8 +242,11 @@ def login_begin(request, template_name='openid/login.html',
@csrf_exempt @csrf_exempt
def login_complete(request, redirect_field_name=REDIRECT_FIELD_NAME, def login_complete(request, redirect_field_name=REDIRECT_FIELD_NAME,
render_failure=default_render_failure): render_failure=None):
redirect_to = request.REQUEST.get(redirect_field_name, '') redirect_to = request.REQUEST.get(redirect_field_name, '')
render_failure = render_failure or \
getattr(settings, 'OPENID_RENDER_FAILURE', None) or \
default_render_failure
openid_response = parse_openid_response(request) openid_response = parse_openid_response(request)
if not openid_response: if not openid_response:
......
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