38
38
from ubuntu_sso.qt.setup_account_ui import Ui_SetUpAccountPage
39
39
from ubuntu_sso.qt.terms_and_conditions_ui import Ui_TosPage
40
40
from ubuntu_sso.qt.success_message_ui import Ui_SuccessPage
41
from ubuntu_sso.qt.forgotten_password_ui import Ui_ForgottenPasswordPage
42
from ubuntu_sso.qt.reset_password_ui import Ui_ResetPasswordPage
41
43
# pylint: enable=F0401,E0611
42
44
from ubuntu_sso.qt.controllers import (
43
45
ChooseSignInController,
44
46
CurrentUserController,
45
47
EmailVerificationController,
49
ForgottenPasswordController,
50
ResetPasswordController,
47
51
SetUpAccountController,
76
80
# pylint: enable=C0103
83
class EnhancedLineEdit(object):
84
"""Represents and enhanced lineedit.
86
This class works on an already added lineedit to the widget so
87
that we are just adding extra items to it.
90
def __init__(self, line_edit, valid_cb=lambda x: False):
91
"""Create an instance."""
92
self._line_edit = line_edit
93
layout = QHBoxLayout(self._line_edit)
95
self._line_edit.setLayout(layout)
96
self.valid_cb = valid_cb
98
self.clear_button = QPushButton(self._line_edit)
99
layout.addWidget(self.clear_button)
100
self.clear_button.setMinimumSize(16, 16)
101
self.clear_button.setVisible(False)
102
self.clear_button.setFlat(True)
103
self.clear_button.setCursor(QCursor(0))
104
self.clear_button.setIcon(QApplication.style().standardIcon(
105
QStyle.SP_MessageBoxWarning))
106
# connect the change of text to the cation that will check if the
107
# text is valid and if the icon should be shown.
108
self._line_edit.textChanged.connect(self.show_button)
110
def show_button(self, string):
111
"""Decide if we show the button or not."""
112
if not self.valid_cb(string):
113
self.clear_button.setVisible(True)
115
self.clear_button.setVisible(False)
118
class SSOWizardEnhancedEditPage(SSOWizardPage):
119
"""Page that contains enhanced line edits."""
121
def __init__(self, ui, controller, parent=None):
122
"""Create a new instance."""
123
SSOWizardPage.__init__(self, ui, controller, parent)
124
self._enhanced_edits = {}
126
def set_line_edit_validation_rule(self, edit, cb):
127
"""Set a new enhanced edit so that we can show an icon."""
128
if edit in self._enhanced_edits:
129
self._enhanced_edits[edit].valid_cb = cb
131
# create a new enhanced edit
132
enhanced_edit = EnhancedLineEdit(edit, cb)
133
self._enhanced_edits[edit] = enhanced_edit
79
136
class ChooseSignInPage(SSOWizardPage):
80
137
"""Widget that allows the user to choose how to sign in."""
170
227
return self.ui.error_message_label
173
class ForgottenPasswordPage(SSOWizardPage):
230
class ForgottenPasswordPage(SSOWizardEnhancedEditPage):
174
231
"""Widget used to deal with users that forgot the password."""
176
233
def __init__(self, ui, controller, parent=None):
177
234
"""Create a new instance."""
178
SSOWizard.__init__(self, ui, controller, parent)
235
SSOWizardEnhancedEditPage.__init__(self, ui, controller, parent)
238
def email_widget(self):
239
"""Return the widget used to show the email information."""
240
return self.ui.email_widget
243
def forgotted_password_intro_label(self):
244
"""Return the intro label that lets the user know the issue."""
245
return self.ui.forgotted_password_intro_label
248
def error_label(self):
249
"""Return the label used to show error."""
250
return self.ui.error_label
253
def email_address_label(self):
254
"""Return the lable used to state the use of the line edit."""
255
return self.ui.email_address_label
258
def email_address(self):
259
"""Return the email address provided by the user."""
260
return str(self.ui.email_line_edit.text())
263
def email_address_line_edit(self):
264
"""Return the line edit with the content."""
265
return self.ui.email_line_edit
268
def send_button(self):
269
"""Return the button used to request the new password."""
270
return self.ui.send_button
273
def try_again_widget(self):
274
"""Return the widget used to display the try again button."""
275
return self.ui.try_again_widget
278
def try_again_button(self):
279
"""Return the button used to try again the reset password."""
280
return self.ui.try_again_button
283
class ResetPasswordPage(SSOWizardEnhancedEditPage):
284
"""Widget used to allow the user change his password."""
286
def __init__(self, ui, controller, parent=None):
287
"""Create a new instance."""
288
SSOWizardEnhancedEditPage.__init__(self, ui, controller, parent)
291
def reset_code_line_edit(self):
292
"""Return the line edit where the reset code is given."""
293
return self.ui.reset_code_line_edit
296
def reset_code(self):
297
"""Return the reset code typed by the user."""
298
return str(self.ui.reset_code_line_edit.text())
301
def password_line_edit(self):
302
"""Return the line edit where the password is typed."""
303
return self.ui.password_line_edit
307
"""Return the passsword typed by the user."""
308
return str(self.ui.password_line_edit.text())
311
def confirm_password_line_edit(self):
312
"""Return the line edit used to confirm the password."""
313
return self.ui.confirm_password_line_edit
316
def retyped_password(self):
317
"""Return the password confirmation given by the user."""
318
return str(self.ui.confirm_password_line_edit.text())
321
def reset_password_button(self):
322
"""Return the button used to reset the password."""
323
return self.ui.reset_password_button
181
326
class TosPage(SSOWizardPage):
182
327
"""Widget used to show the tos."""
191
336
return self.ui.terms_webkit
194
class EnhancedLineEdit(object):
195
"""Represents and enhanced lineedit.
197
This class works on an already added lineedit to the widget so
198
that we are just adding extra items to it.
201
def __init__(self, line_edit, valid_cb=lambda x: False):
202
"""Create an instance."""
203
self._line_edit = line_edit
204
layout = QHBoxLayout(self._line_edit)
206
self._line_edit.setLayout(layout)
207
self.valid_cb = valid_cb
209
self.clear_button = QPushButton(self._line_edit)
210
layout.addWidget(self.clear_button)
211
self.clear_button.setMinimumSize(16, 16)
212
self.clear_button.setVisible(False)
213
self.clear_button.setFlat(True)
214
self.clear_button.setCursor(QCursor(0))
215
self.clear_button.setIcon(QApplication.style().standardIcon(
216
QStyle.SP_MessageBoxWarning))
217
# connect the change of text to the cation that will check if the
218
# text is valid and if the icon should be shown.
219
self._line_edit.textChanged.connect(self.show_button)
221
def show_button(self, string):
222
"""Decide if we show the button or not."""
223
if not self.valid_cb(string):
224
self.clear_button.setVisible(True)
226
self.clear_button.setVisible(False)
229
class SetupAccountPage(SSOWizardPage):
339
class SetupAccountPage(SSOWizardEnhancedEditPage):
230
340
"""Widget used to create a new account."""
232
342
def __init__(self, ui, controller, parent=None):
275
385
frame.setPalette(palette)
276
386
frame.setAutoFillBackground(True)
279
def set_line_edit_validation_rule(self, edit, cb):
280
"""Set a new enhanced edit so that we can show an icon."""
281
if edit in self._enhanced_edits:
282
self._enhanced_edits[edit].valid_cb = cb
284
# create a new enhanced edit
285
enhanced_edit = EnhancedLineEdit(edit, cb)
286
self._enhanced_edits[edit] = enhanced_edit
290
390
"""Return the name input."""
423
523
"""Create a new wizard."""
424
524
QWizard.__init__(self, parent)
525
# store common useful data provided by the app
526
self.app_name = app_name
527
self.tos_url = tos_url
528
self.help_text = help_text
425
530
# set the diff pages of the QWizard
426
531
self.sign_in_controller = ChooseSignInController(title='Sign In')
427
532
self.sign_in_page = ChooseSignInPage(Ui_ChooseSignInPage(),
428
533
self.sign_in_controller,
430
self.setup_controller = SetUpAccountController(app_name=app_name,
535
self.setup_controller = SetUpAccountController()
432
536
self.setup_account = SetupAccountPage(Ui_SetUpAccountPage(),
433
537
self.setup_controller,
435
self.tos = TosPage(Ui_TosPage(), TosController())
539
self.tos = TosPage(Ui_TosPage(), TosController(tos_url=tos_url),
436
541
self.email_verification = EmailVerificationPage(
437
542
Ui_EmailVerificationPage(),
438
543
EmailVerificationController())
439
self.current_user_controller = CurrentUserController(title='Sign in',
544
self.current_user_controller = CurrentUserController(title='Sign in')
441
545
self.current_user = CurrentUserSignInPage(Ui_CurrentUserSignInPage(),
442
546
self.current_user_controller,
447
551
self.error_controller = ErrorController()
448
552
self.error = ErrorPage(Ui_ErrorPage(), self.error_controller)
553
self.forgotte_pwd_controller = ForgottenPasswordController()
554
self.forgotten = ForgottenPasswordPage(Ui_ForgottenPasswordPage(),
555
self.forgotte_pwd_controller,
557
self.reset_password_controller = ResetPasswordController()
558
self.reset_password = ResetPasswordPage(Ui_ResetPasswordPage(),
559
self.reset_password_controller,
449
561
# store the ids of the pages so that it is easier to access them later
451
563
for page in [self.sign_in_page, self.setup_account, self.tos,
452
564
self.email_verification, self.current_user, self.success,
565
self.error, self.forgotten, self.reset_password]:
454
566
self._pages[page] = self.addPage(page)
456
568
# set the buttons layout to only have cancel and back since the next
507
625
class UbuntuSSOClientGUI(object):
508
626
"""Ubuntu single sign-on GUI."""
510
def __init__(self, app_name, tc_url='', help_text='',
628
def __init__(self, app_name, tc_url='http://one.ubuntu.com', help_text='',
511
629
window_id=0, login_only=False):
512
630
"""Create a new instance."""
513
631
# create the controller and the ui, then set the cb and call the show