Merge lp:~ricardokirkner/canonical-identity-provider/814104-mobile-api-fix into lp:~canonical-isd-hackers/canonical-identity-provider/stable

Proposed by Ricardo Kirkner
Status: Merged
Approved by: Anthony Lenton
Approved revision: no longer in the source branch.
Merged at revision: 117
Proposed branch: lp:~ricardokirkner/canonical-identity-provider/814104-mobile-api-fix
Merge into: lp:~canonical-isd-hackers/canonical-identity-provider/stable
Diff against target: 195 lines (+46/-27)
7 files modified
debian/changelog (+6/-0)
debian/control (+1/-0)
identityprovider/api10/handlers.py (+4/-10)
identityprovider/models/authtoken.py (+1/-1)
identityprovider/templates/ubuntu/email/mobile-newuser.txt (+15/-0)
identityprovider/tests/test_handlers.py (+18/-15)
identityprovider/tests/test_models_authtoken.py (+1/-1)
To merge this branch: bzr merge lp:~ricardokirkner/canonical-identity-provider/814104-mobile-api-fix
Reviewer Review Type Date Requested Status
Anthony Lenton (community) Approve
Review via email: mp+68832@code.launchpad.net

Commit message

modified registration flow via api for mobile platform

Description of the change

Overview
========

This branch changes the mobile platform behaviour for the 'register' api call so that the account gets created immeditaly after the call, but the email validation is left pending (exactly the same workflow as for the desktop platform).

Also, each platform has it's own template used to address specific platform dependent considerations.

To post a comment you must log in.
Revision history for this message
Anthony Lenton (elachuni) :
review: Approve

Preview Diff

[H/L] Next/Prev Comment, [J/K] Next/Prev File, [N/P] Next/Prev Hunk
1=== modified file 'debian/changelog'
2--- debian/changelog 2011-07-19 16:12:03 +0000
3+++ debian/changelog 2011-07-22 12:53:51 +0000
4@@ -1,3 +1,9 @@
5+canonical-identity-provider (11.07.20-0ubuntu1) lucid; urgency=low
6+
7+ * Added missing django-piston dependency
8+
9+ -- Ricardo Kirkner <ricardo.kirkner@canonical.com> Wed, 20 Jul 2011 16:28:38 -0300
10+
11 canonical-identity-provider (11.07.19-0ubuntu1) lucid; urgency=low
12
13 * Send optional sreg fields to RP if it's trusted and has auto_authorize set
14
15=== modified file 'debian/control'
16--- debian/control 2011-05-24 13:31:14 +0000
17+++ debian/control 2011-07-22 12:53:51 +0000
18@@ -18,6 +18,7 @@
19 canonical-isd-web-dependencies (>= 1.0.18),
20 memcached,
21 python-django-oauth-backend (= 0.1.dev1),
22+ python-django-piston,
23 python-django-preflight (>= 0.1),
24 python-django-preflight (<< 0.2),
25 python-memcache,
26
27=== modified file 'identityprovider/api10/handlers.py'
28--- identityprovider/api10/handlers.py 2011-07-07 18:53:04 +0000
29+++ identityprovider/api10/handlers.py 2011-07-22 12:53:51 +0000
30@@ -55,12 +55,6 @@
31 from oauth_backend.models import Token
32
33
34-EMAIL_VALIDATION_TEMPLATES = {
35- 'web': 'newuser.txt',
36- 'mobile': 'newuser.txt',
37- 'desktop': 'api-newuser.txt',
38-}
39-
40
41 class CanNotResetPasswordError(Exception):
42 pass
43@@ -207,7 +201,7 @@
44 cleaned_data['password'])
45 displayname = cleaned_data['displayname']
46 email = cleaned_data['email']
47- if platform == 'desktop':
48+ if platform in ['desktop', 'mobile']:
49 account = Account.objects.create_account(
50 displayname, email,
51 encrypted_password, password_encrypted=True,
52@@ -221,15 +215,15 @@
53 displayname=displayname,
54 password=encrypted_password)
55
56- template = EMAIL_VALIDATION_TEMPLATES.get(platform)
57+ template = '{0}-newuser.txt'.format(platform)
58 if template is None:
59 msg = ('Invalid platform requested during registration: {0}. '
60 'Using default platform.'.format(platform))
61 logging.warn(msg)
62- template = EMAIL_VALIDATION_TEMPLATES.get('desktop')
63+ template = 'desktop-newuser.txt'
64 token.sendNewUserEmail(template=template)
65
66- if platform == 'desktop':
67+ if platform in ['desktop', 'mobile']:
68 account_created.send(sender=self,
69 openid_identifier=account.openid_identifier)
70
71
72=== modified file 'identityprovider/models/authtoken.py'
73--- identityprovider/models/authtoken.py 2011-07-06 20:09:53 +0000
74+++ identityprovider/models/authtoken.py 2011-07-22 12:53:51 +0000
75@@ -134,7 +134,7 @@
76 self._send_email(from_name, subject, message)
77
78 # {{workflow}} remove the `old` parameter
79- def sendNewUserEmail(self, template='newuser.txt', old=False):
80+ def sendNewUserEmail(self, template='web-newuser.txt', old=False):
81 url = self.get_absolute_url() if old else self.get_direct_absolute_url()
82 replacements = {
83 'token': self.token,
84
85=== renamed file 'identityprovider/templates/ubuntu/email/api-newuser.txt' => 'identityprovider/templates/ubuntu/email/desktop-newuser.txt'
86=== added file 'identityprovider/templates/ubuntu/email/mobile-newuser.txt'
87--- identityprovider/templates/ubuntu/email/mobile-newuser.txt 1970-01-01 00:00:00 +0000
88+++ identityprovider/templates/ubuntu/email/mobile-newuser.txt 2011-07-22 12:53:51 +0000
89@@ -0,0 +1,15 @@
90+{% load i18n %}
91+{% blocktrans %}Hello
92+
93+As a final step of the Ubuntu Single Sign On (SSO) account creation process, please validate the email address {{ toaddress }}. Ubuntu SSO enables convenient access to a variety of Ubuntu-related services like Ubuntu One with the same username and password.
94+
95+Copy and paste the confirmation code below into your mobile device application.
96+
97+{{ token }}
98+
99+If you don't know what this is about, then someone has probably entered your email address by mistake. Sorry about that. You don't need to do anything further. Just delete this message.
100+
101+Thank you,
102+
103+The Ubuntu Single Sign On team
104+https://login.ubuntu.com/{% endblocktrans %}
105
106=== renamed file 'identityprovider/templates/ubuntu/email/newuser.txt' => 'identityprovider/templates/ubuntu/email/web-newuser.txt'
107=== modified file 'identityprovider/tests/test_handlers.py'
108--- identityprovider/tests/test_handlers.py 2011-07-11 14:33:55 +0000
109+++ identityprovider/tests/test_handlers.py 2011-07-22 12:53:51 +0000
110@@ -127,7 +127,8 @@
111 response = self.registration.register(request)
112 self.assertEqual(response['status'], 'ok')
113
114- mock_sendNewUserEmail.assert_called_with(template='api-newuser.txt')
115+ mock_sendNewUserEmail.assert_called_with(
116+ template='desktop-newuser.txt')
117
118 @patch('identityprovider.models.authtoken.AuthToken.sendNewUserEmail')
119 def test_register_with_platform(self, mock_sendNewUserEmail):
120@@ -141,7 +142,8 @@
121 response = self.registration.register(request)
122 self.assertEqual(response['status'], 'ok')
123
124- mock_sendNewUserEmail.assert_called_with(template='newuser.txt')
125+ mock_sendNewUserEmail.assert_called_with(
126+ template='mobile-newuser.txt')
127
128 @patch('identityprovider.models.authtoken.AuthToken.sendNewUserEmail')
129 def test_register_with_invalid_platform(self, mock_sendNewUserEmail):
130@@ -194,9 +196,10 @@
131 email.account, 'test@example.com', 'http://foo')
132
133 @patch('identityprovider.api10.handlers.encrypt_launchpad_password')
134- @patch('identityprovider.models.authtoken.AuthTokenFactory.new')
135- def test_register_from_mobile_with_redirection_url(self, mock_new,
136- mock_encrypt_launchpad_password):
137+ @patch('identityprovider.models.authtoken.AuthTokenFactory.'
138+ 'new_api_email_validation_token')
139+ def test_register_from_mobile_with_redirection_url(self,
140+ mock_new_api_email_validation_token, mock_encrypt_launchpad_password):
141
142 mock_encrypt_launchpad_password.return_value = 'the_password'
143
144@@ -211,14 +214,15 @@
145 response = self.registration.register(request)
146 self.assertEqual(response['status'], 'ok')
147
148- mock_new.assert_called_with(None, None, 'test@example.com',
149- LoginTokenType.NEWPERSONLESSACCOUNT, 'http://foo',
150- displayname='', password='the_password')
151+ email = EmailAddress.objects.get(email='test@example.com')
152+ mock_new_api_email_validation_token.assert_called_with(
153+ email.account, 'test@example.com', 'http://foo')
154
155 @patch('identityprovider.api10.handlers.encrypt_launchpad_password')
156- @patch('identityprovider.models.authtoken.AuthTokenFactory.new')
157- def test_register_from_mobile_without_redirection_url(self, mock_new,
158- mock_encrypt_launchpad_password):
159+ @patch('identityprovider.models.authtoken.AuthTokenFactory.'
160+ 'new_api_email_validation_token')
161+ def test_register_from_mobile_without_redirection_url(self,
162+ mock_new_api_email_validation_token, mock_encrypt_launchpad_password):
163
164 mock_encrypt_launchpad_password.return_value = 'the_password'
165
166@@ -232,9 +236,9 @@
167 response = self.registration.register(request)
168 self.assertEqual(response['status'], 'ok')
169
170- mock_new.assert_called_with(None, None, 'test@example.com',
171- LoginTokenType.NEWPERSONLESSACCOUNT, None,
172- displayname='', password='the_password')
173+ email = EmailAddress.objects.get(email='test@example.com')
174+ mock_new_api_email_validation_token.assert_called_with(
175+ email.account, 'test@example.com', None)
176
177
178 class AuthenticationTestCase(SQLCachedTestCase):
179@@ -281,4 +285,3 @@
180 content = simplejson.loads(response.content)
181 self.assertEqual(set(content.keys()), set(expected_keys))
182 self.assertEqual(content['name'], 'some-token')
183-
184
185=== modified file 'identityprovider/tests/test_models_authtoken.py'
186--- identityprovider/tests/test_models_authtoken.py 2011-07-06 20:09:53 +0000
187+++ identityprovider/tests/test_models_authtoken.py 2011-07-22 12:53:51 +0000
188@@ -87,7 +87,7 @@
189
190 token.sendNewUserEmail()
191
192- self.assertTrue(mock_rts.template.endswith('newuser.txt'))
193+ self.assertTrue(mock_rts.template.endswith('web-newuser.txt'))
194
195 self._teardown_mock_render_to_string(rts)
196

Subscribers

People subscribed via source and target branches