Changeset View
Changeset View
Standalone View
Standalone View
swh/web/common/utils.py
Show First 20 Lines • Show All 323 Lines • ▼ Show 20 Lines | def is_recaptcha_valid(request, recaptcha_response): | ||||
Args: | Args: | ||||
request (django.http.HttpRequest): the incoming HTTP request | request (django.http.HttpRequest): the incoming HTTP request | ||||
recaptcha_response (str): the reCAPTCHA response | recaptcha_response (str): the reCAPTCHA response | ||||
Returns: | Returns: | ||||
bool: Whether the reCAPTCHA response is valid or not | bool: Whether the reCAPTCHA response is valid or not | ||||
""" | """ | ||||
config = get_config() | config = get_config() | ||||
return requests.post( | if config['grecaptcha']['activated'] is False: | ||||
recaptcha_valid = True | |||||
else: | |||||
recaptcha_valid = requests.post( | |||||
config['grecaptcha']['validation_url'], | config['grecaptcha']['validation_url'], | ||||
data={ | data={ | ||||
'secret': config['grecaptcha']['private_key'], | 'secret': config['grecaptcha']['private_key'], | ||||
'response': recaptcha_response, | 'response': recaptcha_response, | ||||
'remoteip': get_client_ip(request) | 'remoteip': get_client_ip(request) | ||||
}, | }, | ||||
verify=True | verify=True | ||||
).json().get("success", False) | ).json().get("success", False) | ||||
return recaptcha_valid | |||||
def context_processor(request): | def context_processor(request): | ||||
""" | """ | ||||
Django context processor used to inject variables | Django context processor used to inject variables | ||||
in all swh-web templates. | in all swh-web templates. | ||||
""" | """ | ||||
config = get_config() | config = get_config() | ||||
return {'swh_object_icons': swh_object_icons, | return {'swh_object_icons': swh_object_icons, | ||||
'grecaptcha_activated': config['grecaptcha']['activated'], | |||||
'grecaptcha_site_key': config['grecaptcha']['site_key']} | 'grecaptcha_site_key': config['grecaptcha']['site_key']} |