diff --git a/app/main/views.py b/app/main/views.py index 63a67d53a..58fe5efb9 100644 --- a/app/main/views.py +++ b/app/main/views.py @@ -48,14 +48,19 @@ def status(): def technical_support(): if request.method == 'POST': if current_app.config['RECAPTCHA_ENABLED']: - # Verify recaptcha token and return error if failed - recaptcha_response = requests.post( - url='https://www.google.com/recaptcha/api/siteverify?secret={}&response={}' - .format(current_app.config["RECAPTCHA_PRIVATE_KEY"], - request.form["g-recaptcha-response"])).json() - - if recaptcha_response['success'] is False or recaptcha_response['score'] < current_app.config[ - "RECAPTCHA_THRESHOLD"]: + try: + # Verify recaptcha token and return error if failed + recaptcha_response = requests.post( + url='https://www.google.com/recaptcha/api/siteverify?secret={}&response={}' + .format(current_app.config["RECAPTCHA_PRIVATE_KEY"], + request.form["g-recaptcha-response"])).json() + + if recaptcha_response['success'] is False or recaptcha_response['score'] < current_app.config[ + "RECAPTCHA_THRESHOLD"]: + flash('Recaptcha failed, please try again.', category='danger') + render_template('main/contact.html') + except: + current_app.logger.exception("Recaptcha failed to get a response.") flash('Recaptcha failed, please try again.', category='danger') render_template('main/contact.html') diff --git a/app/request/views.py b/app/request/views.py index 10cb6b76a..b0e224d48 100644 --- a/app/request/views.py +++ b/app/request/views.py @@ -99,14 +99,26 @@ def new(): if flask_request.method == "POST": if current_app.config['RECAPTCHA_ENABLED']: - # Verify recaptcha token and return error if failed - recaptcha_response = requests.post( - url='https://www.google.com/recaptcha/api/siteverify?secret={}&response={}' - .format(current_app.config["RECAPTCHA_PRIVATE_KEY"], - request.form["g-recaptcha-response"])).json() - - if recaptcha_response['success'] is False or recaptcha_response['score'] < current_app.config[ - "RECAPTCHA_THRESHOLD"]: + try: + # Verify recaptcha token and return error if failed + recaptcha_response = requests.post( + url='https://www.google.com/recaptcha/api/siteverify?secret={}&response={}' + .format(current_app.config["RECAPTCHA_PRIVATE_KEY"], + flask_request.form["g-recaptcha-response"])).json() + + if recaptcha_response['success'] is False or recaptcha_response['score'] < current_app.config[ + "RECAPTCHA_THRESHOLD"]: + flash('Recaptcha failed, please try again.', category='danger') + return render_template( + new_request_template, + form=form, + kiosk_mode=kiosk_mode, + category=category, + agency=agency, + title=title, + ) + except: + current_app.logger.exception("Recaptcha failed to get a response.") flash('Recaptcha failed, please try again.', category='danger') return render_template( new_request_template, diff --git a/app/templates/main/contact.html b/app/templates/main/contact.html index 9f065c512..17b3e79d3 100644 --- a/app/templates/main/contact.html +++ b/app/templates/main/contact.html @@ -34,16 +34,17 @@

Technical Support


{% if config['RECAPTCHA_ENABLED'] %} - {% else %} - + {% endif %}