Merge lp:~lfaraone/django-openid-auth/custom_response into lp:~django-openid-auth/django-openid-auth/trunk

Proposed by Luke Faraone on 2013-11-19
Status: Needs review
Proposed branch: lp:~lfaraone/django-openid-auth/custom_response
Merge into: lp:~django-openid-auth/django-openid-auth/trunk
Diff against target: 69 lines (+10/-5)
2 files modified
django_openid_auth/tests/test_views.py (+3/-0)
django_openid_auth/views.py (+7/-5)
To merge this branch: bzr merge lp:~lfaraone/django-openid-auth/custom_response
Reviewer Review Type Date Requested Status
django-openid-auth developers 2013-11-19 Pending
Review via email: mp+195845@code.launchpad.net

Description of the change

This branch allows you to specify a custom render failure handler.

This is used in one deployment to redirect users to a registration form when they authenticate without already first having an account on our system.

To post a comment you must log in.

Unmerged revisions

108. By Luke Faraone <email address hidden> on 2013-11-19

Add an openid_response parameter to default_render_failure

This allows the failure handler to take actions depending on the contents of
the failure.

For example, we might want to handle "Unknown user" specially and maybe create
an account for the user.

Preview Diff

[H/L] Next/Prev Comment, [J/K] Next/Prev File, [N/P] Next/Prev Hunk
1=== modified file 'django_openid_auth/tests/test_views.py'
2--- django_openid_auth/tests/test_views.py 2013-06-21 17:24:18 +0000
3+++ django_openid_auth/tests/test_views.py 2013-11-19 18:36:44 +0000
4@@ -538,6 +538,7 @@
5 # Override the login_failure handler
6 def mock_login_failure_handler(request, message, status=403,
7 template_name=None,
8+ openid_response=None,
9 exception=None):
10 self.assertTrue(isinstance(exception, MissingPhysicalMultiFactor))
11 return HttpResponse('Test Failure Override', status=200)
12@@ -946,6 +947,7 @@
13 # Override the login_failure handler
14 def mock_login_failure_handler(request, message, status=403,
15 template_name=None,
16+ openid_response=None,
17 exception=None):
18 self.assertTrue(isinstance(exception, (RequiredAttributeNotReturned, MissingUsernameViolation)))
19 return HttpResponse('Test Failure Override', status=200)
20@@ -1016,6 +1018,7 @@
21 # Override the login_failure handler
22 def mock_login_failure_handler(request, message, status=403,
23 template_name=None,
24+ openid_response=None,
25 exception=None):
26 self.assertTrue(isinstance(exception, DuplicateUsernameViolation))
27 return HttpResponse('Test Failure Override', status=200)
28
29=== modified file 'django_openid_auth/views.py'
30--- django_openid_auth/views.py 2013-06-18 13:28:28 +0000
31+++ django_openid_auth/views.py 2013-11-19 18:36:44 +0000
32@@ -122,6 +122,7 @@
33
34 def default_render_failure(request, message, status=403,
35 template_name='openid/failure.html',
36+ openid_response=None,
37 exception=None):
38 """Render an error page to the user."""
39 data = render_to_string(
40@@ -283,7 +284,7 @@
41 try:
42 user = authenticate(openid_response=openid_response)
43 except DjangoOpenIDException, e:
44- return render_failure(request, e.message, exception=e)
45+ return render_failure(request, e.message, exception=e, openid_response=openid_response)
46
47 if user is not None:
48 if user.is_active:
49@@ -296,15 +297,16 @@
50
51 return response
52 else:
53- return render_failure(request, 'Disabled account')
54+ return render_failure(request, 'Disabled account', openid_response=openid_response)
55 else:
56- return render_failure(request, 'Unknown user')
57+ return render_failure(request, 'Unknown user', openid_response=openid_response)
58 elif openid_response.status == FAILURE:
59 return render_failure(
60 request, 'OpenID authentication failed: %s' %
61- openid_response.message)
62+ openid_response.message,
63+ openid_response=openid_response)
64 elif openid_response.status == CANCEL:
65- return render_failure(request, 'Authentication cancelled')
66+ return render_failure(request, 'Authentication cancelled', openid_response=openid_response)
67 else:
68 assert False, (
69 "Unknown OpenID response type: %r" % openid_response.status)

Subscribers

People subscribed via source and target branches