ui: move confirmation mechanism in subiquitycore.ui
Signed-off-by: Olivier Gayot <olivier.gayot@canonical.com>
This commit is contained in:
parent
d63b44c014
commit
384e4b62ac
|
@ -48,9 +48,6 @@ from subiquity.ui.views.filesystem.compound import (
|
|||
get_possible_components,
|
||||
MultiDeviceField,
|
||||
)
|
||||
from subiquity.ui.views.identity import (
|
||||
setup_password_validation,
|
||||
)
|
||||
|
||||
log = logging.getLogger('subiquity.ui.views.filesystem.lvm')
|
||||
|
||||
|
@ -83,8 +80,8 @@ class VolGroupForm(CompoundDiskForm):
|
|||
self.deleted_vg_names = deleted_vg_names
|
||||
super().__init__(model, possible_components, initial)
|
||||
connect_signal(self.encrypt.widget, 'change', self._change_encrypt)
|
||||
setup_password_validation(field=self.passphrase,
|
||||
field_confirm=self.confirm_passphrase,
|
||||
self.confirm_passphrase.use_as_confirmation(
|
||||
for_field=self.passphrase,
|
||||
desc=_("Passphrases"))
|
||||
self._change_encrypt(None, self.encrypt.value)
|
||||
|
||||
|
|
|
@ -27,7 +27,6 @@ from subiquitycore.ui.interactive import (
|
|||
StringEditor,
|
||||
)
|
||||
from subiquitycore.ui.form import (
|
||||
BoundFormField,
|
||||
Form,
|
||||
simple_field,
|
||||
WantsToKnowFormField,
|
||||
|
@ -187,21 +186,6 @@ class IdentityForm(Form):
|
|||
return _("Passwords do not match")
|
||||
|
||||
|
||||
def setup_password_validation(field: BoundFormField,
|
||||
field_confirm: BoundFormField,
|
||||
desc: str) -> None:
|
||||
""" Set up an automatic check for password vs password confirmation. """
|
||||
def _check_password(sender, new_text):
|
||||
password = field.value
|
||||
if not password.startswith(new_text):
|
||||
field_confirm.show_extra(
|
||||
# desc is "Passwords" or "Passphrases"
|
||||
("info_error", _("{desc} do not match").format(desc=desc)))
|
||||
else:
|
||||
field_confirm.show_extra('')
|
||||
connect_signal(field_confirm.widget, 'change', _check_password)
|
||||
|
||||
|
||||
class IdentityView(BaseView):
|
||||
title = _("Profile setup")
|
||||
excerpt = _("Enter the username and password you will use to log in to "
|
||||
|
@ -231,11 +215,12 @@ class IdentityView(BaseView):
|
|||
|
||||
self.form = IdentityForm(controller, initial)
|
||||
|
||||
connect_signal(self.form, 'submit', self.done)
|
||||
setup_password_validation(field=self.form.password,
|
||||
field_confirm=self.form.confirm_password,
|
||||
self.form.confirm_password.use_as_confirmation(
|
||||
for_field=self.form.password,
|
||||
desc=_("Passwords"))
|
||||
|
||||
connect_signal(self.form, 'submit', self.done)
|
||||
|
||||
super().__init__(
|
||||
screen(
|
||||
self.form.as_rows(),
|
||||
|
|
|
@ -280,6 +280,18 @@ class BoundFormField(object):
|
|||
for row in self._rows:
|
||||
row.enabled = val
|
||||
|
||||
def use_as_confirmation(self, for_field: "BoundFormField", desc: str) \
|
||||
-> None:
|
||||
""" Mark this field as a confirmation field for another field.
|
||||
This will automatically compare the value of both fields when this
|
||||
field (a.k.a., the confirmation field) is changed. """
|
||||
def _check_confirmation(sender, new_text):
|
||||
if not for_field.value.startswith(new_text):
|
||||
self.show_extra(("info_error", _(f"{desc} do not match")))
|
||||
else:
|
||||
self.show_extra("")
|
||||
connect_signal(self.widget, "change", _check_confirmation)
|
||||
|
||||
|
||||
class BoundSubFormField(BoundFormField):
|
||||
def is_in_error(self):
|
||||
|
|
|
@ -23,7 +23,6 @@ from subiquity.common.types import IdentityData
|
|||
from subiquity.ui.views.identity import (
|
||||
IdentityForm,
|
||||
IdentityView,
|
||||
setup_password_validation,
|
||||
)
|
||||
from subiquitycore.ui.utils import screen
|
||||
from subiquitycore.utils import crypt_password
|
||||
|
@ -72,9 +71,9 @@ class WSLIdentityView(BaseView):
|
|||
self.form = WSLIdentityForm(controller, initial)
|
||||
|
||||
connect_signal(self.form, 'submit', self.done)
|
||||
setup_password_validation(field=self.form.password,
|
||||
field_confirm=self.form.confirm_password,
|
||||
desc=_("passwords"))
|
||||
self.form.confirm_password.use_as_confirmation(
|
||||
for_field=self.form.password,
|
||||
desc=_("Passwords"))
|
||||
|
||||
super().__init__(
|
||||
screen(
|
||||
|
|
Loading…
Reference in New Issue