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
=== modified file 'debian/changelog'
--- debian/changelog 2011-07-19 16:12:03 +0000
+++ debian/changelog 2011-07-22 12:53:51 +0000
@@ -1,3 +1,9 @@
1canonical-identity-provider (11.07.20-0ubuntu1) lucid; urgency=low
2
3 * Added missing django-piston dependency
4
5 -- Ricardo Kirkner <ricardo.kirkner@canonical.com> Wed, 20 Jul 2011 16:28:38 -0300
6
1canonical-identity-provider (11.07.19-0ubuntu1) lucid; urgency=low7canonical-identity-provider (11.07.19-0ubuntu1) lucid; urgency=low
28
3 * Send optional sreg fields to RP if it's trusted and has auto_authorize set9 * Send optional sreg fields to RP if it's trusted and has auto_authorize set
410
=== modified file 'debian/control'
--- debian/control 2011-05-24 13:31:14 +0000
+++ debian/control 2011-07-22 12:53:51 +0000
@@ -18,6 +18,7 @@
18 canonical-isd-web-dependencies (>= 1.0.18),18 canonical-isd-web-dependencies (>= 1.0.18),
19 memcached,19 memcached,
20 python-django-oauth-backend (= 0.1.dev1),20 python-django-oauth-backend (= 0.1.dev1),
21 python-django-piston,
21 python-django-preflight (>= 0.1),22 python-django-preflight (>= 0.1),
22 python-django-preflight (<< 0.2),23 python-django-preflight (<< 0.2),
23 python-memcache,24 python-memcache,
2425
=== modified file 'identityprovider/api10/handlers.py'
--- identityprovider/api10/handlers.py 2011-07-07 18:53:04 +0000
+++ identityprovider/api10/handlers.py 2011-07-22 12:53:51 +0000
@@ -55,12 +55,6 @@
55from oauth_backend.models import Token55from oauth_backend.models import Token
5656
5757
58EMAIL_VALIDATION_TEMPLATES = {
59 'web': 'newuser.txt',
60 'mobile': 'newuser.txt',
61 'desktop': 'api-newuser.txt',
62}
63
6458
65class CanNotResetPasswordError(Exception):59class CanNotResetPasswordError(Exception):
66 pass60 pass
@@ -207,7 +201,7 @@
207 cleaned_data['password'])201 cleaned_data['password'])
208 displayname = cleaned_data['displayname']202 displayname = cleaned_data['displayname']
209 email = cleaned_data['email']203 email = cleaned_data['email']
210 if platform == 'desktop':204 if platform in ['desktop', 'mobile']:
211 account = Account.objects.create_account(205 account = Account.objects.create_account(
212 displayname, email,206 displayname, email,
213 encrypted_password, password_encrypted=True,207 encrypted_password, password_encrypted=True,
@@ -221,15 +215,15 @@
221 displayname=displayname,215 displayname=displayname,
222 password=encrypted_password)216 password=encrypted_password)
223217
224 template = EMAIL_VALIDATION_TEMPLATES.get(platform)218 template = '{0}-newuser.txt'.format(platform)
225 if template is None:219 if template is None:
226 msg = ('Invalid platform requested during registration: {0}. '220 msg = ('Invalid platform requested during registration: {0}. '
227 'Using default platform.'.format(platform))221 'Using default platform.'.format(platform))
228 logging.warn(msg)222 logging.warn(msg)
229 template = EMAIL_VALIDATION_TEMPLATES.get('desktop')223 template = 'desktop-newuser.txt'
230 token.sendNewUserEmail(template=template)224 token.sendNewUserEmail(template=template)
231225
232 if platform == 'desktop':226 if platform in ['desktop', 'mobile']:
233 account_created.send(sender=self,227 account_created.send(sender=self,
234 openid_identifier=account.openid_identifier)228 openid_identifier=account.openid_identifier)
235229
236230
=== modified file 'identityprovider/models/authtoken.py'
--- identityprovider/models/authtoken.py 2011-07-06 20:09:53 +0000
+++ identityprovider/models/authtoken.py 2011-07-22 12:53:51 +0000
@@ -134,7 +134,7 @@
134 self._send_email(from_name, subject, message)134 self._send_email(from_name, subject, message)
135135
136 # {{workflow}} remove the `old` parameter136 # {{workflow}} remove the `old` parameter
137 def sendNewUserEmail(self, template='newuser.txt', old=False):137 def sendNewUserEmail(self, template='web-newuser.txt', old=False):
138 url = self.get_absolute_url() if old else self.get_direct_absolute_url()138 url = self.get_absolute_url() if old else self.get_direct_absolute_url()
139 replacements = {139 replacements = {
140 'token': self.token,140 'token': self.token,
141141
=== renamed file 'identityprovider/templates/ubuntu/email/api-newuser.txt' => 'identityprovider/templates/ubuntu/email/desktop-newuser.txt'
=== added file 'identityprovider/templates/ubuntu/email/mobile-newuser.txt'
--- identityprovider/templates/ubuntu/email/mobile-newuser.txt 1970-01-01 00:00:00 +0000
+++ identityprovider/templates/ubuntu/email/mobile-newuser.txt 2011-07-22 12:53:51 +0000
@@ -0,0 +1,15 @@
1{% load i18n %}
2{% blocktrans %}Hello
3
4As 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.
5
6Copy and paste the confirmation code below into your mobile device application.
7
8{{ token }}
9
10If 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.
11
12Thank you,
13
14The Ubuntu Single Sign On team
15https://login.ubuntu.com/{% endblocktrans %}
016
=== renamed file 'identityprovider/templates/ubuntu/email/newuser.txt' => 'identityprovider/templates/ubuntu/email/web-newuser.txt'
=== modified file 'identityprovider/tests/test_handlers.py'
--- identityprovider/tests/test_handlers.py 2011-07-11 14:33:55 +0000
+++ identityprovider/tests/test_handlers.py 2011-07-22 12:53:51 +0000
@@ -127,7 +127,8 @@
127 response = self.registration.register(request)127 response = self.registration.register(request)
128 self.assertEqual(response['status'], 'ok')128 self.assertEqual(response['status'], 'ok')
129129
130 mock_sendNewUserEmail.assert_called_with(template='api-newuser.txt')130 mock_sendNewUserEmail.assert_called_with(
131 template='desktop-newuser.txt')
131132
132 @patch('identityprovider.models.authtoken.AuthToken.sendNewUserEmail')133 @patch('identityprovider.models.authtoken.AuthToken.sendNewUserEmail')
133 def test_register_with_platform(self, mock_sendNewUserEmail):134 def test_register_with_platform(self, mock_sendNewUserEmail):
@@ -141,7 +142,8 @@
141 response = self.registration.register(request)142 response = self.registration.register(request)
142 self.assertEqual(response['status'], 'ok')143 self.assertEqual(response['status'], 'ok')
143144
144 mock_sendNewUserEmail.assert_called_with(template='newuser.txt')145 mock_sendNewUserEmail.assert_called_with(
146 template='mobile-newuser.txt')
145147
146 @patch('identityprovider.models.authtoken.AuthToken.sendNewUserEmail')148 @patch('identityprovider.models.authtoken.AuthToken.sendNewUserEmail')
147 def test_register_with_invalid_platform(self, mock_sendNewUserEmail):149 def test_register_with_invalid_platform(self, mock_sendNewUserEmail):
@@ -194,9 +196,10 @@
194 email.account, 'test@example.com', 'http://foo')196 email.account, 'test@example.com', 'http://foo')
195197
196 @patch('identityprovider.api10.handlers.encrypt_launchpad_password')198 @patch('identityprovider.api10.handlers.encrypt_launchpad_password')
197 @patch('identityprovider.models.authtoken.AuthTokenFactory.new')199 @patch('identityprovider.models.authtoken.AuthTokenFactory.'
198 def test_register_from_mobile_with_redirection_url(self, mock_new,200 'new_api_email_validation_token')
199 mock_encrypt_launchpad_password):201 def test_register_from_mobile_with_redirection_url(self,
202 mock_new_api_email_validation_token, mock_encrypt_launchpad_password):
200203
201 mock_encrypt_launchpad_password.return_value = 'the_password'204 mock_encrypt_launchpad_password.return_value = 'the_password'
202205
@@ -211,14 +214,15 @@
211 response = self.registration.register(request)214 response = self.registration.register(request)
212 self.assertEqual(response['status'], 'ok')215 self.assertEqual(response['status'], 'ok')
213216
214 mock_new.assert_called_with(None, None, 'test@example.com',217 email = EmailAddress.objects.get(email='test@example.com')
215 LoginTokenType.NEWPERSONLESSACCOUNT, 'http://foo',218 mock_new_api_email_validation_token.assert_called_with(
216 displayname='', password='the_password')219 email.account, 'test@example.com', 'http://foo')
217220
218 @patch('identityprovider.api10.handlers.encrypt_launchpad_password')221 @patch('identityprovider.api10.handlers.encrypt_launchpad_password')
219 @patch('identityprovider.models.authtoken.AuthTokenFactory.new')222 @patch('identityprovider.models.authtoken.AuthTokenFactory.'
220 def test_register_from_mobile_without_redirection_url(self, mock_new,223 'new_api_email_validation_token')
221 mock_encrypt_launchpad_password):224 def test_register_from_mobile_without_redirection_url(self,
225 mock_new_api_email_validation_token, mock_encrypt_launchpad_password):
222226
223 mock_encrypt_launchpad_password.return_value = 'the_password'227 mock_encrypt_launchpad_password.return_value = 'the_password'
224228
@@ -232,9 +236,9 @@
232 response = self.registration.register(request)236 response = self.registration.register(request)
233 self.assertEqual(response['status'], 'ok')237 self.assertEqual(response['status'], 'ok')
234238
235 mock_new.assert_called_with(None, None, 'test@example.com',239 email = EmailAddress.objects.get(email='test@example.com')
236 LoginTokenType.NEWPERSONLESSACCOUNT, None,240 mock_new_api_email_validation_token.assert_called_with(
237 displayname='', password='the_password')241 email.account, 'test@example.com', None)
238242
239243
240class AuthenticationTestCase(SQLCachedTestCase):244class AuthenticationTestCase(SQLCachedTestCase):
@@ -281,4 +285,3 @@
281 content = simplejson.loads(response.content)285 content = simplejson.loads(response.content)
282 self.assertEqual(set(content.keys()), set(expected_keys))286 self.assertEqual(set(content.keys()), set(expected_keys))
283 self.assertEqual(content['name'], 'some-token')287 self.assertEqual(content['name'], 'some-token')
284
285288
=== modified file 'identityprovider/tests/test_models_authtoken.py'
--- identityprovider/tests/test_models_authtoken.py 2011-07-06 20:09:53 +0000
+++ identityprovider/tests/test_models_authtoken.py 2011-07-22 12:53:51 +0000
@@ -87,7 +87,7 @@
8787
88 token.sendNewUserEmail()88 token.sendNewUserEmail()
8989
90 self.assertTrue(mock_rts.template.endswith('newuser.txt'))90 self.assertTrue(mock_rts.template.endswith('web-newuser.txt'))
9191
92 self._teardown_mock_render_to_string(rts)92 self._teardown_mock_render_to_string(rts)
9393

Subscribers

People subscribed via source and target branches