~nataliabidart/ubuntu-sso-client/rename-me-too

« back to all changes in this revision

Viewing changes to ubuntu_sso/qt/current_user_sign_in_page.py

- Added signals for the different pages, letting the wizard decide what to do in each case.

Show diffs side-by-side

added added

removed removed

Lines of Context:
18
18
 
19
19
import gettext
20
20
 
21
 
from PyQt4 import QtGui
 
21
from PyQt4 import QtGui, QtCore
22
22
from twisted.internet import defer
23
23
 
24
24
from ubuntu_sso.qt import build_general_error_message
40
40
class CurrentUserSignInPage(SSOWizardPage):
41
41
    """Wizard Page that lets a current user Sign into Ubuntu One."""
42
42
 
 
43
    userLoggedIn = QtCore.pyqtSignal('QString', 'QString')
 
44
    passwordForgotten = QtCore.pyqtSignal()
 
45
    userNotValidated = QtCore.pyqtSignal('QString', 'QString')
 
46
 
43
47
    def __init__(self, ui, *args, **kwargs):
44
48
        super(CurrentUserSignInPage, self).__init__(ui, *args, **kwargs)
45
49
 
53
57
         }
54
58
        self.setup_page()
55
59
 
56
 
    # pylint: disable=W0212
57
60
    def on_user_not_validated(self, *args):
58
61
        """Show the validate email page."""
59
 
        self.next = self.wizard()._pages[self.wizard().email_verification]
60
62
        email = unicode(self.ui.email_edit.text())
61
 
        self.wizard().page(self.next).set_titles(email)
62
 
        self.wizard().next()
63
 
    # pylint: enable=W0212
 
63
        password = unicode(self.ui.password_edit.text())
 
64
        self.userNotValidated.emit(email, password)
64
65
 
65
66
    @defer.inlineCallbacks
66
67
    def setup_page(self):
98
99
        self.ui.sign_in_button.style().polish(
99
100
            self.ui.sign_in_button)
100
101
 
101
 
    def cleanupPage(self):
102
 
        """Reset the state of the wizard if Verification code was visited."""
103
 
        self.wizard()._next_id = None
104
 
 
105
102
    def _set_translated_strings(self):
106
103
        """Set the translated strings."""
107
104
        logger.debug('CurrentUserSignInPage._set_translated_strings')
148
145
        self.message_box.critical(self, self.app_name,
149
146
            build_general_error_message(error))
150
147
 
151
 
    # pylint: disable=W0212
152
148
    def on_logged_in(self, app_name, result):
153
149
        """We managed to log in."""
154
150
        logger.info('Logged in for %s', app_name)
155
 
        self.next = self.wizard()._pages[self.wizard().success]
156
 
        self.wizard().next()
 
151
        email = unicode(self.ui.email_edit.text())
 
152
        self.userLoggedIn.emit(app_name, email)
157
153
        logger.debug('Wizard.loginSuccess emitted.')
158
154
 
159
155
    def on_forgotten_password(self):
160
156
        """Show the user the forgotten password page."""
161
157
        logger.info('Forgotten password')
162
 
        self.next = self.wizard()._pages[self.wizard().forgotten]
163
 
        self.wizard().next()
164
 
    # pylint: enable=W0212
 
158
        self.passwordForgotten.emit()