def validate_form_values(self, form_values): form_error = None if not all(form_values.values()): form_error = tr._("Please enter a username, passphrase and passphrase hint.") elif len(form_values["passphrase"]) < PASSPHRASE_MIN_LENGTH: form_error = tr._("Passphrase must be at least %s characters long.") % PASSPHRASE_MIN_LENGTH if form_error: raise ValueError(form_error)
def finish_initialization(self, *args, success, **kwargs): on_close = self.close_dialog_and_leave if success: self.open_dialog(tr._("Initialization successfully completed."), title=tr._("Success"), on_dismiss=lambda x: self.go_to_home_screen()) else: self.open_dialog(tr._("Operation failed, check logs."), title=tr._("Failure"), on_dismiss=lambda x: self.go_to_home_screen())
def display_help_popup(self): help_text = dedent(tr._("""\ On this page, you can initialize an authenticator inside an empty folder; this authenticator actually consists in metadata files as well as a set of asymmetric keypairs. To proceed, you have to input your user name or pseudo, a long passphrase (e.g. consisting of 4 different words), and a public hint to help your remember your passphrase later. You should keep your passphrase somewhere safe (in a digital password manager, on a paper in a vault...), because if you forget any of its aspects (upper/lower case, accents, spaces...), there is no way to recover it. """)) help_text_popup( title=tr._("Authenticator creation page"), text=help_text,)
def help_text_popup(title, text): # FIXME rename this text = "[size=13sp]" + text + "[/size]" # Else it's too big dialog_with_close_button( title=tr._(title), text=text, full_width=True, )
def dialog_with_close_button(buttons=None, close_btn_label=None, full_width=False, close_btn_callback=None, auto_open_and_register=True, **kwargs): """A dialog which can close itself and works on on smartphone too""" close_btn_label = close_btn_label or tr._("Close") dialog = None def default_on_close(*args): dialog.dismiss() close_btn_callback = close_btn_callback or default_on_close close_btn = MDFlatButton(text=close_btn_label, on_release=close_btn_callback) if full_width: kwargs["size_hint_x"] = 0.95 kwargs["size_hint_y"] = None dialog = MDDialog( auto_dismiss=False, # IMPORTANT, else buggy on Android buttons=buttons + [close_btn] if buttons else [close_btn], **kwargs, ) if auto_open_and_register: dialog.open() register_current_dialog(dialog) return dialog
def display_snackbar_on_error(f, *args, **kwargs): try: return f(*args, **kwargs) except Exception as exc: message = tr._("Abnormal error caught: %s") % exc.__class__.__name__ displayer = lambda dt: Snackbar(text=message).open() Clock.schedule_once( displayer, 0) # Scheduled so that other threads can display popups too raise # Let it flow, other decorator shall intercept it
def open_container_details_dialog(self, message, info_container): self.dialog = MDDialog( title=str(info_container), text=message, size_hint=(0.8, 1), buttons=[ MDFlatButton(text=tr._("Close"), on_release=self.close_dialog) ], ) self.dialog.open()
def request_authenticator_initialization(self): form_values = self.get_form_values() try : self.validate_form_values(form_values) except ValueError as exc: self.open_dialog(str(exc), title=tr._("Validation error")) return self._launch_authenticator_initialization(form_values=form_values)
def _launch_authenticator_initialization(self, form_values): authenticator_path = self._selected_authenticator_path if not authenticator_path.is_dir(): authenticator_path.mkdir(parents=False) # Only 1 level of folder can be created here! assert authenticator_path and authenticator_path.is_dir(), authenticator_path self.ids.button_initialize.disabled = True self.ids.formfield_passphrase.text = "***" # PRIVACY self.operation_status = tr._("Please wait, initialization might take a few minutes.") self.set_form_fields_status(enabled=False) self.ids.initialization_form_toolbar.disabled = True THREAD_POOL_EXECUTOR.submit(self._offloaded_initialize_authenticator, form_values=form_values, authenticator_path=authenticator_path)