Skip to content

Commit

Permalink
Merge pull request #4102 from ckan/4061-recapture-v1-ending
Browse files Browse the repository at this point in the history
[#4061] Recapture version no longer has a default value
  • Loading branch information
amercader committed Mar 19, 2018
2 parents 4d60c99 + ee0c50f commit d7655c8
Show file tree
Hide file tree
Showing 5 changed files with 27 additions and 59 deletions.
2 changes: 2 additions & 0 deletions CHANGELOG.rst
Expand Up @@ -25,6 +25,8 @@ Changes and deprecations:
* The old Celery based background jobs have been removed in CKAN 2.8 in favour of the new RQ based
jobs (http://docs.ckan.org/en/latest/maintaining/background-tasks.html). Extensions can still
of course use Celery but they will need to handle the management themselves.
* `ckan.recaptcha.version` config option is removed, since v2 is the only valid
version now (#4061)

v2.7.3 2018-03-15
=================
Expand Down
1 change: 0 additions & 1 deletion ckan/config/deployment.ini_tmpl
Expand Up @@ -133,7 +133,6 @@ ckan.display_timezone = server
# package_hide_extras = for_search_index_only
#package_edit_return_url = http://another.frontend/dataset/<NAME>
#package_new_return_url = http://another.frontend/dataset/<NAME>
#ckan.recaptcha.version = 1
#ckan.recaptcha.publickey =
#ckan.recaptcha.privatekey =
#licenses_group_url = http://licenses.opendefinition.org/licenses/groups/ckan.json
Expand Down
1 change: 0 additions & 1 deletion ckan/lib/app_globals.py
Expand Up @@ -42,7 +42,6 @@
# has been setup in load_environment():
'ckan.site_id': {},
'ckan.recaptcha.publickey': {'name': 'recaptcha_publickey'},
'ckan.recaptcha.version': {'name': 'recaptcha_version', 'default': '1'},
'ckan.template_title_deliminater': {'default': '-'},
'ckan.template_head_end': {},
'ckan.template_footer_end': {},
Expand Down
63 changes: 22 additions & 41 deletions ckan/lib/captcha.py
Expand Up @@ -13,48 +13,29 @@ def check_recaptcha(request):
if not recaptcha_private_key:
# Recaptcha not enabled
return

client_ip_address = request.environ.get('REMOTE_ADDR', 'Unknown IP Address')

recaptcha_version = config.get('ckan.recaptcha.version', '1')
if recaptcha_version is '1':
recaptcha_response_field = request.params.get('recaptcha_response_field', '')
recaptcha_server_name = 'http://api-verify.recaptcha.net/verify'
recaptcha_challenge_field = request.params.get('recaptcha_challenge_field')

# recaptcha_response_field will be unicode if there are foreign chars in
# the user input. So we need to encode it as utf8 before urlencoding or
# we get an exception (#1431).
params = urllib.urlencode(dict(privatekey=recaptcha_private_key,
remoteip=client_ip_address,
challenge=recaptcha_challenge_field,
response=recaptcha_response_field.encode('utf8')))
f = urllib2.urlopen(recaptcha_server_name, params)
data = f.read()
f.close()

if not data.lower().startswith('true'):
raise CaptchaError()
elif recaptcha_version is '2':
recaptcha_response_field = request.params.get('g-recaptcha-response', '')
recaptcha_server_name = 'https://www.google.com/recaptcha/api/siteverify'

# recaptcha_response_field will be unicode if there are foreign chars in
# the user input. So we need to encode it as utf8 before urlencoding or
# we get an exception (#1431).
params = urllib.urlencode(dict(secret=recaptcha_private_key,
remoteip=client_ip_address,
response=recaptcha_response_field.encode('utf8')))
f = urllib2.urlopen(recaptcha_server_name, params)
data = json.load(f)
f.close()

try:
if not data['success']:
raise CaptchaError()
except IndexError:
# Something weird with recaptcha response

# reCAPTCHA v2
recaptcha_response_field = request.params.get('g-recaptcha-response', '')
recaptcha_server_name = 'https://www.google.com/recaptcha/api/siteverify'

# recaptcha_response_field will be unicode if there are foreign chars in
# the user input. So we need to encode it as utf8 before urlencoding or
# we get an exception (#1431).
params = urllib.urlencode(dict(secret=recaptcha_private_key,
remoteip=client_ip_address,
response=recaptcha_response_field.encode('utf8')))
f = urllib2.urlopen(recaptcha_server_name, params)
data = json.load(f)
f.close()

try:
if not data['success']:
raise CaptchaError()
except IndexError:
# Something weird with recaptcha response
raise CaptchaError()

class CaptchaError(ValueError):
pass
pass
19 changes: 3 additions & 16 deletions doc/maintaining/configuration.rst
Expand Up @@ -1032,36 +1032,23 @@ web interface. ``dumps_format`` is just a string for display. Example::

ckan.dumps_format = CSV/JSON

.. _ckan.recaptcha.version:

ckan.recaptcha.version
^^^^^^^^^^^^^^^^^^^^^^^^

The version of Recaptcha to use, for example::

ckan.recaptcha.version = 1

Default Value: 1

Valid options: 1, 2

.. _ckan.recaptcha.publickey:

ckan.recaptcha.publickey
^^^^^^^^^^^^^^^^^^^^^^^^

The public key for your Recaptcha account, for example::
The public key for your reCAPTCHA account, for example::

ckan.recaptcha.publickey = 6Lc...-KLc

To get a Recaptcha account, sign up at: http://www.google.com/recaptcha
To get a reCAPTCHA account, sign up at: http://www.google.com/recaptcha

.. _ckan.recaptcha.privatekey:

ckan.recaptcha.privatekey
^^^^^^^^^^^^^^^^^^^^^^^^^

The private key for your Recaptcha account, for example::
The private key for your reCAPTCHA account, for example::

ckan.recaptcha.privatekey = 6Lc...-jP

Expand Down

0 comments on commit d7655c8

Please sign in to comment.