Merge lp:~ralsina/ubuntuone-client/login-user-password into lp:ubuntuone-client

Proposed by Roberto Alsina
Status: Merged
Approved by: Roberto Alsina
Approved revision: 1084
Merged at revision: 1082
Proposed branch: lp:~ralsina/ubuntuone-client/login-user-password
Merge into: lp:ubuntuone-client
Diff against target: 196 lines
To merge this branch: bzr merge lp:~ralsina/ubuntuone-client/login-user-password
Reviewer Review Type Date Requested Status
Natalia Bidart (community) Approve
Alejandro J. Cura (community) Approve
Review via email: mp+69709@code.launchpad.net

Commit message

Expose login_with_user_password via ubuntuone-client

Description of the change

Expose login_with_user_password via ubuntuone-client

To post a comment you must log in.
Revision history for this message
Alejandro J. Cura (alecu) wrote :

Looks fine.

review: Approve
Revision history for this message
Natalia Bidart (nataliabidart) :
review: Approve

Preview Diff

[H/L] Next/Prev Comment, [J/K] Next/Prev File, [N/P] Next/Prev Hunk
1=== added file 'contrib/login_email_password.py'
2--- contrib/login_email_password.py 1970-01-01 00:00:00 +0000
3+++ contrib/login_email_password.py 2011-07-29 18:14:24 +0000
4@@ -0,0 +1,40 @@
5+# -*- coding: utf-8 -*-
6+# Author: Roberto Alsina <roberto.alsina@canonical.com>
7+#
8+# Copyright 2011 Canonical Ltd.
9+#
10+# This program is free software: you can redistribute it and/or modify it
11+# under the terms of the GNU General Public License version 3, as published
12+# by the Free Software Foundation.
13+#
14+# This program is distributed in the hope that it will be useful, but
15+# WITHOUT ANY WARRANTY; without even the implied warranties of
16+# MERCHANTABILITY, SATISFACTORY QUALITY, or FITNESS FOR A PARTICULAR
17+# PURPOSE. See the GNU General Public License for more details.
18+#
19+# You should have received a copy of the GNU General Public License along
20+# with this program. If not, see <http://www.gnu.org/licenses/>.
21+"""Script that shows the qt gui."""
22+
23+# pylint: disable=F0401, E1101
24+from twisted.internet import reactor
25+from twisted.internet.defer import inlineCallbacks
26+from ubuntuone.platform.credentials import CredentialsManagementTool
27+
28+
29+@inlineCallbacks
30+def main():
31+ """Perform a client request to be logged in."""
32+ credtool = CredentialsManagementTool()
33+
34+ creds = yield credtool.login_email_password(
35+ email='whomever@canonical.com',
36+ password='whatever',
37+ )
38+ print "creds found", creds
39+ reactor.stop()
40+
41+
42+if __name__ == '__main__':
43+ main()
44+ reactor.run()
45
46=== modified file 'tests/test_credentials.py'
47--- tests/test_credentials.py 2011-06-24 05:30:34 +0000
48+++ tests/test_credentials.py 2011-07-29 18:14:24 +0000
49@@ -98,6 +98,24 @@
50 self.mocker.replay()
51 return self.management_tool.register(window_id=window_id)
52
53+ def test_login_email_password(self):
54+ """Test that we login correctly."""
55+ email = 'email'
56+ password = 'password'
57+ arg_dict = dict(email=email, password=password)
58+ signals = ['creds_found', 'creds_denied', 'creds_error']
59+ self.get_cred_proxy()
60+ self.mocker.result(self.proxy)
61+ self.proxy.register_to_credentials_found(MATCH(callable))
62+ self.mocker.result(signals[0])
63+ self.proxy.register_to_credentials_error(MATCH(callable))
64+ self.mocker.result(signals[1])
65+ self.proxy.login_email_password(arg_dict, reply_handler=MATCH(callable),
66+ error_handler=MATCH(callable))
67+ self.mocker.replay()
68+ return self.management_tool.login_email_password(email=email,
69+ password=password)
70+
71 def test_cleanup_but_no_remove(self):
72 """The cleanup method works on handlers that have no remove method."""
73 self.management_tool._cleanup_signals = ["test signal 1", "test sig 2"]
74
75=== modified file 'ubuntuone/api/__init__.py'
76--- ubuntuone/api/__init__.py 2011-01-14 12:56:21 +0000
77+++ ubuntuone/api/__init__.py 2011-07-29 18:14:24 +0000
78@@ -15,4 +15,4 @@
79 #
80 # You should have received a copy of the GNU General Public License along
81 # with this program. If not, see <http://www.gnu.org/licenses/>.
82-
83+
84
85=== modified file 'ubuntuone/credentials.py'
86--- ubuntuone/credentials.py 2011-07-26 16:07:08 +0000
87+++ ubuntuone/credentials.py 2011-07-29 18:14:24 +0000
88@@ -271,3 +271,37 @@
89
90 result = yield d
91 defer.returnValue(result)
92+
93+ @defer.inlineCallbacks
94+ def login_email_password(self, email, password):
95+ """Login to Ubuntu One.
96+
97+ Return a deferred that, when fired, will return the credentials for
98+ Ubuntu One for the given email and password.
99+
100+ The returned credentials will be either a non-empty dictionary like the
101+ one described in 'find_credentials', or None. The latter indicates
102+ invalid or wrong user/password.
103+
104+ """
105+ d = defer.Deferred()
106+ d.addBoth(self.cleanup)
107+
108+ proxy = yield self.get_creds_proxy()
109+
110+ sig = proxy.register_to_credentials_found(d.callback)
111+ self._cleanup_signals.append(sig)
112+
113+ sig = proxy.register_to_credentials_error(
114+ lambda x, error_dict: d.errback(CredentialsError(error_dict)))
115+ self._cleanup_signals.append(sig)
116+
117+ done = defer.Deferred()
118+ proxy.login_email_password({'email': email, 'password': password},
119+ reply_handler=lambda: done.callback(None),
120+ error_handler=lambda *a: done.errback(a))
121+
122+ yield done
123+
124+ result = yield d
125+ defer.returnValue(result)
126
127=== modified file 'ubuntuone/platform/linux/credentials.py'
128--- ubuntuone/platform/linux/credentials.py 2011-05-31 18:13:24 +0000
129+++ ubuntuone/platform/linux/credentials.py 2011-07-29 18:14:24 +0000
130@@ -226,6 +226,17 @@
131 self.sso_proxy.login(APP_NAME, params,
132 reply_handler=reply_handler, error_handler=error_handler)
133
134+ @dbus.service.method(dbus_interface=DBUS_CREDENTIALS_IFACE,
135+ in_signature='a{ss}',
136+ async_callbacks=("reply_handler", "error_handler"))
137+ def login_email_password(self, args, reply_handler=NO_OP, error_handler=NO_OP):
138+ """Get credentials if found else prompt to login to Ubuntu One."""
139+ self.ref_count += 1
140+ params = {PING_URL_KEY: PING_URL}
141+ params.update(args)
142+ self.sso_proxy.login_email_password(APP_NAME, params,
143+ reply_handler=reply_handler, error_handler=error_handler)
144+
145
146 class CredentialsManagementProxy(object):
147 """Proxy that allows to work with the dbus api.
148@@ -267,6 +278,10 @@
149 """Relay the login method."""
150 return self.proxy.login(*args, **kwargs)
151
152+ def login_email_password(self, *args, **kwargs):
153+ """Relay the login method."""
154+ return self.proxy.login_email_password(*args, **kwargs)
155+
156 def register_to_credentials_stored(self, callback):
157 """Register to the CredentialsStored dbus signal."""
158 return self.proxy.connect_to_signal('CredentialsStored', callback)
159
160=== modified file 'ubuntuone/platform/windows/credentials.py'
161--- ubuntuone/platform/windows/credentials.py 2011-07-20 15:01:03 +0000
162+++ ubuntuone/platform/windows/credentials.py 2011-07-29 18:14:24 +0000
163@@ -101,6 +101,13 @@
164 d = self.sso_proxy.login(APP_NAME, params)
165 d.addCallbacks(lambda _: reply_handler(), error_handler)
166
167+ def login_email_password(self, args, reply_handler=NO_OP, error_handler=NO_OP):
168+ """Get credentials if found else login to Ubuntu One."""
169+ params = {PING_URL_KEY: PING_URL}
170+ params.update(args)
171+ d = self.sso_proxy.login_email_password(APP_NAME, params)
172+ d.addCallbacks(lambda _: reply_handler(), error_handler)
173+
174 def register_to_credentials_stored(self, callback):
175 """Register to the CredentialsStored dbus signal."""
176 return RemovableSignal(self.sso_proxy, "on_credentials_stored_cb",
177@@ -113,6 +120,7 @@
178
179 def register_to_credentials_found(self, callback):
180 """Register to the CredentialsFound dbus signal."""
181+ # XXX: we are not filtering by app name (bug #818190)
182 pass_credentials = lambda app_name, creds: callback(creds)
183 return RemovableSignal(self.sso_proxy, "on_credentials_found_cb",
184 pass_credentials)
185
186=== modified file 'ubuntuone/platform/windows/ipc.py'
187--- ubuntuone/platform/windows/ipc.py 2011-07-28 13:54:36 +0000
188+++ ubuntuone/platform/windows/ipc.py 2011-07-29 18:14:24 +0000
189@@ -316,7 +316,7 @@
190 """Emit RequestQueueRemoved."""
191 sanitize_dict(data)
192 self.emit_signal('on_request_queue_removed', op_name, str(op_id), data)
193-
194
195+
196 class Events(Referenceable, SignalBroadcaster):
197 """The events of the system translated to ipc signals."""
198

Subscribers

People subscribed via source and target branches