mirror of
https://github.com/freedombox/FreedomBox.git
synced 2026-09-19 04:59:01 +00:00
email_server: domains: Add validation to form
- Based on what is already done in domains.py at the time of setting the configuration. Signed-off-by: Sunil Mohan Adapa <sunil@medhas.org> Reviewed-by: James Valleroy <jvalleroy@mailbox.org>
This commit is contained in:
parent
e85001f01f
commit
220149e6e0
@ -6,10 +6,17 @@ import re
|
|||||||
|
|
||||||
from django import forms
|
from django import forms
|
||||||
from django.core.exceptions import ValidationError
|
from django.core.exceptions import ValidationError
|
||||||
|
from django.core.validators import RegexValidator
|
||||||
from django.utils.translation import gettext_lazy as _
|
from django.utils.translation import gettext_lazy as _
|
||||||
|
|
||||||
from . import aliases as aliases_module
|
from . import aliases as aliases_module
|
||||||
|
|
||||||
|
domain_validator = RegexValidator(r'^[A-Za-z0-9-\.]+$',
|
||||||
|
_('Enter a valid domain'))
|
||||||
|
destination_validator = RegexValidator(
|
||||||
|
r'^[ -~]+$', # ASCII chars from 32 to 126
|
||||||
|
_('Enter a valid destination'))
|
||||||
|
|
||||||
|
|
||||||
class EmailServerForm(forms.Form):
|
class EmailServerForm(forms.Form):
|
||||||
domain = forms.CharField(label=_('domain'), max_length=256)
|
domain = forms.CharField(label=_('domain'), max_length=256)
|
||||||
@ -19,10 +26,26 @@ class EmailServerForm(forms.Form):
|
|||||||
|
|
||||||
|
|
||||||
class DomainsForm(forms.Form):
|
class DomainsForm(forms.Form):
|
||||||
_mailname = forms.CharField(required=True, strip=True)
|
_mailname = forms.CharField(required=True, strip=True,
|
||||||
mydomain = forms.CharField(required=True, strip=True)
|
validators=[domain_validator])
|
||||||
myhostname = forms.CharField(required=True, strip=True)
|
mydomain = forms.CharField(required=True, strip=True,
|
||||||
mydestination = forms.CharField(required=True, strip=True)
|
validators=[domain_validator])
|
||||||
|
myhostname = forms.CharField(required=True, strip=True,
|
||||||
|
validators=[domain_validator])
|
||||||
|
mydestination = forms.CharField(required=True, strip=True,
|
||||||
|
validators=[destination_validator])
|
||||||
|
|
||||||
|
def clean(self):
|
||||||
|
"""Convert values to lower case."""
|
||||||
|
data = self.cleaned_data
|
||||||
|
if '_mailname' in data:
|
||||||
|
data['_mailname'] = data['_mailname'].lower()
|
||||||
|
|
||||||
|
if 'myhostname' in data:
|
||||||
|
data['myhostname'] = data['myhostname'].lower()
|
||||||
|
|
||||||
|
if 'mydestination' in data:
|
||||||
|
data['mydestination'] = data['mydestination'].lower()
|
||||||
|
|
||||||
|
|
||||||
class AliasCreateForm(forms.Form):
|
class AliasCreateForm(forms.Form):
|
||||||
|
|||||||
Loading…
x
Reference in New Issue
Block a user