21
21
from PyQt4 import QtGui
22
from twisted.internet import defer
24
from ubuntu_sso.qt import build_general_error_message
23
25
from ubuntu_sso.qt.gui import SSOWizardPage
26
from ubuntu_sso.logger import setup_logging
27
from ubuntu_sso.utils.ui import (
29
FORGOTTEN_PASSWORD_BUTTON,
26
36
_ = gettext.gettext
37
logger = setup_logging('ubuntu_sso.current_user_sign_in_page')
29
40
class CurrentUserSignInPage(SSOWizardPage):
30
41
"""Wizard Page that lets a current user Sign into Ubuntu One."""
43
def __init__(self, ui, *args, **kwargs):
44
super(CurrentUserSignInPage, self).__init__(ui, *args, **kwargs)
48
self._filter_by_app_name(self.on_logged_in),
50
self._filter_by_app_name(self.on_login_error),
52
self._filter_by_app_name(self.on_user_not_validated),
56
# pylint: disable=W0212
57
def on_user_not_validated(self, *args):
58
"""Show the validate email page."""
59
self.next = self.wizard()._pages[self.wizard().email_verification]
60
email = unicode(self.ui.email_edit.text())
61
self.wizard().page(self.next).set_titles(email)
63
# pylint: enable=W0212
65
@defer.inlineCallbacks
67
"""Setup the widget components."""
68
self.backend = yield self.get_backend()
69
self._set_translated_strings()
70
# lets add call backs to be execute for the calls we are interested
32
74
# Invalid names of Qt-inherited methods
33
75
# pylint: disable=C0103
59
101
def cleanupPage(self):
60
102
"""Reset the state of the wizard if Verification code was visited."""
61
103
self.wizard()._next_id = None
105
def _set_translated_strings(self):
106
"""Set the translated strings."""
107
logger.debug('CurrentUserSignInPage._set_translated_strings')
108
self.ui.email_label.setText(EMAIL_LABEL)
109
self.ui.password_label.setText(LOGIN_PASSWORD_LABEL)
110
self.ui.forgot_password_label.setText(FORGOTTEN_PASSWORD_BUTTON)
111
self.ui.sign_in_button.setText(SIGN_IN_BUTTON)
113
def _connect_ui(self):
114
"""Connect the buttons to perform actions."""
115
logger.debug('CurrentUserSignInPage._connect_buttons')
116
self.ui.forgot_password_label.linkActivated.connect(
117
self.on_forgotten_password)
118
self.ui.email_edit.textChanged.connect(self._validate)
119
self.ui.password_edit.textChanged.connect(self._validate)
120
self.ui.sign_in_button.clicked.connect(self.login)
123
"""Perform input validation."""
125
correct_mail = is_correct_email(unicode(self.ui.email_edit.text()))
126
password = unicode(self.ui.password_edit.text())
127
if not correct_mail or not password:
129
self.ui.sign_in_button.setEnabled(valid)
130
self.ui.sign_in_button.setProperty("DisabledState",
131
not self.ui.sign_in_button.isEnabled())
132
self.ui.sign_in_button.style().unpolish(self.ui.sign_in_button)
133
self.ui.sign_in_button.style().polish(self.ui.sign_in_button)
136
"""Perform the login using the self.backend."""
137
logger.debug('CurrentUserSignInPage.login')
138
# grab the data from the view and call the backend
139
email = unicode(self.ui.email_edit.text())
140
password = unicode(self.ui.password_edit.text())
141
self.backend.login(self.app_name, email, password)
143
def on_login_error(self, app_name, error):
144
"""There was an error when login in."""
146
logger.error('Got error when login %s, error: %s',
147
self.app_name, error)
148
self.message_box.critical(self, self.app_name,
149
build_general_error_message(error))
151
# pylint: disable=W0212
152
def on_logged_in(self, app_name, result):
153
"""We managed to log in."""
154
logger.info('Logged in for %s', app_name)
155
self.next = self.wizard()._pages[self.wizard().success]
157
logger.debug('Wizard.loginSuccess emitted.')
159
def on_forgotten_password(self):
160
"""Show the user the forgotten password page."""
161
logger.info('Forgotten password')
162
self.next = self.wizard()._pages[self.wizard().forgotten]
164
# pylint: enable=W0212