~nataliabidart/ubuntuone-client/login-email-password-for-everyone

« back to all changes in this revision

Viewing changes to ubuntuone/platform/credentials/__init__.py

  • Committer: Tarmac
  • Author(s): Natalia B. Bidart
  • Date: 2011-08-17 14:08:54 UTC
  • mfrom: (1106.1.7 platform-details)
  • Revision ID: tarmac-20110817140854-sqatv0i3tgpvutfp
- Platform details are now sent in the PING_URL (LP: #827343).

Show diffs side-by-side

added added

removed removed

Lines of Context:
18
18
# with this program.  If not, see <http://www.gnu.org/licenses/>.
19
19
"""Common code for the credentials management."""
20
20
 
 
21
import gettext
21
22
import logging
22
23
import os
23
 
import gettext
 
24
import platform
 
25
import urllib
 
26
import sys
24
27
 
25
28
from twisted.internet import defer
26
29
 
27
 
from ubuntuone.clientdefs import GETTEXT_PACKAGE
 
30
from ubuntuone import clientdefs
28
31
from ubuntuone.logger import (
29
32
    basic_formatter,
30
33
    CustomRotatingFileHandler,
 
34
    log_call,
31
35
)
32
36
from ubuntuone.platform.xdg_base_directory import ubuntuone_log_dir
33
37
 
42
46
logger.addHandler(MAIN_HANDLER)
43
47
 
44
48
NO_OP = lambda *args, **kwargs: None
45
 
Q_ = lambda string: gettext.dgettext(GETTEXT_PACKAGE, string)
 
49
Q_ = lambda string: gettext.dgettext(clientdefs.GETTEXT_PACKAGE, string)
46
50
APP_NAME = "Ubuntu One"
47
51
TC_URL = "https://one.ubuntu.com/terms/"
48
 
PING_URL = "https://one.ubuntu.com/oauth/sso-finished-so-get-tokens/"
 
52
BASE_PING_URL = \
 
53
    "https://one.ubuntu.com/oauth/sso-finished-so-get-tokens/{email}"
 
54
PLATFORM_DATA = {'platform': platform.system(),
 
55
                 'platform_version': platform.release(),
 
56
                 'platform_arch': platform.machine(),
 
57
                 'client_version': clientdefs.VERSION}
 
58
PING_URL = BASE_PING_URL + "?" + urllib.urlencode(PLATFORM_DATA)
49
59
DESCRIPTION = Q_('Ubuntu One requires an Ubuntu Single Sign On (SSO) account. '
50
60
                 'This process will allow you to create a new account, '
51
61
                 'if you do not yet have one.')
52
62
 
 
63
 
53
64
class CredentialsError(Exception):
54
65
    """A general exception when hadling credentilas."""
55
66
 
56
67
 
57
 
class CredentialsManagementToolRoot(object):
 
68
class CredentialsManagementTool(object):
58
69
    """Wrapper to CredentialsManagement.
59
70
 
60
 
    The goal of this class is to abstract the caller from calling the DBus
 
71
    The goal of this class is to abstract the caller from calling the IPC
61
72
    service implemented in the class CredentialsManagement.
62
73
 
63
74
    """
64
75
 
65
 
    def __init__(self, get_proxy_fn):
 
76
    def __init__(self):
66
77
        self._cleanup_signals = []
67
 
        self.get_proxy_fn = get_proxy_fn
68
78
 
69
79
    def cleanup(self, _):
70
80
        """Disconnect all the DBus signals."""
77
87
 
78
88
    def get_creds_proxy(self):
79
89
        """Call the get_proxy_fn, and perhaps wrap the result in a defer."""
80
 
        return defer.maybeDeferred(self.get_proxy_fn)
 
90
        if sys.platform == 'win32':
 
91
            from ubuntuone.platform.credentials import windows
 
92
            source = windows
 
93
        else:
 
94
            from ubuntuone.platform.credentials import linux
 
95
            source = linux
 
96
        result = defer.maybeDeferred(source.get_creds_proxy)
 
97
        return result
81
98
 
 
99
    @log_call(logger.debug)
82
100
    @defer.inlineCallbacks
83
101
    def find_credentials(self):
84
102
        """Find credentials for Ubuntu One.
121
139
        result = yield d
122
140
        defer.returnValue(result)
123
141
 
 
142
    @log_call(logger.debug)
124
143
    @defer.inlineCallbacks
125
144
    def clear_credentials(self):
126
145
        """Clear credentials for Ubuntu One.
149
168
 
150
169
        yield d
151
170
 
 
171
    @log_call(logger.debug)
152
172
    @defer.inlineCallbacks
153
173
    def store_credentials(self, token):
154
174
        """Store credentials for Ubuntu One.
181
201
 
182
202
        yield d
183
203
 
 
204
    @log_call(logger.debug)
184
205
    @defer.inlineCallbacks
185
206
    def register(self, window_id=0):
186
207
        """Register to Ubuntu One.
226
247
        result = yield d
227
248
        defer.returnValue(result)
228
249
 
 
250
    @log_call(logger.debug)
229
251
    @defer.inlineCallbacks
230
252
    def login(self, window_id=0):
231
253
        """Login to Ubuntu One.
272
294
        result = yield d
273
295
        defer.returnValue(result)
274
296
 
 
297
    @log_call(logger.debug)
275
298
    @defer.inlineCallbacks
276
299
    def login_email_password(self, email, password):
277
300
        """Login to Ubuntu One.