Add password match validator

Signed-off-by: Adam Stokes <adam.stokes@ubuntu.com>
This commit is contained in:
Adam Stokes 2015-09-28 11:03:01 -04:00
parent 3bb2a79c2e
commit c6628911d4
2 changed files with 10 additions and 0 deletions

View File

@ -53,6 +53,8 @@ STYLES = [
Palette.black, Palette.dark_green), Palette.black, Palette.dark_green),
('info_minor', '', '', '', ('info_minor', '', '', '',
Palette.dark_gray, ''), Palette.dark_gray, ''),
('info_error', '', '', '',
Palette.dark_red, ''),
('string_input', '', '', '', ('string_input', '', '', '',
Palette.black, Palette.light_gray), Palette.black, Palette.light_gray),
('string_input focus', '', '', '', ('string_input focus', '', '', '',

View File

@ -36,11 +36,14 @@ class IdentityView(ViewPolicy):
self.realname = StringEditor(caption="") self.realname = StringEditor(caption="")
self.username = StringEditor(caption="") self.username = StringEditor(caption="")
self.password = PasswordEditor(caption="") self.password = PasswordEditor(caption="")
self.error = Text("", align="center")
self.confirm_password = PasswordEditor(caption="") self.confirm_password = PasswordEditor(caption="")
body = [ body = [
Padding.center_50(self._build_model_inputs()), Padding.center_50(self._build_model_inputs()),
Padding.line_break(""), Padding.line_break(""),
Padding.center_50(Color.info_error(self.error)),
Padding.line_break(""),
Padding.center_15(self._build_buttons()), Padding.center_15(self._build_buttons()),
] ]
super().__init__(ListBox(body)) super().__init__(ListBox(body))
@ -97,6 +100,11 @@ class IdentityView(ViewPolicy):
return Pile(sl) return Pile(sl)
def done(self, result): def done(self, result):
if self.password.value != self.confirm_password.value:
self.error.set_text("Passwords do not match.")
self.password.value = ""
self.confirm_password.value = ""
return
cpassword = self.model.encrypt_password(self.password.value) cpassword = self.model.encrypt_password(self.password.value)
log.debug("*crypted* User input: {} {} {}".format( log.debug("*crypted* User input: {} {} {}".format(
self.username.value, cpassword, cpassword)) self.username.value, cpassword, cpassword))