175
182
"""Perform the login using the backend."""
176
183
logger.debug('CurrentUserController.login')
177
184
# grab the data from the view and call the backend
178
d = backend.login(self._app_name, view.email, view.password)
179
d.addErrback(lambda e: self.on_login_error(view, self._app_name, e))
185
d = backend.login(view.wizard().app_name, view.email, view.password)
186
d.addErrback(lambda e: self.on_login_error(view, e))
181
def on_login_error(self, view, app_name, error):
188
def on_login_error(self, view, error):
182
189
"""There was an error when login in."""
183
190
# let the user know
184
191
logger.error('Got error when login %s, error: %s', app_name, error)
185
self.message_box.critical(view, app_name, str(error))
192
self.message_box.critical(view, view.wizard().app_name, str(error))
187
194
def on_logged_in(self, view, app_name, result):
188
195
"""We managed to log in."""
349
351
def validate_form(self, view):
350
352
"""Validate the info of the form and return an error."""
351
353
logger.debug('SetUpAccountController.validate_form')
352
if not self.is_correct_email(view.email):
353
self.message_box.critical(view, self._app_name, EMAIL_INVALID)
354
if not is_correct_email(view.email):
355
self.message_box.critical(view, view.wizard().app_name,
354
357
if view.email_edit.text() != view.confirm_email_edit.text():
355
self.message_box.critical(view, self._app_name, EMAIL_MISMATCH)
358
self.message_box.critical(view, view.wizard().app_name,
357
361
if not is_min_required_password(str(view.password_edit.text())):
358
self.message_box.critical(view, self._app_name, PASSWORD_TOO_WEAK)
362
self.message_box.critical(view, view.wizard().app_name,
360
365
if view.password_edit.text() != view.confirm_password_edit.text():
361
self.message_box.critical(view, self._app_name, PASSWORD_MISMATCH)
366
self.message_box.critical(view, view.wizard().app_name,
476
478
#pylint: enable=C0103
481
class ForgottenPasswordController(BackendController):
482
"""Controller used to deal with the forgotten pwd page."""
485
"""Create a new instance."""
486
super(ForgottenPasswordController, self).__init__()
488
def _register_fields(self, view):
489
"""Register the fields of the wizard page."""
490
view.registerField('email_address', view.email_address_line_edit)
492
def _set_translated_strings(self, view):
493
"""Set the translated strings in the view."""
494
view.forgotted_password_intro_label.setText(
495
REQUEST_PASSWORD_TOKEN_LABEL % {'app_name':
496
view.wizard().app_name})
497
view.email_address_label.setText(EMAIL_LABEL)
498
view.send_button.setText(RESET_PASSWORD)
499
view.try_again_button.setText(TRY_AGAIN_BUTTON)
501
def _set_enhanced_line_edir(self, view):
502
"""Set the extra logic to the line edits."""
503
view.set_line_edit_validation_rule(view.email_address_line_edit,
506
def _connect_ui(self, view, backend):
507
"""Connect the diff signals from the Ui."""
508
view.send_button.clicked.connect(
509
lambda: backend.request_password_reset_token(
510
view.wizard().app_name,
512
view.try_again_button.clicked.connect(lambda: self.on_try_again(view))
513
# set the backend callbacks to be used
514
backend.on_password_reset_token_sent_cb = lambda app, result:\
515
self.on_password_reset_token_sent(view)
516
backend.on_password_reset_error_cb = lambda app_name, error:\
517
self.on_password_reset_error(app_name,
521
def on_try_again(self, view):
522
"""Set back the widget to the initial state."""
523
view.error_label.setVisible(False)
524
view.try_again_widget.setVisible(False)
525
view.email_widget.setVisible(True)
527
def on_password_reset_token_sent(self, view):
528
"""Action taken when we managed to get the password reset done."""
529
# ignore the result and move to the reset page
530
view.next = view.wizard().reset_password_page_id
533
def on_password_reset_error(self, app_name, error, view):
534
"""Action taken when there was an error requesting the reset."""
535
if error['errtype'] == 'ResetPasswordTokenError':
536
# the account provided is wrong, lets tell the user to try
538
view.error_label.setText(REQUEST_PASSWORD_TOKEN_WRONG_EMAIL)
539
view.error_label.setVisible(True)
541
# ouch, I dont know what went wrong, lets tell the user to try later
542
view.email_widget.setVisible(False)
543
view.forgotted_password_intro_label.setVisible(False)
544
view.try_again_wisget.setVisible(True)
545
# set the error message
546
view.error_label.setText(REQUEST_PASSWORD_TOKEN_TECH_ERROR)
548
#pylint: disable=C0103
550
def setupUi(self, view):
551
"""Setup the view."""
552
backend = yield self.get_backend()
553
# hide the error label
554
view.error_label.setVisible(False)
555
view.try_again_widget.setVisible(False)
556
self._set_translated_strings(view)
557
self._connect_ui(view, backend)
558
self._set_enhanced_line_edir(view)
559
self._register_fields(view)
560
#pylint: enable=C0103
563
class ResetPasswordController(BackendController):
564
"""Controller used to deal with reseintg the password."""
567
"""Create a new instance."""
568
super(ResetPasswordController, self).__init__()
570
def _set_translated_strings(self, view):
571
"""Translate the diff strings used in the app."""
572
view.reset_code_line_edit.setPlaceholderText(RESET_CODE_ENTRY)
573
view.password_line_edit.setPlaceholderText(PASSWORD1_ENTRY)
574
view.confirm_password_line_edit.setPlaceholderText(PASSWORD2_ENTRY)
575
view.reset_password_button.setText(RESET_PASSWORD)
576
view.setSubTitle(PASSWORD_HELP)
578
def _connect_ui(self, view, backend):
579
"""Connect the different ui signals."""
580
view.reset_password_button.clicked.connect(
581
lambda: self.set_new_password(view, backend))
582
backend.on_password_changed_cb = lambda app, result:\
583
self.on_password_changed(app,
586
backend.on_password_change_error_cb = lambda app, error:\
587
self.on_password_change_error(app,
591
def _add_line_edits_validations(self, view):
592
"""Add the validations to be use by the line edits."""
593
view.set_line_edit_validation_rule(view.password_line_edit,
594
is_min_required_password)
595
view.set_line_edit_validation_rule(view.confirm_password_line_edit,
596
lambda x: self.is_correct_password_confirmation(x, view))
597
# same as the above case, lets connect a signal to a signal
598
view.password_line_edit.textChanged.connect(
599
view.confirm_password_line_edit.textChanged.emit)
601
def on_password_changed(self, app_name, result, view):
602
"""Let user know that the password was changed."""
604
def on_password_change_error(self, app_name, error, view):
605
"""Let the user know that there was an error."""
607
def set_new_password(self, view, backend):
608
"""Request a new password to be set."""
609
app_name = view.wizard().app_name
610
email = str(view.wizard().field('email_address').toString())
611
code = view.reset_code
612
logger.info('Settig new password for %s and email %s with code %s',
613
app_name, email, code)
614
backend.set_new_password(app_name, email, code, view.password)
616
def is_correct_password_confirmation(self, password, view):
617
"""Return if the password is correct."""
618
return view.password_line_edit.text() == password
620
#pylint: disable=C0103
622
def setupUi(self, view):
623
"""Setup the view."""
624
backend = yield self.get_backend()
625
self._set_translated_strings(view)
626
self._connect_ui(view, backend)
627
self._add_line_edits_validations(view)
628
#pylint: enable=C0103
479
631
class SuccessController(object):
480
632
"""Controller used for the success page."""