def _on_claim_clicked(self): # No try/except given `self.line_edit_device` has already been validated against `DeviceLabel` device_label = DeviceLabel( validators.trim_user_name(self.line_edit_device.text())) try: user_name = validators.trim_user_name( self.line_edit_user_full_name.text()) human_handle = HumanHandle(email=self.line_edit_user_email.text(), label=user_name) device_label = DeviceLabel(self.line_edit_device.text()) except ValueError as exc: show_error(self, _("TEXT_CLAIM_USER_INVALID_HUMAN_HANDLE"), exception=exc) return self.button_ok.setDisabled(True) self.widget_info.setDisabled(True) self.label_wait.show() self.claim_job = self.jobs_ctx.submit_job( self.claim_success, self.claim_error, self.claimer.claim_user, device_label=device_label, human_handle=human_handle, )
def _on_create_user_clicked(self): assert not self.create_user_job handle = None # No try/except given `self.line_edit_device` has already been validated against `DeviceLabel` device_label = DeviceLabel( validators.trim_user_name(self.line_edit_device.text())) try: user_name = validators.trim_user_name( self.line_edit_user_full_name.text()) handle = HumanHandle(label=user_name, email=self.line_edit_user_email.text()) except ValueError as exc: show_error(self, _("TEXT_GREET_USER_INVALID_HUMAN_HANDLE"), exception=exc) return self.button_create_user.setDisabled(True) self.button_create_user.setText(_("TEXT_GREET_USER_WAITING")) self.create_user_job = self.jobs_ctx.submit_job( self.create_user_success, self.create_user_error, self.greeter.create_new_user, human_handle=handle, device_label=device_label, profile=self.combo_profile.currentData(), )
def _on_validate_clicked(self): backend_addr = None org_id = None device_name = None human_handle = None if self.start_addr: backend_addr = self.start_addr else: try: org_id = OrganizationID( self.user_widget.line_edit_org_name.text()) except ValueError as exc: show_error(self, _("TEXT_ORG_WIZARD_INVALID_ORGANIZATION_ID"), exception=exc) return try: backend_addr = BackendOrganizationBootstrapAddr.build( backend_addr=self.user_widget.backend_addr if self.user_widget.radio_use_custom.isChecked() else self.config.preferred_org_creation_backend_addr, organization_id=org_id, ) except ValueError as exc: show_error(self, _("TEXT_ORG_WIZARD_INVALID_BACKEND_ADDR"), exception=exc) return try: device_name = DeviceName( self.device_widget.line_edit_device.text()) except ValueError as exc: show_error(self, _("TEXT_ORG_WIZARD_INVALID_DEVICE_NAME"), exception=exc) return try: user_name = validators.trim_user_name( self.user_widget.line_edit_user_full_name.text()) human_handle = HumanHandle( self.user_widget.line_edit_user_email.text(), user_name) except ValueError as exc: show_error(self, _("TEXT_ORG_WIZARD_INVALID_HUMAN_HANDLE"), exception=exc) return self.create_job = self.jobs_ctx.submit_job( ThreadSafeQtSignal(self, "req_success"), ThreadSafeQtSignal(self, "req_error"), _do_create_org, config=self.config, human_handle=human_handle, device_name=device_name, password=self.device_widget.password, backend_addr=backend_addr, ) self.button_validate.setEnabled(False)
async def _on_validate_clicked(self): if isinstance(self.current_page, DeviceRecoveryImportPage1Widget): # No try/except given `self.line_edit_device` has already been validated against `DeviceLabel` device_label = DeviceLabel( validators.trim_user_name( self.current_page.line_edit_device.text())) self.jobs_ctx.submit_job( self.create_new_device_success, self.create_new_device_failure, self._create_new_device, device_label=device_label, file_path=PurePath(self.current_page.get_recovery_key_file()), passphrase=self.current_page.get_passphrase(), ) else: try: self.button_validate.setEnabled(False) auth_method = self.current_page.get_auth_method() if auth_method == DeviceFileType.PASSWORD: save_device_with_password_in_config( config_dir=self.config.config_dir, device=self.new_device, password=self.current_page.get_auth(), ) else: await save_device_with_smartcard_in_config( config_dir=self.config.config_dir, device=self.new_device) show_info(self, translate("TEXT_RECOVERY_IMPORT_SUCCESS")) self.dialog.accept() except LocalDeviceCryptoError as exc: self.button_validate.setEnabled(True) if auth_method == DeviceFileType.SMARTCARD: show_error(self, translate("TEXT_INVALID_SMARTCARD"), exception=exc) except LocalDeviceNotFoundError as exc: if auth_method == DeviceFileType.PASSWORD: show_error(self, translate("TEXT_CANNOT_SAVE_DEVICE"), exception=exc) self.button_validate.setEnabled(True) except LocalDeviceError as exc: show_error(self, translate("TEXT_CANNOT_SAVE_DEVICE"), exception=exc) self.button_validate.setEnabled(True)
def _on_claim_clicked(self): if not self.new_device: # No try/except given `self.line_edit_device` has already been validated against `DeviceLabel` device_label = DeviceLabel( validators.trim_user_name(self.line_edit_device.text())) self.button_ok.setDisabled(True) self.widget_info.setDisabled(True) self.label_wait.show() self.claim_job = self.jobs_ctx.submit_job( self.claim_success, self.claim_error, self.claimer.claim_device, device_label=device_label, ) else: self.succeeded.emit(self.new_device, self.widget_auth.get_auth_method(), self.widget_auth.get_auth())
def _on_claim_clicked(self): device_label = self.line_edit_device.text() try: user_name = validators.trim_user_name(self.line_edit_user_full_name.text()) human_handle = HumanHandle(email=self.line_edit_user_email.text(), label=user_name) except ValueError as exc: show_error(self, _("TEXT_CLAIM_USER_INVALID_HUMAN_HANDLE"), exception=exc) return self.button_ok.setDisabled(True) self.widget_info.setDisabled(True) self.label_wait.show() self.claim_job = self.jobs_ctx.submit_job( ThreadSafeQtSignal(self, "claim_success", QtToTrioJob), ThreadSafeQtSignal(self, "claim_error", QtToTrioJob), self.claimer.claim_user, device_label=device_label, human_handle=human_handle, )
def _on_create_user_clicked(self): assert not self.create_user_job handle = None device_label = self.line_edit_device.text() try: user_name = validators.trim_user_name(self.line_edit_user_full_name.text()) handle = HumanHandle(label=user_name, email=self.line_edit_user_email.text()) except ValueError as exc: show_error(self, _("TEXT_GREET_USER_INVALID_HUMAN_HANDLE"), exception=exc) return self.button_create_user.setDisabled(True) self.button_create_user.setText(_("TEXT_GREET_USER_WAITING")) self.create_user_job = self.jobs_ctx.submit_job( ThreadSafeQtSignal(self, "create_user_success", QtToTrioJob), ThreadSafeQtSignal(self, "create_user_error", QtToTrioJob), self.greeter.create_new_user, human_handle=handle, device_label=device_label, profile=self.combo_profile.currentData(), )
async def _on_next_clicked(self): if isinstance(self.current_widget, CreateOrgUserInfoWidget): backend_addr = None org_id = None device_label = None human_handle = None if self.start_addr: backend_addr = self.start_addr else: try: org_id = OrganizationID( self.current_widget.line_edit_org_name.text()) except ValueError as exc: show_error(self, _("TEXT_ORG_WIZARD_INVALID_ORGANIZATION_ID"), exception=exc) return try: backend_addr = BackendOrganizationBootstrapAddr.build( backend_addr=self.current_widget.backend_addr if self.current_widget.radio_use_custom.isChecked() else self.config.preferred_org_creation_backend_addr, organization_id=org_id, ) except ValueError as exc: show_error(self, _("TEXT_ORG_WIZARD_INVALID_BACKEND_ADDR"), exception=exc) return try: user_name = validators.trim_user_name( self.current_widget.line_edit_user_full_name.text()) human_handle = HumanHandle( self.current_widget.line_edit_user_email.text(), user_name) except ValueError as exc: show_error(self, _("TEXT_ORG_WIZARD_INVALID_HUMAN_HANDLE"), exception=exc) return # No try/except given `self.current_widget.line_edit_device` has already been validated against `DeviceLabel` try: device_label = DeviceLabel( self.current_widget.line_edit_device.text()) except ValueError as exc: show_error(self, _("TEXT_ORG_WIZARD_INVALID_DEVICE_LABEL"), exception=exc) return # TODO: call `await _do_create_org` directly since the context is now async self.create_job = self.jobs_ctx.submit_job( self.req_success, self.req_error, _do_create_org, config=self.config, human_handle=human_handle, device_label=device_label, backend_addr=backend_addr, ) self.dialog.button_close.setVisible(False) self.button_validate.setEnabled(False) else: auth_method = self.current_widget.get_auth_method() try: if auth_method == DeviceFileType.PASSWORD: save_device_with_password_in_config( self.config.config_dir, self.new_device, self.current_widget.get_auth()) elif auth_method == DeviceFileType.SMARTCARD: await save_device_with_smartcard_in_config( self.config.config_dir, self.new_device) self.status = (self.new_device, auth_method, self.current_widget.get_auth()) if self.dialog: self.dialog.accept() elif QApplication.activeModalWidget(): QApplication.activeModalWidget().accept() else: logger.warning("Cannot close dialog when org wizard") except LocalDeviceCryptoError as exc: if auth_method == DeviceFileType.SMARTCARD: show_error(self, _("TEXT_INVALID_SMARTCARD"), exception=exc) except LocalDeviceNotFoundError as exc: if auth_method == DeviceFileType.PASSWORD: show_error(self, _("TEXT_CANNOT_SAVE_DEVICE"), exception=exc) except LocalDeviceError as exc: show_error(self, _("TEXT_CANNOT_SAVE_DEVICE"), exception=exc)
def human_handle(self): user_name = validators.trim_user_name( self.line_edit_user_full_name.text()) return HumanHandle(label=user_name, email=self.line_edit_user_email.text())