~mvo/ubuntu-sso-client/strawman-lp711413

« back to all changes in this revision

Viewing changes to ubuntu_sso/credentials.py

  • Committer: Natalia B. Bidart
  • Date: 2010-11-19 19:53:22 UTC
  • mto: This revision was merged to the branch mainline in revision 653.
  • Revision ID: natalia.bidart@canonical.com-20101119195322-kiwyeov087oefpcy
Splitting GUI code out of backend (LP: #677518).

Show diffs side-by-side

added added

removed removed

Lines of Context:
35
35
 
36
36
"""
37
37
 
 
38
import sys
38
39
import traceback
39
40
import urllib2
40
41
 
58
59
HELP_TEXT_KEY = 'help_text'
59
60
WINDOW_ID_KEY = 'window_id'
60
61
PING_URL_KEY = 'ping_url'
 
62
UI_MODULE_KEY = 'ui_module'
 
63
UI_CLASS_KEY = 'ui_class'
61
64
SUCCESS_CB_KEY = 'success_cb'
62
65
ERROR_CB_KEY = 'error_cb'
63
66
DENIAL_CB_KEY = 'denial_cb'
133
136
 
134
137
    def __init__(self, app_name, tc_url=None, help_text='',
135
138
                 window_id=0, ping_url=None,
 
139
                 ui_module='ubuntu_sso.gtk.gui', ui_class='UbuntuSSOClientGUI',
136
140
                 success_cb=NO_OP, error_cb=NO_OP, denial_cb=NO_OP):
137
141
        """Return a Credentials management object.
138
142
 
174
178
        self.window_id = window_id
175
179
        self.ping_url = ping_url
176
180
        self.tc_url = tc_url
 
181
        self.ui_module = ui_module
 
182
        self.ui_class = ui_class
177
183
        self._success_cb = success_cb
178
184
        self._error_cb = error_cb
179
185
        self.denial_cb = denial_cb
203
209
 
204
210
            self.success_cb(creds)
205
211
 
206
 
    def _login_error_cb(self, dialog, app_name, error):
207
 
        """Handle UI error when login/registration failed."""
208
 
        logger.warning('Login/registration failed app %r, error %r',
209
 
                       app_name, error)
210
 
        self.error_cb({ERROR_KEY: error})
211
 
 
212
212
    def _auth_denial_cb(self, dialog, app_name):
213
213
        """The user decided not to allow the registration or login."""
214
214
        logger.warning('Login/registration was denied to app %r', app_name)
244
244
    @handle_exceptions(msg='Problem opening the Ubuntu SSO user interface')
245
245
    def _show_ui(self, login_only):
246
246
        """Shows the UI, connect outcome signals."""
247
 
        # delay gui import to be able to function on non-graphical envs
248
 
        from ubuntu_sso import gui
249
 
        self.gui = gui.UbuntuSSOClientGUI(app_name=self.app_name,
 
247
 
 
248
        __import__(self.ui_module)
 
249
        gui = sys.modules[self.ui_module]
 
250
 
 
251
        self.gui = getattr(gui, self.ui_class)(app_name=self.app_name,
250
252
                        tc_url=self.tc_url, help_text=self.help_text,
251
253
                        window_id=self.window_id, login_only=login_only)
252
254
 
253
255
        self.gui.connect(gui.SIG_LOGIN_SUCCEEDED, self._login_success_cb)
254
 
        self.gui.connect(gui.SIG_LOGIN_FAILED, self._login_error_cb)
255
256
        self.gui.connect(gui.SIG_REGISTRATION_SUCCEEDED,
256
257
                         self._login_success_cb)
257
 
        self.gui.connect(gui.SIG_REGISTRATION_FAILED, self._login_error_cb)
258
258
        self.gui.connect(gui.SIG_USER_CANCELATION, self._auth_denial_cb)
259
259
 
260
260
    @handle_failures(msg='Problem while retrieving credentials')