Merge lp:~canonical-isd-hackers/canonical-identity-provider/session-refactor-email-sent into lp:canonical-identity-provider/release

Proposed by Simon Davy
Status: Merged
Approved by: Ricardo Kirkner
Approved revision: no longer in the source branch.
Merged at revision: 244
Proposed branch: lp:~canonical-isd-hackers/canonical-identity-provider/session-refactor-email-sent
Merge into: lp:canonical-identity-provider/release
Diff against target: 500 lines (+83/-111)
8 files modified
identityprovider/templates/launchpad/email/invitation.txt (+2/-4)
identityprovider/templates/ubuntu/email/invitation.txt (+2/-4)
identityprovider/tests/test_loginservice.py (+15/-15)
identityprovider/tests/test_views_account.py (+5/-5)
identityprovider/tests/test_views_ui.py (+21/-27)
identityprovider/urls.py (+0/-1)
identityprovider/views/account.py (+15/-17)
identityprovider/views/ui.py (+23/-38)
To merge this branch: bzr merge lp:~canonical-isd-hackers/canonical-identity-provider/session-refactor-email-sent
Reviewer Review Type Date Requested Status
Ricardo Kirkner (community) Approve
Review via email: mp+85930@code.launchpad.net

Commit message

Refactor to not use session/redirect for displaying email sent page. Instead, we just render the page directly

Description of the change

Refactor to not use session/redirect for displaying email sent page. Instead, we just render the page directly

To post a comment you must log in.
Revision history for this message
Ricardo Kirkner (ricardokirkner) wrote :

I like avoiding the use of session for this (+1)

- tiny stylistic issue: we prefer singular assertion methods (assertEqual)
- l. 249: always use RequestContext, otherwise context processors won't be applied (you won't get a style page for example)

One last question: given that there were certain precautions not to break the openid dance in this view, are we certain not redirecting will keep those scenarios working?

review: Needs Fixing
Revision history for this message
Simon Davy (bloodearnest) wrote :

> I like avoiding the use of session for this (+1)
>
> - tiny stylistic issue: we prefer singular assertion methods (assertEqual)
> - l. 249: always use RequestContext, otherwise context processors won't be
> applied (you won't get a style page for example)

Fixed

> One last question: given that there were certain precautions not to break the
> openid dance in this view, are we certain not redirecting will keep those
> scenarios working?

I'm not sure, as I'm not clear on the exact steps of the dance :) I just left anything relating to tokens alone, or reproduced it in the new code. Some day you'll have to teach me the dance :)

Revision history for this message
Ricardo Kirkner (ricardokirkner) wrote :

LGTM

review: Approve

Preview Diff

[H/L] Next/Prev Comment, [J/K] Next/Prev File, [N/P] Next/Prev Hunk
=== modified file 'identityprovider/templates/launchpad/email/invitation.txt'
--- identityprovider/templates/launchpad/email/invitation.txt 2011-12-15 16:29:12 +0000
+++ identityprovider/templates/launchpad/email/invitation.txt 2011-12-16 12:35:28 +0000
@@ -1,11 +1,9 @@
1{% load i18n %}1{% load i18n %}
2{% blocktrans %}Hello2{% blocktrans %}Hello
33
4You recently requested a password reset for the email account {{ email }} for4You recently requested a password reset for the email account {{ email }} for the Launchpad Login Service
5the Launchpad Login Service
65
7This email is not associated with any current accounts. You are very welcome6This email is not associated with any current accounts. You are very welcome to create a Launchpad account - to do so, please go to {{ signup }}
8to create a Launchpad account - to do so, please go to {{ signup }}
97
10Thanks8Thanks
119
1210
=== modified file 'identityprovider/templates/ubuntu/email/invitation.txt'
--- identityprovider/templates/ubuntu/email/invitation.txt 2011-12-15 16:29:12 +0000
+++ identityprovider/templates/ubuntu/email/invitation.txt 2011-12-16 12:35:28 +0000
@@ -1,11 +1,9 @@
1{% load i18n %}1{% load i18n %}
2{% blocktrans %}Hello2{% blocktrans %}Hello
33
4You recently requested a password reset for the email account {{ email }} for4You recently requested a password reset for the email account {{ email }} for the Ubuntu Single Sign On service.
5the Ubuntu Single Sign On service.
65
7This email is not associated with any current accounts. You are very welcome6This email is not associated with any current accounts. You are very welcome to create an Ubuntu SSO account - to do so, please go to {{ signup }}
8to create an Ubuntu SSO account - to do so, please go to {{ signup }}
97
10Thanks8Thanks
119
1210
=== modified file 'identityprovider/tests/test_loginservice.py'
--- identityprovider/tests/test_loginservice.py 2011-12-15 16:29:12 +0000
+++ identityprovider/tests/test_loginservice.py 2011-12-16 12:35:28 +0000
@@ -33,11 +33,11 @@
33 'email': 'nobody@debian.org',33 'email': 'nobody@debian.org',
34 }34 }
35 response = self.client.post('/+forgot_password', query)35 response = self.client.post('/+forgot_password', query)
36 self.assertEquals(response.status_code, 302)36 self.assertEqual(response.status_code, 200)
37 self.assertEquals(response['location'],37 self.assertIn("Forgotten your password?", response.content)
38 'http://testserver/+email-sent')38 self.assertIn("nobody@debian.org", response.content)
39 self.assertEquals(len(mail.outbox), 1)39 self.assertEqual(len(mail.outbox), 1)
40 self.assertEquals(mail.outbox[0].subject,40 self.assertEqual(mail.outbox[0].subject,
41 u"%s: Password reset request" % current_brand.name)41 u"%s: Password reset request" % current_brand.name)
42 self.assertTrue('nobody@debian.org' in mail.outbox[0].body)42 self.assertTrue('nobody@debian.org' in mail.outbox[0].body)
43 self.assertTrue('+new_account' in mail.outbox[0].body)43 self.assertTrue('+new_account' in mail.outbox[0].body)
@@ -55,11 +55,11 @@
55 'passwordconfirm': 'Testing123'55 'passwordconfirm': 'Testing123'
56 }56 }
57 response = self.client.post('/+new_account', query)57 response = self.client.post('/+new_account', query)
58 self.assertEquals(response.status_code, 302)58 self.assertEqual(response.status_code, 200)
59 self.assertEquals(response['location'],59 self.assertIn("Registration mail sent", response.content)
60 'http://testserver/+email-sent')60 self.assertIn("test@canonical.com", response.content)
61 self.assertEquals(len(mail.outbox), 1)61 self.assertEqual(len(mail.outbox), 1)
62 self.assertEquals(mail.outbox[0].subject,62 self.assertEqual(mail.outbox[0].subject,
63 u"%s: Warning" % current_brand.name)63 u"%s: Warning" % current_brand.name)
64 mail.outbox = []64 mail.outbox = []
6565
@@ -68,11 +68,11 @@
68 'email': 'test@canonical.com',68 'email': 'test@canonical.com',
69 }69 }
70 response = self.client.post('/+forgot_password', query)70 response = self.client.post('/+forgot_password', query)
71 self.assertEquals(response.status_code, 302)71 self.assertEqual(response.status_code, 200)
72 self.assertEquals(response['location'],72 self.assertIn("Forgotten your password?", response.content)
73 'http://testserver/+email-sent')73 self.assertIn("test@canonical.com", response.content)
74 self.assertEquals(len(mail.outbox), 1)74 self.assertEqual(len(mail.outbox), 1)
75 self.assertEquals(mail.outbox[0].subject,75 self.assertEqual(mail.outbox[0].subject,
76 u"%s: Forgotten Password" % current_brand.name)76 u"%s: Forgotten Password" % current_brand.name)
77 mail.outbox = []77 mail.outbox = []
7878
7979
=== modified file 'identityprovider/tests/test_views_account.py'
--- identityprovider/tests/test_views_account.py 2011-09-09 14:31:09 +0000
+++ identityprovider/tests/test_views_account.py 2011-12-16 12:35:28 +0000
@@ -85,7 +85,7 @@
85 account=account,85 account=account,
86 status=EmailStatus.NEW)86 status=EmailStatus.NEW)
87 r = self.client.get('/+verify-email', {'id': email.id})87 r = self.client.get('/+verify-email', {'id': email.id})
88 self.assertEqual(r.status_code, 302)88 self.assertEqual(r.status_code, 200)
89 self.assertEqual(len(mail.outbox), 1)89 self.assertEqual(len(mail.outbox), 1)
90 # Erasing emails. Necessary to make other tests pass.90 # Erasing emails. Necessary to make other tests pass.
91 mail.outbox = []91 mail.outbox = []
@@ -97,13 +97,13 @@
97 def test_new_email_post(self):97 def test_new_email_post(self):
98 r = self.client.post('/+new-email',98 r = self.client.post('/+new-email',
99 {'newemail': "very-new-email@example.com"})99 {'newemail': "very-new-email@example.com"})
100 self.assertRedirects(r, '/+email-sent')100 self.assertEqual(r.status_code, 200)
101 mail.outbox = []101 mail.outbox = []
102102
103 def test_new_email_post_with_token(self):103 def test_new_email_post_with_token(self):
104 r = self.client.post('/thisissuperrando/+new-email',104 r = self.client.post('/thisissuperrando/+new-email',
105 {'newemail': "very-new-email@example.com"})105 {'newemail': "very-new-email@example.com"})
106 self.assertEquals(len(mail.outbox), 1)106 self.assertEqual(len(mail.outbox), 1)
107 mail.outbox = []107 mail.outbox = []
108108
109109
@@ -189,7 +189,7 @@
189 self.assertRedirects(r, '/+deactivated')189 self.assertRedirects(r, '/+deactivated')
190190
191 # test token is preserved191 # test token is preserved
192 self.assertEquals(self.client.session.get(token),192 self.assertEqual(self.client.session.get(token),
193 'raw_orequest content')193 'raw_orequest content')
194194
195195
@@ -237,4 +237,4 @@
237 r = self.client.post('/+applications', {'token_id': token.token})237 r = self.client.post('/+applications', {'token_id': token.token})
238238
239 self.assertRedirects(r, '/+applications')239 self.assertRedirects(r, '/+applications')
240 self.assertEquals(Token.objects.filter(token=token.token).count(), 1)240 self.assertEqual(Token.objects.filter(token=token.token).count(), 1)
241241
=== modified file 'identityprovider/tests/test_views_ui.py'
--- identityprovider/tests/test_views_ui.py 2011-11-29 18:06:51 +0000
+++ identityprovider/tests/test_views_ui.py 2011-12-16 12:35:28 +0000
@@ -83,7 +83,7 @@
8383
84 r = _post_new_account(self.client, email='mark@example.com')84 r = _post_new_account(self.client, email='mark@example.com')
8585
86 self.assertRedirects(r, '/+email-sent')86 self.assertEqual(r.status_code, 200)
87 self.assertEqual(len(mail.outbox), 1)87 self.assertEqual(len(mail.outbox), 1)
8888
8989
@@ -202,7 +202,7 @@
202 session.save()202 session.save()
203203
204 self.client.get('/%s/+logout' % token)204 self.client.get('/%s/+logout' % token)
205 self.assertEquals(self.client.session.get(token),205 self.assertEqual(self.client.session.get(token),
206 'raw_orequest content')206 'raw_orequest content')
207207
208 def create_token(self, token_type, email=None, redirection_url=None,208 def create_token(self, token_type, email=None, redirection_url=None,
@@ -253,13 +253,13 @@
253253
254 def test_claim_unexisting_token(self):254 def test_claim_unexisting_token(self):
255 r = self.client.get('/token/%s/' % 0, {'email': 'fake%40example.com'})255 r = self.client.get('/token/%s/' % 0, {'email': 'fake%40example.com'})
256 self.assertEquals(r.status_code, 404)256 self.assertEqual(r.status_code, 404)
257257
258 def test_claim_token_for_unexisting_token_type(self):258 def test_claim_token_for_unexisting_token_type(self):
259 token = self.create_token(9999, 'fake@example.com')259 token = self.create_token(9999, 'fake@example.com')
260 r = self.client.get('/token/%s/' % token.token,260 r = self.client.get('/token/%s/' % token.token,
261 {'email': 'fake%40example.com'})261 {'email': 'fake%40example.com'})
262 self.assertEquals(r.status_code, 404)262 self.assertEqual(r.status_code, 404)
263263
264 def test_claim_consumed_token(self):264 def test_claim_consumed_token(self):
265 self.client.post('/+forgot_password',265 self.client.post('/+forgot_password',
@@ -306,11 +306,11 @@
306306
307 def test_token_form_email_when_it_is_turned_off(self):307 def test_token_form_email_when_it_is_turned_off(self):
308 r = self.get_debug_token_response(False)308 r = self.get_debug_token_response(False)
309 self.assertEquals(r.status_code, 404)309 self.assertEqual(r.status_code, 404)
310310
311 def test_bad_token(self):311 def test_bad_token(self):
312 r = self.client.get('/+bad-token')312 r = self.client.get('/+bad-token')
313 self.assertEquals(r.status_code, 200)313 self.assertEqual(r.status_code, 200)
314314
315 def test_non_field_errors_is_not_in_html(self):315 def test_non_field_errors_is_not_in_html(self):
316 r = self.client.post('/+enter_token', {316 r = self.client.post('/+enter_token', {
@@ -322,7 +322,7 @@
322322
323 def test_logout_to_confirm(self):323 def test_logout_to_confirm(self):
324 r = self.client.get('/+logout-to-confirm')324 r = self.client.get('/+logout-to-confirm')
325 self.assertEquals(r.status_code, 200)325 self.assertEqual(r.status_code, 200)
326326
327 def test_confirm_account_while_logged_in(self):327 def test_confirm_account_while_logged_in(self):
328 token = self.create_token(at.LoginTokenType.NEWPERSONLESSACCOUNT,328 token = self.create_token(at.LoginTokenType.NEWPERSONLESSACCOUNT,
@@ -343,7 +343,7 @@
343 # get a valid session343 # get a valid session
344 token1 = 'a' * 16344 token1 = 'a' * 16
345 r = _post_new_account(self.client, token=token1)345 r = _post_new_account(self.client, token=token1)
346 self.assertRedirects(r, '/%s/+email-sent' % token1)346 self.assertEqual(r.status_code, 200)
347347
348 # claim token348 # claim token
349 r = self.client.post(self._token_url('+newaccount'),349 r = self.client.post(self._token_url('+newaccount'),
@@ -355,7 +355,7 @@
355 # get a valid session355 # get a valid session
356 token1 = create_token(16)356 token1 = create_token(16)
357 r = _post_new_account(self.client, token=token1)357 r = _post_new_account(self.client, token=token1)
358 self.assertRedirects(r, '/%s/+email-sent' % token1)358 self.assertEqual(r.status_code, 200)
359359
360 # claim token360 # claim token
361 r = self.client.post(self._token_url('+newaccount'),361 r = self.client.post(self._token_url('+newaccount'),
@@ -366,7 +366,7 @@
366 def test_confirm_account_redirect_to_decide_with_rpconfig(self):366 def test_confirm_account_redirect_to_decide_with_rpconfig(self):
367 token1 = create_token(16)367 token1 = create_token(16)
368 r = _post_new_account(self.client, token=token1)368 r = _post_new_account(self.client, token=token1)
369 self.assertRedirects(r, '/%s/+email-sent' % token1)369 self.assertEqual(r.status_code, 200)
370370
371 request = {'openid.mode': 'checkid_setup',371 request = {'openid.mode': 'checkid_setup',
372 'openid.trust_root': 'http://localhost/',372 'openid.trust_root': 'http://localhost/',
@@ -664,7 +664,7 @@
664 account.save()664 account.save()
665665
666 r = _post_new_account(self.client, email='mark@example.com')666 r = _post_new_account(self.client, email='mark@example.com')
667 self.assertRedirects(r, '/+email-sent')667 self.assertEqual(r.status_code, 200)
668668
669 if status == AccountStatus.ACTIVE:669 if status == AccountStatus.ACTIVE:
670 mails_sent = 1670 mails_sent = 1
@@ -736,7 +736,7 @@
736 email.delete()736 email.delete()
737 # use verification token737 # use verification token
738 r = self.client.get("/token/%s/+newemail" % token.token)738 r = self.client.get("/token/%s/+newemail" % token.token)
739 self.assertEquals(r.status_code, 404)739 self.assertEqual(r.status_code, 404)
740740
741 def test_confirm_email_get(self):741 def test_confirm_email_get(self):
742 self.authenticate()742 self.authenticate()
@@ -761,10 +761,10 @@
761761
762 token_id = token.pk762 token_id = token.pk
763763
764 self.assertEquals(r.status_code, 404)764 self.assertEqual(r.status_code, 404)
765 self.assertEquals(0, at.AuthToken.objects.filter(pk=token_id).count())765 self.assertEqual(0, at.AuthToken.objects.filter(pk=token_id).count())
766 email = EmailAddress.objects.get(email='newemail2@example.com')766 email = EmailAddress.objects.get(email='newemail2@example.com')
767 self.assertEquals(EmailStatus.NEW, email.status)767 self.assertEqual(EmailStatus.NEW, email.status)
768768
769 def test_config_email_when_not_logged_in_redirects_to_login(self):769 def test_config_email_when_not_logged_in_redirects_to_login(self):
770 account = Account.objects.get_by_email('mark@example.com')770 account = Account.objects.get_by_email('mark@example.com')
@@ -803,12 +803,12 @@
803803
804 def test_invalid_email_does_not_blow_up(self):804 def test_invalid_email_does_not_blow_up(self):
805 r = _post_new_account(self.client, email='what<~@ever.com')805 r = _post_new_account(self.client, email='what<~@ever.com')
806 self.assertEquals(200, r.status_code)806 self.assertEqual(200, r.status_code)
807 self.assertContains(r, 'Invalid email')807 self.assertContains(r, 'Invalid email')
808808
809 def test_valid_email_redirects(self):809 def test_valid_email_redirects(self):
810 r = _post_new_account(self.client, email='what@ever.com')810 r = _post_new_account(self.client, email='what@ever.com')
811 self.assertRedirects(r, '/+email-sent')811 self.assertEqual(r.status_code, 200)
812812
813813
814@skipOnSqlite814@skipOnSqlite
@@ -826,7 +826,7 @@
826 try:826 try:
827 # test normal workflow827 # test normal workflow
828 r = _post_new_account(self.client, email='mark@example.com')828 r = _post_new_account(self.client, email='mark@example.com')
829 self.assertRedirects(r, '/+email-sent')829 self.assertEqual(r.status_code, 200)
830 finally:830 finally:
831 # restore model integrity831 # restore model integrity
832 email.lp_person_id = lp_person_id832 email.lp_person_id = lp_person_id
@@ -866,10 +866,7 @@
866 response = _post_new_account(866 response = _post_new_account(
867 self.client,867 self.client,
868 email=email)868 email=email)
869 # should redirect to '/+email-sent'869 self.assertEqual(response.status_code, 200)
870 self.assertEqual(response.status_code, 302)
871 redirect = response['location']
872 self.assertTrue(redirect.endswith('/+email-sent'))
873870
874 def test_new_account_captcha_whitelist_with_uuid(self):871 def test_new_account_captcha_whitelist_with_uuid(self):
875 email = 'canonicaltest+something@gmail.com'872 email = 'canonicaltest+something@gmail.com'
@@ -882,10 +879,7 @@
882 response = _post_new_account(879 response = _post_new_account(
883 self.client,880 self.client,
884 email=email)881 email=email)
885 # should redirect to '/+email-sent'882 self.assertEqual(response.status_code, 200)
886 self.assertEqual(response.status_code, 302)
887 redirect = response['location']
888 self.assertTrue(redirect.endswith('/+email-sent'))
889883
890 def test_new_account_captcha_whitelist_fail(self):884 def test_new_account_captcha_whitelist_fail(self):
891 email = 'notcanonicaltest@gmail.com'885 email = 'notcanonicaltest@gmail.com'
@@ -976,7 +970,7 @@
976970
977 def test_cookie_is_sessionless(self):971 def test_cookie_is_sessionless(self):
978 self.client.get('/+login')972 self.client.get('/+login')
979 self.assertEquals(self._count_sessions(), 0)973 self.assertEqual(self._count_sessions(), 0)
980974
981975
982class LoginFlowStatsTestCase(SSOBaseTestCase):976class LoginFlowStatsTestCase(SSOBaseTestCase):
983977
=== modified file 'identityprovider/urls.py'
--- identityprovider/urls.py 2011-12-15 16:29:12 +0000
+++ identityprovider/urls.py 2011-12-16 12:35:28 +0000
@@ -59,7 +59,6 @@
5959
60 (r'^\+bad-token', 'bad_token'),60 (r'^\+bad-token', 'bad_token'),
61 (r'^\+logout-to-confirm', 'logout_to_confirm'),61 (r'^\+logout-to-confirm', 'logout_to_confirm'),
62 (r'^%(optional_token)s\+email-sent$' % repls, 'email_sent'),
63 (r'^debug-token/(?P<email>.*\@.*\..*)$', 'token_from_email'),62 (r'^debug-token/(?P<email>.*\@.*\..*)$', 'token_from_email'),
64 (r'^\+deactivated$', 'deactivated'),63 (r'^\+deactivated$', 'deactivated'),
65 (r'^\+suspended$', 'suspended'),64 (r'^\+suspended$', 'suspended'),
6665
=== modified file 'identityprovider/views/account.py'
--- identityprovider/views/account.py 2011-11-21 19:57:56 +0000
+++ identityprovider/views/account.py 2011-12-16 12:35:28 +0000
@@ -23,7 +23,7 @@
23from identityprovider.signals import account_email_added23from identityprovider.signals import account_email_added
2424
25from identityprovider.views.server import xrds25from identityprovider.views.server import xrds
2626from identityprovider.views.ui import display_email_sent
2727
28@vary_on_headers('Accept')28@vary_on_headers('Accept')
29def index(request, token=None):29def index(request, token=None):
@@ -124,7 +124,7 @@
124 return HttpResponseRedirect('/+deactivated')124 return HttpResponseRedirect('/+deactivated')
125125
126126
127def _send_verification_email(account, session, email, tokenid=None):127def _send_verification_email(request, email, tokenid=None):
128 # TODO: This makes use of `tokenid` if it's passed in, but the128 # TODO: This makes use of `tokenid` if it's passed in, but the
129 # call to `send_validation_email_request` always generates a new129 # call to `send_validation_email_request` always generates a new
130 # token. Is this right?130 # token. Is this right?
@@ -134,22 +134,22 @@
134 status=EmailStatus.NEW).delete()134 status=EmailStatus.NEW).delete()
135135
136 # Ensure that this account has such email address; return value is not used136 # Ensure that this account has such email address; return value is not used
137 account.emailaddress_set.get_or_create(137 request.user.emailaddress_set.get_or_create(
138 email=email, lp_person=account.person, status=EmailStatus.NEW)138 email=email, lp_person=request.user.person, status=EmailStatus.NEW)
139139
140 redirection_url = redirection_url_for_token(tokenid)140 redirection_url = redirection_url_for_token(tokenid)
141141
142 token = send_validation_email_request(account, email, redirection_url)142 token = send_validation_email_request(request.user, email, redirection_url)
143 set_session_token_info(session, token)143 set_session_token_info(request.session, token)
144144
145 session['email_feedback'] = settings.FEEDBACK_TO_ADDRESS145 return display_email_sent(request,
146 session['email_heading'] = _("Validate your email address")146 _("Validate your email address"),
147 session['email_reason'] = _("We&rsquo;ve just "147 _("We&rsquo;ve just "
148 "emailed %(email_to)s (from %(email_from)s) "148 "emailed %(email_to)s (from %(email_from)s) "
149 "with instructions on validating your email address.") % {149 "with instructions on validating your email address.") % {
150 'email_to': email,150 'email_to': email,
151 'email_from': settings.NOREPLY_FROM_ADDRESS,151 'email_from': settings.NOREPLY_FROM_ADDRESS}
152 }152 )
153153
154 return HttpResponseRedirect('./+email-sent')154 return HttpResponseRedirect('./+email-sent')
155155
@@ -167,8 +167,7 @@
167 account_email_added.send(167 account_email_added.send(
168 openid_identifier=request.user.openid_identifier,168 openid_identifier=request.user.openid_identifier,
169 sender=None)169 sender=None)
170 return _send_verification_email(request.user, request.session,170 return _send_verification_email(request, email, token)
171 email, token)
172171
173 context = RequestContext(request, {'form': form})172 context = RequestContext(request, {'form': form})
174 return render_to_response('account/new_email.html', context)173 return render_to_response('account/new_email.html', context)
@@ -180,8 +179,7 @@
180 emailid = request.GET.get('id', 0)179 emailid = request.GET.get('id', 0)
181 email = get_object_or_404(request.user.emailaddress_set, pk=emailid,180 email = get_object_or_404(request.user.emailaddress_set, pk=emailid,
182 status=EmailStatus.NEW)181 status=EmailStatus.NEW)
183 return _send_verification_email(request.user, request.session, email.email,182 return _send_verification_email(request, email.email, token)
184 token)
185183
186184
187@login_required185@login_required
188186
=== modified file 'identityprovider/views/ui.py'
--- identityprovider/views/ui.py 2011-12-15 16:29:12 +0000
+++ identityprovider/views/ui.py 2011-12-16 12:35:28 +0000
@@ -455,22 +455,15 @@
455 atoken.sendNewUserEmail(old=old)455 atoken.sendNewUserEmail(old=old)
456 set_session_token_info(request.session, atoken)456 set_session_token_info(request.session, atoken)
457457
458 request.session['email_feedback'] = settings.FEEDBACK_TO_ADDRESS458 return display_email_sent(request,
459 request.session['email_heading'] = _("Registration mail sent")459 _("Registration mail sent"),
460 request.session['email_reason'] = _("We&rsquo;ve just emailed "460 _("We&rsquo;ve just emailed "
461 "%(email_to)s (from %(email_from)s) to confirm "461 "%(email_to)s (from %(email_from)s) to confirm "
462 "your address.") % {462 "your address.") % {
463 'email_to': email,463 'email_to': email,
464 'email_from': settings.NOREPLY_FROM_ADDRESS,464 'email_from': settings.NOREPLY_FROM_ADDRESS },
465 }465 token = token
466 request.session['email_notreceived_extra'] = None466 )
467 if token is not None:
468 # Redirected from an OpenID request, must get back after
469 # confirmation
470 redirection_url = '/%s/+email-sent' % token
471 else:
472 redirection_url = '/+email-sent'
473 return HttpResponseRedirect(redirection_url)
474 else:467 else:
475 polite_form_errors(form._errors)468 polite_form_errors(form._errors)
476 # track number of form errors469 # track number of form errors
@@ -619,17 +612,14 @@
619 return HttpResponseNotFound()612 return HttpResponseNotFound()
620613
621614
622def email_sent(request, token=None):615def display_email_sent(request, heading, reason, extra=None, token=None):
623 request.token = token
624 context = RequestContext(request, {616 context = RequestContext(request, {
625 'email_feedback': request.session.get('email_feedback'),617 'email_feedback': settings.FEEDBACK_TO_ADDRESS,
626 'email_heading': request.session.get('email_heading'),618 'email_heading': heading,
627 'email_reason': request.session.get('email_reason'),619 'email_reason': reason,
628 'email_notreceived_extra': request.session.get(620 'email_notreceived_extra': extra,
629 'email_notreceived_extra'),
630 'token': token,621 'token': token,
631 })622 })
632
633 return render_to_response('registration/email_sent.html', context)623 return render_to_response('registration/email_sent.html', context)
634624
635625
@@ -708,7 +698,8 @@
708 # on how to create an account698 # on how to create an account
709 brand = unicode(current_brand.name)699 brand = unicode(current_brand.name)
710 subject = u"%s: %s" % (brand, u"Password reset request")700 subject = u"%s: %s" % (brand, u"Password reset request")
711 context = { 'email': email, 'signup': reverse(new_account) }701 url = urljoin(settings.SSO_ROOT_URL, reverse(new_account))
702 context = { 'email': email, 'signup': url }
712 tmpl = '%s/email/invitation.txt' % current_brand.template_dir703 tmpl = '%s/email/invitation.txt' % current_brand.template_dir
713 body = render_to_string(tmpl, context)704 body = render_to_string(tmpl, context)
714 send_mail(subject, body, settings.NOREPLY_FROM_ADDRESS, [email])705 send_mail(subject, body, settings.NOREPLY_FROM_ADDRESS, [email])
@@ -749,24 +740,18 @@
749740
750 #regardless of result, we always display the same information back741 #regardless of result, we always display the same information back
751 # to the user742 # to the user
752 # TODO: remove this from session and display via direct render?743 return display_email_sent(request,
753 request.session['email_feedback'] = settings.FEEDBACK_TO_ADDRESS744 _("Forgotten your password?"),
754 request.session['email_heading'] = _("Forgotten your password?")745 _("We&rsquo;ve just emailed "
755 request.session['email_reason'] = _("We&rsquo;ve just emailed "746 "%(email_to)s (from %(email_from)s) with "
756 "%(email_to)s (from %(email_from)s) with "747 "instructions on resetting your password.") % {
757 "instructions on resetting your password.") % {
758 'email_to': email,748 'email_to': email,
759 'email_from': settings.NOREPLY_FROM_ADDRESS,749 'email_from': settings.NOREPLY_FROM_ADDRESS,
760 }750 },
761 request.session['email_notreceived_extra'] = _("Check that "751 _("Check that you&rsquo;ve actually "
762 "you&rsquo;ve actually entered a subscribed email address.")752 "entered a subscribed email address."),
763 if token is not None:753 token=token
764 # Redirected from an OpenID request, must get back after754 )
765 # confirmation
766 redirection_url = '/%s/+email-sent' % token
767 else:
768 redirection_url = '/+email-sent'
769 return HttpResponseRedirect(redirection_url)
770 else:755 else:
771 # track form errors756 # track form errors
772 stats.increment('flows.forgot_password', key='error.form',757 stats.increment('flows.forgot_password', key='error.form',