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

« back to all changes in this revision

Viewing changes to ubuntu_sso/qt/gui.py

  • Committer: Tarmac
  • Author(s): Manuel de la Pena, ralsina, Roberto Alsina
  • Date: 2011-04-14 17:01:56 UTC
  • mfrom: (705.2.2 forgotten_password)
  • Revision ID: tarmac-20110414170156-4k8s1708gzgj5oi2
Fixes lp:753281

Adds the required UI and backend to allow a windows user to reset his sso password from the Windows client. Tests have been added to ensure that the backend is correctly called.

Show diffs side-by-side

added added

removed removed

Lines of Context:
19
19
from PyQt4.QtCore import pyqtSignal
20
20
from PyQt4.QtGui import (
21
21
    QApplication,
 
22
    QColor,
22
23
    QCursor,
23
24
    QHBoxLayout,
 
25
    QPalette,
24
26
    QPixmap,
25
27
    QPushButton,
26
28
    QStyle,
54
56
 
55
57
logger = setup_logging('ubuntu_sso.gui')
56
58
 
 
59
# colors used to define the password stenght
 
60
WEAK_COLOR = QColor(220, 20, 60)
 
61
MEDIUM_COLOR = QColor(255, 215, 0)
 
62
STRONG_COLOR = QColor(50, 205, 50)
 
63
 
57
64
 
58
65
class SSOWizardPage(QWizardPage):
59
66
    """Root class for all wizard pages."""
134
141
        """Create a new widget to be used."""
135
142
        SSOWizardPage.__init__(self, ui, controller, parent)
136
143
 
 
144
    # allow to access to the different useful children
 
145
    @property
 
146
    def existing_account_button(self):
 
147
        """Return the button used to sign in using an existing account."""
 
148
        return self.ui.existing_account_button
 
149
 
 
150
    @property
 
151
    def new_account_button(self):
 
152
        """Return the button used to sign in with a new account."""
 
153
        return self.ui.setup_account_button
 
154
 
137
155
 
138
156
class CurrentUserSignInPage(SSOWizardPage):
139
157
    """Widget that allows to get the data of user to sign in."""
142
160
        """Create a new widget to be used."""
143
161
        SSOWizardPage.__init__(self, ui, controller, parent)
144
162
 
 
163
    # allow to access to the different useful data
 
164
    @property
 
165
    def email(self):
 
166
        """Return the email data in the edit field."""
 
167
        return str(self.ui.email_edit.text())
 
168
 
 
169
    @property
 
170
    def email_edit(self):
 
171
        """Return the email edit that is used in the view."""
 
172
        return self.ui.email_edit
 
173
 
 
174
    @property
 
175
    def password(self):
 
176
        """Return the password data in the edit field."""
 
177
        return str(self.ui.password_edit.text())
 
178
 
 
179
    @property
 
180
    def password_edit(self):
 
181
        """Return the password edit used in the view."""
 
182
        return self.ui.password_edit
 
183
 
 
184
    @property
 
185
    def forgot_password_label(self):
 
186
        """Return the forgot password label."""
 
187
        return self.ui.forgot_label
 
188
 
 
189
    @property
 
190
    def sign_in_button(self):
 
191
        """Return the sign in button."""
 
192
        return self.ui.sign_in_button
 
193
 
145
194
 
146
195
class EmailVerificationPage(SSOWizardPage):
147
196
    """Widget used to input the email verification code."""
156
205
        return str(self.ui.verification_code_edit.text())
157
206
 
158
207
    @property
 
208
    def verification_code_edit(self):
 
209
        """Return the edit used for the verification code."""
 
210
        return self.ui.verification_code_edit
 
211
 
 
212
    @property
159
213
    def next_button(self):
160
214
        """Return the button that move to the next stage."""
161
215
        return self.ui.next_button
167
221
    def __init__(self, ui, controller, parent=None):
168
222
        """Create a new widget to be used."""
169
223
        SSOWizardPage.__init__(self, ui, controller, parent)
 
224
        self.ui = ui
 
225
        self.ui.setupUi(self)
 
226
        self.controller = controller
 
227
        self.controller.setupUi(self)
 
228
        self.next = -1
 
229
 
 
230
    # pylint: disable=C0103
 
231
    def nextId(self):
 
232
        """Return the next page id."""
 
233
        return self.next
 
234
    # pylint: enable=C0103
 
235
 
 
236
    @property
 
237
    def error_message_label(self):
 
238
        """Return the label used to show the error."""
 
239
        return self.ui.error_message_label
170
240
 
171
241
 
172
242
class ForgottenPasswordPage(SSOWizardEnhancedEditPage):
229
299
        """Create a new instance."""
230
300
        SSOWizardEnhancedEditPage.__init__(self, ui, controller, parent)
231
301
 
 
302
    @property
 
303
    def reset_code_line_edit(self):
 
304
        """Return the  line edit where the reset code is given."""
 
305
        return self.ui.reset_code_line_edit
 
306
 
 
307
    @property
 
308
    def reset_code(self):
 
309
        """Return the reset code typed by the user."""
 
310
        return str(self.ui.reset_code_line_edit.text())
 
311
 
 
312
    @property
 
313
    def password_line_edit(self):
 
314
        """Return the line edit where the password is typed."""
 
315
        return self.ui.password_line_edit
 
316
 
 
317
    @property
 
318
    def password(self):
 
319
        """Return the passsword typed by the user."""
 
320
        return str(self.ui.password_line_edit.text())
 
321
 
 
322
    @property
 
323
    def confirm_password_line_edit(self):
 
324
        """Return the line edit used to confirm the password."""
 
325
        return self.ui.confirm_password_line_edit
 
326
 
 
327
    @property
 
328
    def retyped_password(self):
 
329
        """Return the password confirmation given by the user."""
 
330
        return str(self.ui.confirm_password_line_edit.text())
 
331
 
 
332
    @property
 
333
    def reset_password_button(self):
 
334
        """Return the button used to reset the password."""
 
335
        return self.ui.reset_password_button
 
336
 
232
337
 
233
338
class TosPage(SSOWizardPage):
234
339
    """Widget used to show the tos."""
237
342
        """Create a new instance."""
238
343
        SSOWizardPage.__init__(self, ui, controller, parent)
239
344
 
 
345
    @property
 
346
    def webkit(self):
 
347
        """Return the webkit widget used to load the terms."""
 
348
        return self.ui.terms_webkit
 
349
 
240
350
 
241
351
class SetupAccountPage(SSOWizardEnhancedEditPage):
242
352
    """Widget used to create a new account."""
245
355
        """Create a new widget to be used."""
246
356
        SSOWizardEnhancedEditPage.__init__(self, ui, controller, parent)
247
357
        self._enhanced_edits = {}
248
 
        # palettes that will be used to set the colors of the password strengh
 
358
        self.ui = ui
 
359
        self.ui.setupUi(self)
 
360
        # palettes that will be used to set the colors of the password strength
 
361
        original_palette = self.ui.strength_frame.palette()
 
362
        self._original_color = original_palette.background().color()
249
363
        self.captcha_id = None
250
364
        self.captcha_file = None
251
365
        self.ui.captcha_view.setPixmap(QPixmap())
 
366
        self.controller = controller
 
367
        self.controller.setupUi(self)
 
368
 
 
369
    def set_strength_level(self, level, password):
 
370
        """Set the strength level colors."""
 
371
        if password != '':
 
372
            if level <= 1:
 
373
                # low password
 
374
                self._set_frame_color(self.ui.weak_frame, WEAK_COLOR)
 
375
                self._set_frame_color(self.ui.medium_frame,
 
376
                                      self._original_color)
 
377
                self._set_frame_color(self.ui.strong_frame,
 
378
                                      self._original_color)
 
379
            elif level <= 3:
 
380
                # medium password
 
381
                self._set_frame_color(self.ui.weak_frame, MEDIUM_COLOR)
 
382
                self._set_frame_color(self.ui.medium_frame, MEDIUM_COLOR)
 
383
                self._set_frame_color(self.ui.strong_frame,
 
384
                                      self._original_color)
 
385
            else:
 
386
                # nice!
 
387
                self._set_frame_color(self.ui.weak_frame, STRONG_COLOR)
 
388
                self._set_frame_color(self.ui.medium_frame, STRONG_COLOR)
 
389
                self._set_frame_color(self.ui.strong_frame, STRONG_COLOR)
 
390
        else:
 
391
            # set it to the minimum
 
392
            self._set_frame_color(self.ui.weak_frame, self._original_color)
 
393
            self._set_frame_color(self.ui.medium_frame, self._original_color)
 
394
            self._set_frame_color(self.ui.strong_frame, self._original_color)
 
395
 
 
396
    def _set_frame_color(self, frame, color):
 
397
        """Set the color of a frame to indicated a strength."""
 
398
        # change the color background for the given frame
 
399
        palette = frame.palette()
 
400
        palette.setColor(QPalette.Background, color)
 
401
        frame.setPalette(palette)
 
402
        frame.setAutoFillBackground(True)
 
403
 
 
404
    @property
 
405
    def name(self):
 
406
        """Return the name input."""
 
407
        return str(self.ui.first_name_edit.text())
 
408
 
 
409
    @property
 
410
    def name_edit(self):
 
411
        """Return the edit used for the name."""
 
412
        return self.ui.first_name_edit
 
413
 
 
414
    @property
 
415
    def last_name(self):
 
416
        """Return the last name input."""
 
417
        return str(self.ui.last_name_edit.text())
 
418
 
 
419
    @property
 
420
    def last_name_edit(self):
 
421
        """Return the edit used for the last name."""
 
422
        return self.ui.last_name_edit
 
423
 
 
424
    @property
 
425
    def email(self):
 
426
        """Return the email input."""
 
427
        return str(self.ui.email_edit.text())
 
428
 
 
429
    @property
 
430
    def email_edit(self):
 
431
        """Return the edit used for the email."""
 
432
        return self.ui.email_edit
 
433
 
 
434
    @property
 
435
    def retyped_email(self):
 
436
        """Return the retyped email."""
 
437
        return str(self.ui.confirm_email_edit.text())
 
438
 
 
439
    @property
 
440
    def confirm_email_edit(self):
 
441
        """Return the edit used for the retype of the email."""
 
442
        return self.ui.confirm_email_edit
 
443
 
 
444
    @property
 
445
    def password_info_label(self):
 
446
        """Return the password used to show the info of the label."""
 
447
        return self.ui.password_info_label
 
448
 
 
449
    @property
 
450
    def password(self):
 
451
        """Return the password data."""
 
452
        return str(self.ui.password_edit.text())
 
453
 
 
454
    @property
 
455
    def password_edit(self):
 
456
        """Return the edit used for the password."""
 
457
        return self.ui.password_edit
 
458
 
 
459
    @property
 
460
    def retyped_password(self):
 
461
        """Return the retyped password."""
 
462
        return str(self.ui.confirm_password_edit.text())
 
463
 
 
464
    @property
 
465
    def confirm_password_edit(self):
 
466
        """Return the edit used to confirm the password."""
 
467
        return self.ui.confirm_password_edit
 
468
 
 
469
    @property
 
470
    def captcha_refresh_label(self):
 
471
        """Return the refresh label."""
 
472
        return self.ui.refresh_label
 
473
 
 
474
    @property
 
475
    def captcha_solution(self):
 
476
        """Return the provided captcha solution."""
 
477
        return str(self.ui.captcha_solution_edit.text())
 
478
 
 
479
    @property
 
480
    def captcha_solution_edit(self):
 
481
        """Return the edit used for the captcha solution."""
 
482
        return self.ui.captcha_solution_edit
252
483
 
253
484
    def get_captcha_image(self):
254
485
        """Return the path to the captcha image."""
261
492
 
262
493
    captcha_image = property(get_captcha_image, set_captcha_image)
263
494
 
 
495
    @property
 
496
    def terms_and_conditions_agreed(self):
 
497
        """Return if the user agreed the terms."""
 
498
        return self.ui.terms_checkbox.isChecked()
 
499
 
 
500
    @property
 
501
    def terms_and_conditions_check_box(self):
 
502
        """Return the terms and codition item."""
 
503
        return self.ui.terms_checkbox
 
504
 
 
505
    @property
 
506
    def terms_and_conditions_button(self):
 
507
        """Return the terms and conditions button."""
 
508
        return self.ui.terms_button
 
509
 
 
510
    @property
 
511
    def set_up_button(self):
 
512
        """Return the set up button."""
 
513
        return self.ui.set_up_button
 
514
 
264
515
 
265
516
class SuccessPage(SSOWizardPage):
266
517
    """Page used to display success message."""
268
519
    def __init__(self, ui, controller, parent=None):
269
520
        """Create a new instance."""
270
521
        SSOWizardPage.__init__(self, ui, controller, parent)
 
522
        self.ui = ui
 
523
        self.ui.setupUi(self)
 
524
        self.controller = controller
 
525
        self.controller.setupUi(self)
 
526
        self.next = -1
 
527
 
 
528
    # pylint: disable=C0103
 
529
    def nextId(self):
 
530
        """Return the next page id."""
 
531
        return self.next
 
532
    # pylint: enable=C0103
 
533
 
 
534
    @property
 
535
    def success_message_label(self):
 
536
        """Return the label used to show the message."""
 
537
        return self.ui.success_message_label
271
538
 
272
539
 
273
540
class UbuntuSSOWizard(QWizard):