156
158
self.message_box = message_box
157
159
self._title = title
159
def _set_translated_strings(self):
161
def _set_translated_strings(self, view):
160
162
"""Set the translated strings."""
161
163
logger.debug('CurrentUserController._set_translated_strings')
162
self.view.ui.email_edit.setPlaceholderText(EMAIL1_ENTRY)
163
self.view.ui.password_edit.setPlaceholderText(PASSWORD1_ENTRY)
164
self.view.ui.forgot_password_label.setText(
164
view.email_edit.setPlaceholderText(EMAIL1_ENTRY)
165
view.password_edit.setPlaceholderText(PASSWORD1_ENTRY)
166
view.forgot_password_label.setText(
165
167
FAKE_URL % FORGOTTEN_PASSWORD_BUTTON)
166
self.view.ui.sign_in_button.setText(SIGN_IN_BUTTON)
168
view.sign_in_button.setText(SIGN_IN_BUTTON)
168
def _connect_ui(self):
170
def _connect_ui(self, view, backend):
169
171
"""Connect the buttons to perform actions."""
170
172
logger.debug('CurrentUserController._connect_buttons')
171
self.view.ui.sign_in_button.clicked.connect(self.login)
173
view.sign_in_button.clicked.connect(lambda: self.login(view, backend))
172
174
# lets add call backs to be execute for the calls we are interested
173
self.backend.on_login_error_cb = lambda app, error:\
174
self.on_login_error(error)
175
self.backend.on_logged_in_cb = self.on_logged_in
176
self.view.ui.forgot_password_label.linkActivated.connect(
177
self.on_forgotten_password)
175
backend.on_login_error_cb = lambda app, error:\
176
self.on_login_error(view, error)
177
backend.on_logged_in_cb = lambda app, result:\
178
self.on_logged_in(view, app, result)
179
view.forgot_password_label.linkActivated.connect(lambda link:\
180
self.on_forgotten_password(view))
180
"""Perform the login using the self.backend."""
182
def login(self, view, backend):
183
"""Perform the login using the backend."""
181
184
logger.debug('CurrentUserController.login')
182
185
# grab the data from the view and call the backend
183
email = str(self.view.ui.email_edit.text())
184
password = str(self.view.ui.password_edit.text())
185
d = self.backend.login(self.view.wizard().app_name, email, password)
186
d.addErrback(self.on_login_error)
186
d = backend.login(view.wizard().app_name, view.email, view.password)
187
d.addErrback(lambda e: self.on_login_error(view, e))
188
def on_login_error(self, error):
189
def on_login_error(self, view, error):
189
190
"""There was an error when login in."""
190
191
# let the user know
191
192
logger.error('Got error when login %s, error: %s',
192
self.view.wizard().app_name, error)
193
self.message_box.critical(self.view, self.view.wizard().app_name,
193
view.wizard().app_name, error)
194
self.message_box.critical(view, view.wizard().app_name, str(error))
196
def on_logged_in(self, app_name, result):
197
def on_logged_in(self, view, app_name, result):
197
198
"""We managed to log in."""
198
199
logger.info('Logged in for %s', app_name)
199
email = str(self.view.ui.email_edit.text())
200
self.view.wizard().loginSuccess.emit(app_name, email)
200
view.wizard().loginSuccess.emit(app_name, view.email)
201
201
logger.debug('Wizard.loginSuccess emitted.')
203
def on_forgotten_password(self):
203
def on_forgotten_password(self, view):
204
204
"""Show the user the forgotten password page."""
205
205
logger.info('Forgotten password')
206
self.view.next = self.view.wizard().forgotten_password_page_id
207
self.view.wizard().next()
206
view.next = view.wizard().forgotten_password_page_id
209
209
# use an ugly name just so have a simlar api as found in PyQt
210
210
#pylint: disable=C0103
212
212
def setupUi(self, view):
213
213
"""Setup the view."""
215
self.backend = yield self.get_backend()
216
self.view.setTitle(self._title)
217
self._set_translated_strings()
214
backend = yield self.get_backend()
215
view.setTitle(self._title)
216
self._set_translated_strings(view)
217
self._connect_ui(view, backend)
219
218
#pylint: enable=C0103
229
228
message_box = QMessageBox
230
229
self.message_box = message_box
232
def _set_translated_strings(self):
231
def _set_translated_strings(self, view):
233
232
"""Set the different gettext translated strings."""
234
233
logger.debug('SetUpAccountController._set_translated_strings')
235
234
# set the translated string
236
self.view.ui.name_label.setText(NAME_ENTRY)
237
self.view.ui.email_label.setText(EMAIL1_ENTRY)
238
self.view.ui.confirm_email_label.setText(EMAIL2_ENTRY)
239
self.view.ui.password_label.setText(PASSWORD1_ENTRY)
240
self.view.ui.confirm_password_label.setText(PASSWORD2_ENTRY)
241
self.view.ui.password_info_label.setText(PASSWORD_HELP)
242
self.view.ui.captcha_solution_edit.setPlaceholderText(
243
CAPTCHA_SOLUTION_ENTRY)
244
self.view.ui.terms_checkbox.setText(
245
YES_TO_TC % {'app_name': self.view.wizard().app_name})
246
self.view.ui.terms_button.setText(TC_BUTTON)
247
self.view.ui.set_up_button.setText(SET_UP_ACCOUNT_BUTTON)
235
view.name_edit.setPlaceholderText(NAME_ENTRY)
236
view.last_name_edit.setPlaceholderText(SURNAME_ENTRY)
237
view.email_edit.setPlaceholderText(EMAIL1_ENTRY)
238
view.confirm_email_edit.setPlaceholderText(EMAIL2_ENTRY)
239
view.password_edit.setPlaceholderText(PASSWORD1_ENTRY)
240
view.confirm_password_edit.setPlaceholderText(PASSWORD2_ENTRY)
241
view.password_info_label.setText(PASSWORD_HELP)
242
view.captcha_solution_edit.setPlaceholderText(CAPTCHA_SOLUTION_ENTRY)
243
view.terms_and_conditions_check_box.setText(
244
YES_TO_TC % {'app_name': view.wizard().app_name})
245
view.terms_and_conditions_button.setText(TC_BUTTON)
246
view.set_up_button.setText(SET_UP_ACCOUNT_BUTTON)
249
def _set_line_edits_validations(self):
248
def _set_line_edits_validations(self, view):
250
249
"""Set the validations to be performed on the edits."""
251
250
logger.debug('SetUpAccountController._set_line_edits_validations')
252
self.view.set_line_edit_validation_rule(self.view.ui.email_edit,
251
view.set_line_edit_validation_rule(view.email_edit, is_correct_email)
254
252
# set the validation rule for the email confirmation
255
self.view.set_line_edit_validation_rule(
256
self.view.ui.confirm_email_edit,
257
self.is_correct_email_confirmation)
253
view.set_line_edit_validation_rule(view.confirm_email_edit,
254
lambda x: self.is_correct_email_confirmation(x, view))
258
255
# connect the changed text of the password to trigger a changed text
259
256
# in the confirm so that the validation is redone
260
self.view.ui.email_edit.textChanged.connect(
261
self.view.ui.confirm_email_edit.textChanged.emit)
262
self.view.set_line_edit_validation_rule(self.view.ui.password_edit,
263
is_min_required_password)
264
self.view.set_line_edit_validation_rule(
265
self.view.ui.confirm_password_edit,
266
self.is_correct_password_confirmation)
257
view.email_edit.textChanged.connect(
258
view.confirm_email_edit.textChanged.emit)
259
view.set_line_edit_validation_rule(view.password_edit,
260
is_min_required_password)
261
view.set_line_edit_validation_rule(view.confirm_password_edit,
262
lambda x: self.is_correct_password_confirmation(x, view))
267
263
# same as the above case, lets connect a signal to a signal
268
self.view.ui.password_edit.textChanged.connect(
269
self.view.ui.confirm_password_edit.textChanged.emit)
264
view.password_edit.textChanged.connect(
265
view.confirm_password_edit.textChanged.emit)
271
def _connect_ui_elements(self):
267
def _connect_ui_elements(self, view, backend):
272
268
"""Set the connection of signals."""
273
269
logger.debug('SetUpAccountController._connect_ui_elements')
274
self.view.ui.terms_button.clicked.connect(self.set_next_tos)
275
self.view.ui.set_up_button.clicked.connect(self.set_next_validation)
276
self.view.ui.terms_checkbox.stateChanged.connect(
277
self.view.ui.set_up_button.setEnabled)
278
self.view.ui.refresh_label.linkActivated.connect(lambda url: \
279
self._refresh_captcha())
270
view.terms_and_conditions_button.clicked.connect(
271
lambda: self.set_next_tos(view))
272
view.set_up_button.clicked.connect(lambda: self.set_next_validation(
274
view.password_edit.textChanged.connect(
275
lambda x: self.update_password_strength(x, view))
276
view.terms_and_conditions_check_box.stateChanged.connect(
277
view.set_up_button.setEnabled)
278
view.captcha_refresh_label.linkActivated.connect(lambda url:\
279
self._refresh_captcha(view, backend))
280
280
# set the callbacks for the captcha generation
281
self.backend.on_captcha_generated_cb = self.on_captcha_generated
282
self.backend.on_captcha_generation_error_cb = lambda app, error: \
283
self.on_captcha_generation_error(error)
284
self.backend.on_user_registered_cb = self.on_user_registered
285
self.backend.on_user_registration_error_cb = \
286
self.on_user_registration_error
281
backend.on_captcha_generated_cb = lambda app, result:\
282
self.on_captcha_generated(view, app, result)
283
backend.on_captcha_generation_error_cb = lambda app, error:\
284
self.on_captcha_generation_error(view, error)
285
backend.on_user_registered_cb = lambda app, result:\
286
self.on_user_registered(view, app, result)
287
backend.on_user_registration_error_cb = lambda app, error:\
288
self.on_user_registration_error(view, app, error)
288
def _refresh_captcha(self):
291
def _refresh_captcha(self, view, backend):
289
292
"""Refresh the captcha image shown in the ui."""
290
293
logger.debug('SetUpAccountController._refresh_captcha')
291
294
# lets clean behind us, do we have the old file arround?
293
if self.view.captcha_file and os.path.exists(self.view.captcha_file):
294
old_file = self.view.captcha_file
296
if view.captcha_file and os.path.exists(view.captcha_file):
297
old_file = view.captcha_file
295
298
fd = tempfile.TemporaryFile(mode='r')
296
299
file_name = fd.name
297
self.view.captcha_file = file_name
298
d = self.backend.generate_captcha(self.view.wizard().app_name,
300
view.captcha_file = file_name
301
d = backend.generate_captcha(view.wizard().app_name, file_name)
301
303
d.addCallback(lambda x: os.unlink(old_file))
302
d.addErrback(self.on_captcha_generation_error)
304
d.addErrback(lambda e: self.on_captcha_generation_error(view, e))
304
def _set_titles(self):
306
def _set_titles(self, view):
305
307
"""Set the diff titles of the view."""
306
308
logger.debug('SetUpAccountController._set_titles')
307
wizard = self.view.wizard()
308
self.view.setTitle(JOIN_HEADER_LABEL % {'app_name': wizard.app_name})
309
self.view.setSubTitle(wizard.help_text)
311
def _register_fields(self):
312
"""Register the diff fields of the Ui."""
313
self.view.registerField('email_address', self.view.ui.email_edit)
314
self.view.registerField('password', self.view.ui.password_edit)
316
def on_captcha_generated(self, app_name, result):
309
wizard = view.wizard()
310
view.setTitle(JOIN_HEADER_LABEL % {'app_name': wizard.app_name})
311
view.setSubTitle(wizard.help_text)
313
def on_captcha_generated(self, view, app_name, result):
317
314
"""A new image was generated."""
318
315
logger.debug('SetUpAccountController.on_captcha_generated')
319
self.view.captcha_id = result
316
view.captcha_id = result
320
317
# HACK: First, let me apologize before hand, you can mention my mother
321
318
# if needed I would do the same (mandel)
322
319
# In an ideal world we could use the Qt plug-in for the images so that
323
320
# we could load jpgs etc.. but this won't work when the app has been
324
# brozen win py2exe using bundle_files=1
321
# frozen win py2exe using bundle_files=1
325
322
# The main issue is that Qt will complain about the thread not being
326
323
# the correct one when performing a moveToThread operation which is
327
324
# done either by a setParent or something within the qtreactor, PIL
328
325
# in this case does solve the issue. Sorry :(
329
pil_image = Image.open(self.view.captcha_file)
326
pil_image = Image.open(view.captcha_file)
330
327
string_io = StringIO.StringIO()
331
328
pil_image.save(string_io, format='png')
332
329
pixmap_image = QPixmap()
333
330
pixmap_image.loadFromData(string_io.getvalue())
334
self.view.captcha_image = pixmap_image
331
view.captcha_image = pixmap_image
336
def on_captcha_generation_error(self, error):
333
def on_captcha_generation_error(self, view, error):
337
334
"""An error ocurred."""
338
335
logger.debug('SetUpAccountController.on_captcha_generation_error')
339
self.message_box.critical(self.view, self.view.wizard().app_name,
336
self.message_box.critical(view, view.wizard().app_name, str(error))
342
def on_user_registration_error(self, app_name, error):
338
def on_user_registration_error(self, view, app_name, error):
343
339
"""Let the user know we could not register."""
344
340
logger.debug('SetUpAccountController.on_user_registration_error')
345
341
# error are returned as a dict with the data we want to show.
346
self.message_box.critical(self.view, error['errtype'], error['email'])
342
self.message_box.critical(view, error['errtype'], error['email'])
348
def on_user_registered(self, app_name, result):
345
def on_user_registered(self, view, app_name, result):
349
346
"""Execute when the user did register."""
350
347
logger.debug('SetUpAccountController.on_user_registered')
351
self.view.next = self.view.wizard().email_verification_page_id
352
self.view.wizard().next()
348
view.wizard().registrationSuccess.emit(app_name, view.email)
354
def set_next_tos(self):
350
def set_next_tos(self, view):
355
351
"""Set the tos page as the next one."""
356
352
logger.debug('SetUpAccountController.set_next_tos')
357
self.view.next = self.view.wizard().tos_page_id
358
self.view.wizard().next()
353
view.next = view.wizard().tos_page_id
360
def validate_form(self):
356
def validate_form(self, view):
361
357
"""Validate the info of the form and return an error."""
362
358
logger.debug('SetUpAccountController.validate_form')
363
email = str(self.view.ui.email_edit.text())
364
confirm_email = str(self.view.ui.confirm_email_edit.text())
365
password = str(self.view.ui.password_edit.text())
366
confirm_password = str(self.view.ui.confirm_password_edit.text())
367
if not is_correct_email(email):
368
self.message_box.critical(self.view, self.view.wizard().app_name,
359
if not is_correct_email(view.email):
360
self.message_box.critical(view, view.wizard().app_name,
370
if email != confirm_email:
371
self.message_box.critical(self.view, self.view.wizard().app_name,
362
if view.email_edit.text() != view.confirm_email_edit.text():
363
self.message_box.critical(view, view.wizard().app_name,
374
if not is_min_required_password(password):
375
self.message_box.critical(self.view, self.view.wizard().app_name,
366
if not is_min_required_password(str(view.password_edit.text())):
367
self.message_box.critical(view, view.wizard().app_name,
376
368
PASSWORD_TOO_WEAK)
378
if password != confirm_password:
379
self.message_box.critical(self.view, self.view.wizard().app_name,
370
if view.password_edit.text() != view.confirm_password_edit.text():
371
self.message_box.critical(view, view.wizard().app_name,
380
372
PASSWORD_MISMATCH)
384
def set_next_validation(self):
376
def set_next_validation(self, view, backend):
385
377
"""Set the validation as the next page."""
386
378
logger.debug('SetUpAccountController.set_next_validation')
387
email = str(self.view.ui.email_edit.text())
388
password = str(self.view.ui.password_edit.text())
389
name = str(self.view.ui.name_edit.text())
390
captcha_id = self.view.captcha_id
391
captcha_solution = str(self.view.ui.captcha_solution_edit.text())
392
379
# validate the current info of the form, try to perform the action
393
380
# to register the user, and then move foward
394
if self.validate_form():
395
self.backend.register_user(self.view.wizard().app_name, email,
396
password, name, captcha_id,
381
if self.validate_form(view):
382
backend.register_user(view.wizard().app_name, view.email,
383
view.password, view.captcha_id,
384
view.captcha_solution)
385
view.next = view.wizard().email_verification_page_id
388
def update_password_strength(self, password, view):
389
"""Callback used to update the password strength UI code."""
390
logger.debug('SetUpAccountController.update_password_strength')
391
# get the strengh and then according to it color the frames
392
strength = get_password_strength(password)
393
logger.info('Password strength is %s', strength)
394
view.set_strength_level(strength, password)
400
396
def is_correct_email(self, email_address):
401
397
"""Return if the email is correct."""
402
398
logger.debug('SetUpAccountController.is_correct_email')
403
399
return '@' in email_address
405
def is_correct_email_confirmation(self, email_address):
401
def is_correct_email_confirmation(self, email_address, view):
406
402
"""Return that the email is the same."""
407
403
logger.debug('SetUpAccountController.is_correct_email_confirmation')
408
return self.view.ui.email_edit.text() == email_address
404
return view.email_edit.text() == email_address
410
def is_correct_password_confirmation(self, password):
406
def is_correct_password_confirmation(self, password, view):
411
407
"""Return that the passwords are correct."""
412
408
logger.debug('SetUpAccountController.is_correct_password_confirmation')
413
return self.view.ui.password_edit.text() == password
409
return view.password_edit.text() == password
415
411
#pylint: disable=C0103
417
413
def setupUi(self, view):
418
414
"""Setup the view."""
420
415
# request the backend to be used with the ui
421
self.backend = yield self.get_backend()
422
self._connect_ui_elements()
423
self._refresh_captcha()
425
self._set_translated_strings()
426
self._set_line_edits_validations()
427
self._register_fields()
416
backend = yield self.get_backend()
417
self._connect_ui_elements(view, backend)
418
self._refresh_captcha(view, backend)
419
self._set_titles(view)
420
self._set_translated_strings(view)
421
self._set_line_edits_validations(view)
428
422
#pylint: enable=C0103
441
434
#pylint: disable=C0103
442
435
def setupUi(self, view):
443
436
"""Set up the ui."""
445
self.view.setTitle(self._title)
446
self.view.setSubTitle(self._subtitle)
437
view.setTitle(self._title)
438
view.setSubTitle(self._subtitle)
447
439
# load the tos page
448
self.view.ui.terms_webkit.load(QUrl(self._tos_url))
440
view.webkit.load(QUrl(self._tos_url))
449
441
#pylint: enable=C0103
452
class EmailVerificationController(BackendController):
444
class EmailVerificationController(object):
453
445
"""Controller used for the verification page."""
455
def _set_translated_strings(self):
447
def _set_translated_strings(self, view):
456
448
"""Set the trnaslated strings."""
457
449
logger.debug('EmailVerificationController._set_translated_strings')
458
self.view.ui.verification_code_edit.setPlaceholderText(
450
view.verification_code_edit.setPlaceholderText(VERIFY_EMAIL_TITLE)
461
def _connect_ui_elements(self):
452
def _connect_ui_elements(self, view):
462
453
"""Set the connection of signals."""
463
454
logger.debug('EmailVerificationController._connect_ui_elements')
464
self.view.next_button.clicked.connect(self.validate_email)
465
self.backend.on_email_validated_cb = lambda app, result: \
466
self.on_email_validated(app)
467
self.backend.on_email_validation_error_cb = \
468
self.on_email_validation_error
455
view.next_button.clicked.connect(lambda: self.next_page(view))
470
def _set_titles(self):
457
def _set_titles(self, view):
471
458
"""Set the different titles."""
472
459
logger.debug('EmailVerificationController._set_titles')
473
self.view.setTitle(VERIFY_EMAIL_TITLE)
474
self.view.setSubTitle(VERIFY_EMAIL_CONTENT)
460
view.setTitle(VERIFY_EMAIL_TITLE)
461
view.setSubTitle(VERIFY_EMAIL_CONTENT)
476
463
#pylint: disable=C0103
478
464
def setupUi(self, view):
479
465
"""Setup the view."""
481
self.backend = yield self.get_backend()
483
self._set_translated_strings()
484
self._connect_ui_elements()
466
self._set_titles(view)
467
self._set_translated_strings(view)
468
self._connect_ui_elements(view)
485
469
#pylint: enable=C0103
487
def validate_email(self):
471
def next_page(self, view):
488
472
"""Call the next action."""
489
logger.debug('EmailVerificationController.validate_email')
490
email = str(self.view.wizard().field('email_address').toString())
491
password = str(self.view.wizard().field('password').toString())
492
code = str(self.view.ui.verification_code_edit.text())
493
self.backend.validate_email(self.view.wizard().app_name, email,
496
def on_email_validated(self, app_name):
497
"""Signal thrown after the email is validated."""
498
logger.info('EmailVerificationController.on_email_validated')
499
email = self.view.wizard().field('email_address').toString()
500
self.view.wizard().registrationSuccess.emit(app_name, email)
502
def on_email_validation_error(self, app_name, raised_error):
503
"""Signal thrown when there's a problem validating the email."""
473
logger.debug('EmailVerificationController.next_page')
506
477
class ErrorController(object):
527
495
"""Create a new instance."""
528
496
super(ForgottenPasswordController, self).__init__()
530
def _register_fields(self):
498
def _register_fields(self, view):
531
499
"""Register the fields of the wizard page."""
532
self.view.registerField('email_address',
533
self.view.email_address_line_edit)
500
view.registerField('email_address', view.email_address_line_edit)
535
def _set_translated_strings(self):
502
def _set_translated_strings(self, view):
536
503
"""Set the translated strings in the view."""
537
self.view.forgotted_password_intro_label.setText(
504
view.forgotted_password_intro_label.setText(
538
505
REQUEST_PASSWORD_TOKEN_LABEL % {'app_name':
539
self.view.wizard().app_name})
540
self.view.email_address_label.setText(EMAIL_LABEL)
541
self.view.send_button.setText(RESET_PASSWORD)
542
self.view.try_again_button.setText(TRY_AGAIN_BUTTON)
506
view.wizard().app_name})
507
view.email_address_label.setText(EMAIL_LABEL)
508
view.send_button.setText(RESET_PASSWORD)
509
view.try_again_button.setText(TRY_AGAIN_BUTTON)
544
def _set_enhanced_line_edit(self):
511
def _set_enhanced_line_edit(self, view):
545
512
"""Set the extra logic to the line edits."""
546
self.view.set_line_edit_validation_rule(
547
self.view.email_address_line_edit,
513
view.set_line_edit_validation_rule(view.email_address_line_edit,
548
514
is_correct_email)
550
def _connect_ui(self):
516
def _connect_ui(self, view, backend):
551
517
"""Connect the diff signals from the Ui."""
552
self.view.send_button.clicked.connect(
553
lambda: self.backend.request_password_reset_token(
554
self.view.wizard().app_name,
555
self.view.email_address))
556
self.view.try_again_button.clicked.connect(self.on_try_again)
518
view.send_button.clicked.connect(
519
lambda: backend.request_password_reset_token(
520
view.wizard().app_name,
522
view.try_again_button.clicked.connect(lambda: self.on_try_again(view))
557
523
# set the backend callbacks to be used
558
self.backend.on_password_reset_token_sent_cb = lambda app, result:\
559
self.on_password_reset_token_sent()
560
self.backend.on_password_reset_error_cb = self.on_password_reset_error
524
backend.on_password_reset_token_sent_cb = lambda app, result:\
525
self.on_password_reset_token_sent(view)
526
backend.on_password_reset_error_cb = lambda app_name, error:\
527
self.on_password_reset_error(app_name,
562
def on_try_again(self):
531
def on_try_again(self, view):
563
532
"""Set back the widget to the initial state."""
564
self.view.error_label.setVisible(False)
565
self.view.try_again_widget.setVisible(False)
566
self.view.email_widget.setVisible(True)
533
view.error_label.setVisible(False)
534
view.try_again_widget.setVisible(False)
535
view.email_widget.setVisible(True)
568
def on_password_reset_token_sent(self):
537
def on_password_reset_token_sent(self, view):
569
538
"""Action taken when we managed to get the password reset done."""
570
539
# ignore the result and move to the reset page
571
self.view.next = self.view.wizard().reset_password_page_id
572
self.view.wizard().next()
540
view.next = view.wizard().reset_password_page_id
574
def on_password_reset_error(self, app_name, error):
543
def on_password_reset_error(self, app_name, error, view):
575
544
"""Action taken when there was an error requesting the reset."""
576
545
if error['errtype'] == 'ResetPasswordTokenError':
577
546
# the account provided is wrong, lets tell the user to try
579
self.view.error_label.setText(REQUEST_PASSWORD_TOKEN_WRONG_EMAIL)
580
self.view.error_label.setVisible(True)
548
view.error_label.setText(REQUEST_PASSWORD_TOKEN_WRONG_EMAIL)
549
view.error_label.setVisible(True)
582
551
# ouch, I dont know what went wrong, tell the user to try later
583
self.view.email_widget.setVisible(False)
584
self.view.forgotted_password_intro_label.setVisible(False)
585
self.view.try_again_wisget.setVisible(True)
552
view.email_widget.setVisible(False)
553
view.forgotted_password_intro_label.setVisible(False)
554
view.try_again_wisget.setVisible(True)
586
555
# set the error message
587
self.view.error_label.setText(REQUEST_PASSWORD_TOKEN_TECH_ERROR)
556
view.error_label.setText(REQUEST_PASSWORD_TOKEN_TECH_ERROR)
589
558
#pylint: disable=C0103
591
560
def setupUi(self, view):
592
561
"""Setup the view."""
594
self.backend = yield self.get_backend()
562
backend = yield self.get_backend()
595
563
# hide the error label
596
self.view.error_label.setVisible(False)
597
self.view.try_again_widget.setVisible(False)
598
self._set_translated_strings()
600
self._set_enhanced_line_edit()
601
self._register_fields()
564
view.error_label.setVisible(False)
565
view.try_again_widget.setVisible(False)
566
self._set_translated_strings(view)
567
self._connect_ui(view, backend)
568
self._set_enhanced_line_edit(view)
569
self._register_fields(view)
602
570
#pylint: enable=C0103
609
577
"""Create a new instance."""
610
578
super(ResetPasswordController, self).__init__()
612
def _set_translated_strings(self):
580
def _set_translated_strings(self, view):
613
581
"""Translate the diff strings used in the app."""
614
self.view.ui.reset_code_line_edit.setPlaceholderText(RESET_CODE_ENTRY)
615
self.view.ui.password_line_edit.setPlaceholderText(PASSWORD1_ENTRY)
616
self.view.ui.confirm_password_line_edit.setPlaceholderText(
618
self.view.ui.reset_password_button.setText(RESET_PASSWORD)
619
self.view.setSubTitle(PASSWORD_HELP)
582
view.reset_code_line_edit.setPlaceholderText(RESET_CODE_ENTRY)
583
view.password_line_edit.setPlaceholderText(PASSWORD1_ENTRY)
584
view.confirm_password_line_edit.setPlaceholderText(PASSWORD2_ENTRY)
585
view.reset_password_button.setText(RESET_PASSWORD)
586
view.setSubTitle(PASSWORD_HELP)
621
def _connect_ui(self):
588
def _connect_ui(self, view, backend):
622
589
"""Connect the different ui signals."""
623
self.view.ui.reset_password_button.clicked.connect(
624
self.set_new_password)
625
self.backend.on_password_changed_cb = self.on_password_changed
626
self.backend.on_password_change_error_cb = \
627
self.on_password_change_error
590
view.reset_password_button.clicked.connect(
591
lambda: self.set_new_password(view, backend))
592
backend.on_password_changed_cb = lambda app, result:\
593
self.on_password_changed(app,
596
backend.on_password_change_error_cb = lambda app, error:\
597
self.on_password_change_error(app,
629
def _add_line_edits_validations(self):
601
def _add_line_edits_validations(self, view):
630
602
"""Add the validations to be use by the line edits."""
631
self.view.set_line_edit_validation_rule(
632
self.view.ui.password_line_edit,
603
view.set_line_edit_validation_rule(view.password_line_edit,
633
604
is_min_required_password)
634
self.view.set_line_edit_validation_rule(
635
self.view.ui.confirm_password_line_edit,
636
self.is_correct_password_confirmation)
605
view.set_line_edit_validation_rule(view.confirm_password_line_edit,
606
lambda x: self.is_correct_password_confirmation(x, view))
637
607
# same as the above case, lets connect a signal to a signal
638
self.view.ui.password_line_edit.textChanged.connect(
639
self.view.ui.confirm_password_line_edit.textChanged.emit)
608
view.password_line_edit.textChanged.connect(
609
view.confirm_password_line_edit.textChanged.emit)
641
def on_password_changed(self, app_name, result):
611
def on_password_changed(self, app_name, result, view):
642
612
"""Let user know that the password was changed."""
644
def on_password_change_error(self, app_name, error):
614
def on_password_change_error(self, app_name, error, view):
645
615
"""Let the user know that there was an error."""
647
def set_new_password(self):
617
def set_new_password(self, view, backend):
648
618
"""Request a new password to be set."""
649
app_name = self.view.wizard().app_name
650
email = str(self.view.wizard().field('email_address').toString())
651
code = str(self.view.ui.reset_code_line_edit.text())
652
password = str(self.view.ui.password_line_edit.text())
619
app_name = view.wizard().app_name
620
email = str(view.wizard().field('email_address').toString())
621
code = view.reset_code
653
622
logger.info('Settig new password for %s and email %s with code %s',
654
623
app_name, email, code)
655
self.backend.set_new_password(app_name, email, code, password)
624
backend.set_new_password(app_name, email, code, view.password)
657
def is_correct_password_confirmation(self, password):
626
def is_correct_password_confirmation(self, password, view):
658
627
"""Return if the password is correct."""
659
return self.view.ui.password_line_edit.text() == password
628
return view.password_line_edit.text() == password
661
630
#pylint: disable=C0103
663
632
def setupUi(self, view):
664
633
"""Setup the view."""
666
self.backend = yield self.get_backend()
667
self._set_translated_strings()
669
self._add_line_edits_validations()
634
backend = yield self.get_backend()
635
self._set_translated_strings(view)
636
self._connect_ui(view, backend)
637
self._add_line_edits_validations(view)
670
638
#pylint: enable=C0103
726
691
logger.debug('Result from callback is %s', result)
728
693
logger.info('Success in calling the given registration_callback')
729
self.show_success_message()
694
self.show_success_message(view)
731
696
logger.info('Success in calling the given registration_callback')
732
self.show_error_message()
734
def show_success_message(self):
697
self.show_error_message(view)
699
def show_error_message(self, view):
700
"""Show the error page in the view."""
701
logger.info('Showing error message.')
702
# similar to the success page but using the error id
703
view.currentPage().next = view.error_page_id
705
# show the finish button but with a close message
707
buttons_layout.append(QWizard.Stretch)
708
buttons_layout.append(QWizard.FinishButton)
709
view.setButtonLayout(buttons_layout)
711
def show_success_message(self, view):
735
712
"""Show the success message in the view."""
736
713
logger.info('Showing success message.')
737
714
# get the id of the success page, set it as the next id of the
738
715
# current page and let the wizard move to the next step
739
self.view.currentPage().next = self.view.success_page_id
741
# show the finish button but with a close message
743
buttons_layout.append(QWizard.Stretch)
744
buttons_layout.append(QWizard.FinishButton)
745
self.view.setButtonLayout(buttons_layout)
747
def show_error_message(self):
748
"""Show the error page in the view."""
749
logger.info('Showing error message.')
750
# similar to the success page but using the error id
751
self.view.currentPage().next = self.view.error_page_id
753
# show the finish button but with a close message
755
buttons_layout.append(QWizard.Stretch)
756
buttons_layout.append(QWizard.FinishButton)
757
self.view.setButtonLayout(buttons_layout)
716
view.currentPage().next = view.success_page_id
718
# show the finish button but with a close message
720
buttons_layout.append(QWizard.Stretch)
721
buttons_layout.append(QWizard.FinishButton)
722
view.setButtonLayout(buttons_layout)
759
724
#pylint: disable=C0103
760
725
def setupUi(self, view):
761
726
"""Setup the view."""
763
self.view.setWizardStyle(QWizard.ModernStyle)
764
self.view.button(QWizard.CancelButton).clicked.connect(
765
self.on_user_cancelation)
766
self.view.loginSuccess.connect(self.on_login_success)
767
self.view.registrationSuccess.connect(self.on_registration_success)
727
view.setWizardStyle(QWizard.ModernStyle)
728
view.button(QWizard.CancelButton).clicked.connect(
729
lambda: self.on_user_cancelation(view))
730
view.loginSuccess.connect(
731
lambda app, email: self.on_login_success(app, email, view))
732
view.registrationSuccess.connect(
733
lambda app, email: self.on_registration_success(app, email, view))
768
734
#pylint: enable=C0103