mirror of
https://github.com/freedombox/FreedomBox.git
synced 2026-09-19 04:59:01 +00:00
do form validation within clean function of the ConfigureForm class and not when applying the changes
This commit is contained in:
parent
7ea9e1cf94
commit
2dbdc0c685
@ -115,6 +115,15 @@ class ConfigureForm(forms.Form):
|
|||||||
validators=[
|
validators=[
|
||||||
validators.URLValidator(schemes=['http', 'https', 'ftp'])])
|
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
|
@login_required
|
||||||
@package.required('ez-ipupdate')
|
@package.required('ez-ipupdate')
|
||||||
@ -203,20 +212,11 @@ def _apply_changes(request, old_status, new_status):
|
|||||||
"""Apply the changes to Dynamic DNS client"""
|
"""Apply the changes to Dynamic DNS client"""
|
||||||
LOGGER.info('New status is - %s', new_status)
|
LOGGER.info('New status is - %s', new_status)
|
||||||
LOGGER.info('Old status was - %s', old_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 \
|
if old_status['dynamicdns_secret'] == '' and \
|
||||||
new_status['dynamicdns_secret'] == '':
|
new_status['dynamicdns_secret'] == '':
|
||||||
messages.error(request, _('please give a password'))
|
messages.error(request, _('please give a password'))
|
||||||
fail = True
|
else:
|
||||||
|
|
||||||
if not fail:
|
|
||||||
if new_status['dynamicdns_secret'] == '':
|
if new_status['dynamicdns_secret'] == '':
|
||||||
new_status['dynamicdns_secret'] = old_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']:
|
if old_status['enabled']:
|
||||||
_run(['stop'])
|
_run(['stop'])
|
||||||
|
|
||||||
if new_status['enabled']:
|
if new_status['enabled']:
|
||||||
_run(['start'])
|
_run(['start'])
|
||||||
|
|
||||||
messages.success(request,
|
messages.success(request,
|
||||||
_('Dynamic DNS configuration is updated!'))
|
_('Dynamic DNS configuration is updated!'))
|
||||||
else:
|
|
||||||
messages.error(request,
|
|
||||||
_('At least one failure occured,\
|
|
||||||
please check your input.'))
|
|
||||||
|
|
||||||
|
|
||||||
def _run(arguments, superuser=False):
|
def _run(arguments, superuser=False):
|
||||||
|
|||||||
Loading…
x
Reference in New Issue
Block a user