Skip to content

Commit

Permalink
Merge pull request #16 from MOwsianowski/improve_turn_off_recaptcha
Browse files Browse the repository at this point in the history
RECAPTCHA_DISABLE improve
  • Loading branch information
kbytesys authored Jul 7, 2020
2 parents cc38802 + 69219ca commit c89a7c0
Show file tree
Hide file tree
Showing 2 changed files with 20 additions and 5 deletions.
5 changes: 3 additions & 2 deletions snowpenguin/django/recaptcha3/fields.py
Original file line number Diff line number Diff line change
Expand Up @@ -15,8 +15,9 @@

class ReCaptchaField(forms.CharField):
def __init__(self, attrs=None, *args, **kwargs):
self._private_key = kwargs.pop('private_key', settings.RECAPTCHA_PRIVATE_KEY)
self._score_threshold = kwargs.pop('score_threshold', settings.RECAPTCHA_SCORE_THRESHOLD)
if os.environ.get('RECAPTCHA_DISABLE', None) is None:
self._private_key = kwargs.pop('private_key', settings.RECAPTCHA_PRIVATE_KEY)
self._score_threshold = kwargs.pop('score_threshold', settings.RECAPTCHA_SCORE_THRESHOLD)

if 'widget' not in kwargs:
kwargs['widget'] = ReCaptchaHiddenInput()
Expand Down
20 changes: 17 additions & 3 deletions snowpenguin/django/recaptcha3/templatetags/recaptcha3.py
Original file line number Diff line number Diff line change
@@ -1,5 +1,8 @@
import os

from django import template
from django.conf import settings
from django.template.loader import get_template

register = template.Library()

Expand All @@ -9,7 +12,6 @@ def recaptcha_key():
return settings.RECAPTCHA_PUBLIC_KEY


@register.inclusion_tag('snowpenguin/recaptcha/recaptcha_init.html')
def recaptcha_init(public_key=None):

return {
Expand All @@ -19,7 +21,6 @@ def recaptcha_init(public_key=None):
}


@register.inclusion_tag('snowpenguin/recaptcha/recaptcha_ready.html')
def recaptcha_ready(public_key=None, action_name=None, custom_callback=None):
return {
'public_key': public_key or settings.RECAPTCHA_PUBLIC_KEY,
Expand All @@ -28,10 +29,23 @@ def recaptcha_ready(public_key=None, action_name=None, custom_callback=None):
}


@register.inclusion_tag('snowpenguin/recaptcha/recaptcha_execute.html')
def recaptcha_execute(public_key=None, action_name=None, custom_callback=None):
return {
'public_key': public_key or settings.RECAPTCHA_PUBLIC_KEY,
'action_name': action_name or settings.RECAPTCHA_DEFAULT_ACTION,
'custom_callback': custom_callback
}


def return_empty_context(*args, **kwargs):
return ''


if not os.environ.get('RECAPTCHA_DISABLE', None):
register.inclusion_tag(get_template('snowpenguin/recaptcha/recaptcha_init.html'))(recaptcha_init)
register.inclusion_tag(get_template('snowpenguin/recaptcha/recaptcha_ready.html'))(recaptcha_ready)
register.inclusion_tag(get_template('snowpenguin/recaptcha/recaptcha_execute.html'))(recaptcha_execute)
else:
register.simple_tag(return_empty_context, name='recaptcha_init')
register.simple_tag(return_empty_context, name='recaptcha_ready')
register.simple_tag(return_empty_context, name='recaptcha_execute')

0 comments on commit c89a7c0

Please sign in to comment.