This commit is contained in:
Adrian Amaglio 2020-05-01 18:58:19 +02:00
parent 86e3847b4f
commit 6ffd214325
2 changed files with 6 additions and 2 deletions

View File

@ -123,7 +123,10 @@ def submission ():
subject = re.sub(form_regex, r'{\1}', form['subject']).format(**subject_fields)
content = re.sub(form_regex, r'{\1}', form['content']).format(**content_fields)
print(subject)
print(content)
return 'aborted'
try:
if not send_mail(from_address, form['mail'], subject, content):
response.status = 500
@ -142,14 +145,14 @@ def get_fields (string):
""" Parse the string looking for template elements and create an array with template to fill and their default values. None if mandatory. """
result = {}
for match in re.findall(form_regex, string):
result[match[0]] = match[1]
result[match[0]] = None if match[1] == '' else match[1][1:]
return result
def fill_fields(request, fields):
"""Look for fields in request and fill fields dict with values or let default ones. If the value is required, throw exception."""
for field in fields:
if field in request.forms:
fields[field] = html.escape(request.forms[field])
fields[field] = request.forms.getunicode(field)
elif fields[field] == None:
raise MissingParameterException("Le champs {} est obligatoire".format(field))
return fields

View File

@ -74,6 +74,7 @@ You can store them in a `.env` file. The python app will read it or you can pass
- [unit tests](https://bottlepy.org/docs/dev/recipes.html#unit-testing-bottle-applications)
- add redirection urls to form config
- Include some [capcha](https://alternativeto.net/software/recaptcha/) support
- Correctly escape html entities
### Ameliorations
- Use real user/passwords accounts