Skip to content

Commit

Permalink
Merge 041e738 into dc7cbfe
Browse files Browse the repository at this point in the history
  • Loading branch information
VenturaFranklin committed Jan 23, 2021
2 parents dc7cbfe + 041e738 commit 09d0279
Show file tree
Hide file tree
Showing 2 changed files with 9 additions and 3 deletions.
2 changes: 1 addition & 1 deletion captcha/templates/captcha/includes/js_v3.html
Expand Up @@ -2,7 +2,7 @@
<script src="https://{{ recaptcha_domain }}/recaptcha/api.js?render={{ public_key }}{% if api_params %}&{{ api_params }}{% endif %}"></script>
<script type="text/javascript">
grecaptcha.ready(function() {
grecaptcha.execute('{{ public_key }}', {action: 'form'})
grecaptcha.execute('{{ public_key }}', {action: '{{ action|escape }}'})
.then(function(token) {
console.log("reCAPTCHA validated for 'data-widget-uuid=\"{{ widget_uuid }}\"'. Setting input value...")
var element = document.querySelector('.g-recaptcha[data-widget-uuid="{{ widget_uuid }}"]');
Expand Down
10 changes: 8 additions & 2 deletions captcha/widgets.py
Expand Up @@ -69,15 +69,16 @@ def build_attrs(self, base_attrs, extra_attrs=None):
class ReCaptchaV3(ReCaptchaBase):
template_name = "captcha/widget_v3.html"

def __init__(self, api_params=None, *args, **kwargs):
def __init__(self, api_params=None, action="form", *args, **kwargs):
super(ReCaptchaV3, self).__init__(
api_params=api_params, *args, **kwargs
)
if not self.attrs.get("required_score", None):
self.attrs["required_score"] = getattr(
settings, "RECAPTCHA_REQUIRED_SCORE", None
)

self.action = action

def build_attrs(self, base_attrs, extra_attrs=None):
attrs = super(ReCaptchaV3, self).build_attrs(
base_attrs, extra_attrs
Expand All @@ -86,3 +87,8 @@ def build_attrs(self, base_attrs, extra_attrs=None):

def value_from_datadict(self, data, files, name):
return data.get(name)

def get_context(self, name, value, attrs):
context = super(ReCaptchaV3, self).get_context(name, value, attrs)
context.update({'action': self.action})
return context

0 comments on commit 09d0279

Please sign in to comment.