From 2dbdc0c685ed6ed8c5dde1e107c1f788ac7c3037 Mon Sep 17 00:00:00 2001 From: Daniel Steglich Date: Mon, 23 Feb 2015 13:38:58 +0000 Subject: [PATCH] do form validation within clean function of the ConfigureForm class and not when applying the changes --- plinth/modules/dynamicdns/dynamicdns.py | 25 ++++++++++--------------- 1 file changed, 10 insertions(+), 15 deletions(-) diff --git a/plinth/modules/dynamicdns/dynamicdns.py b/plinth/modules/dynamicdns/dynamicdns.py index 3f2c34fc7..8d0d05c90 100644 --- a/plinth/modules/dynamicdns/dynamicdns.py +++ b/plinth/modules/dynamicdns/dynamicdns.py @@ -115,6 +115,15 @@ class ConfigureForm(forms.Form): validators=[ validators.URLValidator(schemes=['http', 'https', 'ftp'])]) + def clean(self): + cleaned_data = super(ConfigureForm, self).clean() + dynamicdns_secret = cleaned_data.get("dynamicdns_secret") + dynamicdns_secret_repeat = cleaned_data.get("dynamicdns_secret_repeat") + + if dynamicdns_secret or dynamicdns_secret_repeat: + if dynamicdns_secret != dynamicdns_secret_repeat: + raise forms.ValidationError("password missmatch") + @login_required @package.required('ez-ipupdate') @@ -203,20 +212,11 @@ def _apply_changes(request, old_status, new_status): """Apply the changes to Dynamic DNS client""" LOGGER.info('New status is - %s', new_status) LOGGER.info('Old status was - %s', old_status) - fail = False - - if new_status['dynamicdns_secret_repeat'] != \ - new_status['dynamicdns_secret']: - - messages.error(request, _('passwords does not match')) - fail = True if old_status['dynamicdns_secret'] == '' and \ new_status['dynamicdns_secret'] == '': messages.error(request, _('please give a password')) - fail = True - - if not fail: + else: if new_status['dynamicdns_secret'] == '': new_status['dynamicdns_secret'] = old_status['dynamicdns_secret'] @@ -244,16 +244,11 @@ def _apply_changes(request, old_status, new_status): if old_status['enabled']: _run(['stop']) - if new_status['enabled']: _run(['start']) messages.success(request, _('Dynamic DNS configuration is updated!')) - else: - messages.error(request, - _('At least one failure occured,\ - please check your input.')) def _run(arguments, superuser=False):