fix field control

This commit is contained in:
Adrian Amaglio 2020-10-08 20:17:48 +02:00
parent 8f88cd6d2c
commit e2465e2874
2 changed files with 12 additions and 3 deletions

View File

@ -106,6 +106,9 @@ function jeanCloudContactFormIntercept (formId, notifier) {
loadingText.parentNode.removeChild(loadingText) loadingText.parentNode.removeChild(loadingText)
notifier.error('Impossible denvoyer le formulaire. Vérifiez votre connexion internet ou réessayez plus tard.') notifier.error('Impossible denvoyer le formulaire. Vérifiez votre connexion internet ou réessayez plus tard.')
}) })
/* Remove timer field after xhr. So we can try again. */
formElem.removeChild(timerField)
} }
} }

10
main.py
View File

@ -46,7 +46,6 @@ class EnableCors(object):
return _enable_cors return _enable_cors
app = application = bottle.Bottle(catchall=False) app = application = bottle.Bottle(catchall=False)
#app.install(EnableCors())
##################################################### Configuration ############################################ ##################################################### Configuration ############################################
@ -137,11 +136,13 @@ def submission ():
# Did the bot filled the honeypot field? # Did the bot filled the honeypot field?
if 'honeypotfield' in form and form['honeypotfield'] in request.forms and request.forms.get(form['honeypotfield']) != '': if 'honeypotfield' in form and form['honeypotfield'] in request.forms and request.forms.get(form['honeypotfield']) != '':
response.status = 400 response.status = 400
print('honeypotfield')
return resp('error', 'We identified you as a bot. If this is an error, try to contact us via another way.') return resp('error', 'We identified you as a bot. If this is an error, try to contact us via another way.')
# Is the js timer enabled? # Is the js timer enabled?
if 'timerdelay' in form: if 'timerdelay' in form:
# Did it work? # Did it work?
if 'timerfield' not in request.forms or request.forms.get('timerfield') < form['timerdelay']: if 'timerfield' not in request.forms or int(request.forms.get('timerfield')) < int(form['timerdelay']):
print('timer : {}/{}'.format(request.forms.get('timerfield'), form['timerdelay']))
response.status = 400 response.status = 400
return resp('error', 'We identified you as a bot. If this is an error, try to contact us via another way.') return resp('error', 'We identified you as a bot. If this is an error, try to contact us via another way.')
@ -190,9 +191,13 @@ 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:
if request.forms.get(field).strip() == '' and fields[field] is None: # If empty and mandatory
raise MissingParameterException("Le champs {} doit être rempli".format(field))
fields[field] = request.forms.getunicode(field) fields[field] = request.forms.getunicode(field)
if fields[field] is None: # if unicode failed if fields[field] is None: # if unicode failed
fields[field] = request.forms.get(field) fields[field] = request.forms.get(field)
if fields[field] is None: # if get failed too
raise Exception("Error, field '{}' not gettable".format(field))
elif fields[field] is None: elif fields[field] is None:
raise MissingParameterException("Le champs {} est obligatoire".format(field)) raise MissingParameterException("Le champs {} est obligatoire".format(field))
return fields return fields
@ -418,6 +423,7 @@ def delete_user (username):
##################################################### app startup ############################################ ##################################################### app startup ############################################
if __name__ == '__main__': if __name__ == '__main__':
app.install(EnableCors())
bottle.run(app=StripPathMiddleware(app), host=listen_address, port=listen_port, debug=True) bottle.run(app=StripPathMiddleware(app), host=listen_address, port=listen_port, debug=True)
else: else:
prod_app = StripPathMiddleware(app) prod_app = StripPathMiddleware(app)