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) subject = re.sub(form_regex, r'{\1}', form['subject']).format(**subject_fields)
content = re.sub(form_regex, r'{\1}', form['content']).format(**content_fields) content = re.sub(form_regex, r'{\1}', form['content']).format(**content_fields)
print(subject)
print(content)
return 'aborted'
try: try:
if not send_mail(from_address, form['mail'], subject, content): if not send_mail(from_address, form['mail'], subject, content):
response.status = 500 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. """ """ Parse the string looking for template elements and create an array with template to fill and their default values. None if mandatory. """
result = {} result = {}
for match in re.findall(form_regex, string): 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 return result
def fill_fields(request, fields): 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.""" """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: for field in fields:
if field in request.forms: if field in request.forms:
fields[field] = html.escape(request.forms[field]) fields[field] = request.forms.getunicode(field)
elif fields[field] == None: elif fields[field] == None:
raise MissingParameterException("Le champs {} est obligatoire".format(field)) raise MissingParameterException("Le champs {} est obligatoire".format(field))
return fields 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) - [unit tests](https://bottlepy.org/docs/dev/recipes.html#unit-testing-bottle-applications)
- add redirection urls to form config - add redirection urls to form config
- Include some [capcha](https://alternativeto.net/software/recaptcha/) support - Include some [capcha](https://alternativeto.net/software/recaptcha/) support
- Correctly escape html entities
### Ameliorations ### Ameliorations
- Use real user/passwords accounts - Use real user/passwords accounts