kbytesys / django-recaptcha2 Goto Github PK
View Code? Open in Web Editor NEWDjango reCaptcha v2 field/widget
License: GNU Lesser General Public License v2.1
Django reCaptcha v2 field/widget
License: GNU Lesser General Public License v2.1
Hi,
thanks for this great package !
I have found a few minor issues when running with python -Wall
, namely:
\Python36\lib\importlib\_bootstrap_external.py:426: ImportWarning: Not importing directory env\lib\site-packages\snowpenguin: missing __init__
_warnings.warn(msg.format(portions[0]), ImportWarning)
\Python36\lib\importlib\_bootstrap_external.py:426: ImportWarning: Not importing directory env\lib\site-packages\snowpenguin\django: missing __init__
_warnings.warn(msg.format(portions[0]), ImportWarning)
# Repeated about 20 times ...
I'm not sure how severe this is, but at least it pollutes the console output, so probably this would be worth fixing ?
Cheers,
Lorcan
In the current version of recaptcha2 the recaptcha_host variable is passed to the wrong tag (recaptcha_invisible_button), so recaptcha_init tries to include the api.js from the site directly instead of the value specified in RECAPTCHA_PROXY_HOST or https://google.com
I will do a Pull request which fixes the problem.
Hello,
I have a signup page with a form and added a captcha field, but it seems to be blank.
Django version 2.1
class SignUpForm(UserCreationForm):
captcha = ReCaptchaField(widget=ReCaptchaWidget())
def init(self, *args, **kwargs):
super(SignUpForm, self).init(*args, **kwargs)
for field_name, field in self.fields.items():
field.widget.attrs['class'] = 'form-control'
class Meta:
model = CustomUser
While the template render it seems to show the captcha field name but the actual captcha doesnt render at all. There are no messages showing.
How to reload this plugin after ajax request?
$('#id_input').keyup(function(e){
let url = index_url;
$.ajax({
type: "POST",
url: url,
data: {
'input': $('#id_input').val(),
'offer_type': $('#id_offer_type').val(),
'category': $('#id_category').val()
},
success: function (data) {
$('#offer-objects').html(data);
},
complete: function(){
SwiperReload();
},
});
});
Something like that. If recaptcha is inside div with ID offer objects (#offerobjects) it does not load after ajax request finished (inside success function).
Any ideas?
How to start。
Hello!
I think that there is a missing space in recaptcha_invisible_button.html after g-recaptcha
, since the addition of extra_css_classes
to recaptcha_invisible_button
results in broken css for button. So as for now extra_css_classes
should start with space, and that's not quite convenient.
On pages where captcha display is conditional, in cases where no captcha is displayed, it would be nice to not load the captcha script. But if you're including {% recaptcha_init %}
in a page's <head>
tag you have to do the captcha check in two places. It would also make first time setup easier as you wouldn't need to edit any of your project templates to facilitate integration.
It would be nice if you add some information how to validate captcha after submit.
On line https://github.com/kbytesys/django-recaptcha2/blob/master/snowpenguin/django/recaptcha2/fields.py#L47 we crash if 'error-codes' is not defined in the json data. I think this might have happened as a result of some sort of glitch with Google servers.
Traceback:
File "/opt/python/run/venv/lib64/python3.4/site-packages/django/core/handlers/base.py" in get_response
149. response = self.process_exception_by_middleware(e, request)
File "/opt/python/run/venv/lib64/python3.4/site-packages/django/core/handlers/base.py" in get_response
147. response = wrapped_callback(request, *callback_args, **callback_kwargs)
File "/usr/lib64/python3.4/contextlib.py" in inner
30. return func(*args, **kwds)
File "/opt/python/run/venv/lib64/python3.4/site-packages/django/views/generic/base.py" in view
68. return self.dispatch(request, *args, **kwargs)
File "/opt/python/run/venv/lib64/python3.4/site-packages/django/utils/decorators.py" in _wrapper
67. return bound_func(*args, **kwargs)
File "/opt/python/run/venv/lib64/python3.4/site-packages/django/views/decorators/debug.py" in sensitive_post_parameters_wrapper
76. return view(request, *args, **kwargs)
File "/opt/python/run/venv/lib64/python3.4/site-packages/django/utils/decorators.py" in bound_func
63. return func.__get__(self, type(self))(*args2, **kwargs2)
File "/opt/python/current/app/facs/formtest/views.py" in dispatch
552. return super(RegistrationView, self).dispatch(request, *args, **kwargs)
File "/opt/python/run/venv/lib/python3.4/site-packages/allauth/account/views.py" in dispatch
69. **kwargs)
File "/opt/python/run/venv/lib64/python3.4/site-packages/django/views/generic/base.py" in dispatch
88. return handler(request, *args, **kwargs)
File "/opt/python/run/venv/lib/python3.4/site-packages/allauth/account/views.py" in post
84. if form.is_valid():
File "/opt/python/run/venv/lib64/python3.4/site-packages/django/forms/forms.py" in is_valid
161. return self.is_bound and not self.errors
File "/opt/python/run/venv/lib64/python3.4/site-packages/django/forms/forms.py" in errors
153. self.full_clean()
File "/opt/python/run/venv/lib/python3.4/site-packages/django_superform/forms.py" in full_clean
220. super(SuperFormMixin, self).full_clean()
File "/opt/python/run/venv/lib64/python3.4/site-packages/django/forms/forms.py" in full_clean
362. self._clean_fields()
File "/opt/python/run/venv/lib64/python3.4/site-packages/django/forms/forms.py" in _clean_fields
380. value = field.clean(value)
File "/opt/python/run/venv/lib/python3.4/site-packages/snowpenguin/django/recaptcha2/fields.py" in clean
47. if 'missing-input-secret' in json_response['error-codes'] or \
Exception Type: KeyError at ...
Exception Value: 'error-codes'
Request information:
GET: No GET data
praekelt/django-recaptcha (which it looks like this project follows the API of pretty closely) allows you to pass private_key
and public_key
kwargs when constructing a new ReCaptchaField as opposed to using keys in settings. This was nice because it allowed more than one set of keys to be used per project and let you defer the selection of a keyset for a form until runtime. It would be nice to see the same feature here.
This is working fine for me on my dev and stage environments. I just launched to a www domain. Recaptcha field renders and can be selected appropriately, but when I submit I get
Connection to reCaptcha server failed
I see that your code logs the exception. How can I capture the log info?
I have multiple user registration forms on a single page. The captcha is getting rendered for only first form on the page and not for others. Even though I have set explicit=True
in forms.py and have also included
{% recaptcha_explicit_support %} and {% recaptcha_explicit_init %} in the template.
i have multi forms in one page i try to render multi invisible recapcha but not work with me how can and when I try to follow way on wiki i got error closed tag? can any exmple or something to help me
My form, which uses django-crispy-forms
and django-recaptcha2
, has suddenly stopped working after I updated to 1.0.3 of django-recaptcha2
and 1.7.2 of django-crispy-forms
.
Here is the traceback (I've replaced the name of the project and omitted my home directory for privacy reasons):
Traceback (most recent call last):
File "~/.local/share/virtualenvs/django-project-1vOU-KL3/lib/python3.6/site-packages/django/core/handlers/exception.py", line 34, in inner
response = get_response(request)
File "~/.local/share/virtualenvs/django-project-1vOU-KL3/lib/python3.6/site-packages/django/core/handlers/base.py", line 126, in _get_response
response = self.process_exception_by_middleware(e, request)
File "~/.local/share/virtualenvs/django-project-1vOU-KL3/lib/python3.6/site-packages/django/core/handlers/base.py", line 124, in _get_response
response = wrapped_callback(request, *callback_args, **callback_kwargs)
File "~/Git/django-project/app/views/SignupView.py", line 21, in SignupView
"form": form
File "~/.local/share/virtualenvs/django-project-1vOU-KL3/lib/python3.6/site-packages/django/shortcuts.py", line 36, in render
content = loader.render_to_string(template_name, context, request, using=using)
File "~/.local/share/virtualenvs/django-project-1vOU-KL3/lib/python3.6/site-packages/django/template/loader.py", line 62, in render_to_string
return template.render(context, request)
File "~/.local/share/virtualenvs/django-project-1vOU-KL3/lib/python3.6/site-packages/django/template/backends/django.py", line 61, in render
return self.template.render(context)
File "~/.local/share/virtualenvs/django-project-1vOU-KL3/lib/python3.6/site-packages/django/template/base.py", line 171, in render
return self._render(context)
File "~/.local/share/virtualenvs/django-project-1vOU-KL3/lib/python3.6/site-packages/django/template/base.py", line 163, in _render
return self.nodelist.render(context)
File "~/.local/share/virtualenvs/django-project-1vOU-KL3/lib/python3.6/site-packages/django/template/base.py", line 937, in render
bit = node.render_annotated(context)
File "~/.local/share/virtualenvs/django-project-1vOU-KL3/lib/python3.6/site-packages/django/template/base.py", line 904, in render_annotated
return self.render(context)
File "~/.local/share/virtualenvs/django-project-1vOU-KL3/lib/python3.6/site-packages/django/template/loader_tags.py", line 150, in render
return compiled_parent._render(context)
File "~/.local/share/virtualenvs/django-project-1vOU-KL3/lib/python3.6/site-packages/django/template/base.py", line 163, in _render
return self.nodelist.render(context)
File "~/.local/share/virtualenvs/django-project-1vOU-KL3/lib/python3.6/site-packages/django/template/base.py", line 937, in render
bit = node.render_annotated(context)
File "~/.local/share/virtualenvs/django-project-1vOU-KL3/lib/python3.6/site-packages/django/template/base.py", line 904, in render_annotated
return self.render(context)
File "~/.local/share/virtualenvs/django-project-1vOU-KL3/lib/python3.6/site-packages/django/template/loader_tags.py", line 62, in render
result = block.nodelist.render(context)
File "~/.local/share/virtualenvs/django-project-1vOU-KL3/lib/python3.6/site-packages/django/template/base.py", line 937, in render
bit = node.render_annotated(context)
File "~/.local/share/virtualenvs/django-project-1vOU-KL3/lib/python3.6/site-packages/django/template/base.py", line 904, in render_annotated
return self.render(context)
File "~/.local/share/virtualenvs/django-project-1vOU-KL3/lib/python3.6/site-packages/django/template/base.py", line 987, in render
output = self.filter_expression.resolve(context)
File "~/.local/share/virtualenvs/django-project-1vOU-KL3/lib/python3.6/site-packages/django/template/base.py", line 698, in resolve
new_obj = func(obj, *arg_vals)
File "~/.local/share/virtualenvs/django-project-1vOU-KL3/lib/python3.6/site-packages/crispy_forms/templatetags/crispy_forms_filters.py", line 66, in as_crispy_form
return template.render(c)
File "~/.local/share/virtualenvs/django-project-1vOU-KL3/lib/python3.6/site-packages/django/template/backends/django.py", line 61, in render
return self.template.render(context)
File "~/.local/share/virtualenvs/django-project-1vOU-KL3/lib/python3.6/site-packages/django/template/base.py", line 171, in render
return self._render(context)
File "~/.local/share/virtualenvs/django-project-1vOU-KL3/lib/python3.6/site-packages/django/template/base.py", line 163, in _render
return self.nodelist.render(context)
File "~/.local/share/virtualenvs/django-project-1vOU-KL3/lib/python3.6/site-packages/django/template/base.py", line 937, in render
bit = node.render_annotated(context)
File "~/.local/share/virtualenvs/django-project-1vOU-KL3/lib/python3.6/site-packages/django/template/base.py", line 904, in render_annotated
return self.render(context)
File "~/.local/share/virtualenvs/django-project-1vOU-KL3/lib/python3.6/site-packages/crispy_forms/templatetags/crispy_forms_utils.py", line 34, in render
return remove_spaces(self.nodelist.render(context).strip())
File "~/.local/share/virtualenvs/django-project-1vOU-KL3/lib/python3.6/site-packages/django/template/base.py", line 937, in render
bit = node.render_annotated(context)
File "~/.local/share/virtualenvs/django-project-1vOU-KL3/lib/python3.6/site-packages/django/template/base.py", line 904, in render_annotated
return self.render(context)
File "~/.local/share/virtualenvs/django-project-1vOU-KL3/lib/python3.6/site-packages/django/template/defaulttags.py", line 209, in render
nodelist.append(node.render_annotated(context))
File "~/.local/share/virtualenvs/django-project-1vOU-KL3/lib/python3.6/site-packages/django/template/base.py", line 904, in render_annotated
return self.render(context)
File "~/.local/share/virtualenvs/django-project-1vOU-KL3/lib/python3.6/site-packages/django/template/loader_tags.py", line 188, in render
return template.render(context)
File "~/.local/share/virtualenvs/django-project-1vOU-KL3/lib/python3.6/site-packages/django/template/base.py", line 173, in render
return self._render(context)
File "~/.local/share/virtualenvs/django-project-1vOU-KL3/lib/python3.6/site-packages/django/template/base.py", line 163, in _render
return self.nodelist.render(context)
File "~/.local/share/virtualenvs/django-project-1vOU-KL3/lib/python3.6/site-packages/django/template/base.py", line 937, in render
bit = node.render_annotated(context)
File "~/.local/share/virtualenvs/django-project-1vOU-KL3/lib/python3.6/site-packages/django/template/base.py", line 904, in render_annotated
return self.render(context)
File "~/.local/share/virtualenvs/django-project-1vOU-KL3/lib/python3.6/site-packages/django/template/defaulttags.py", line 309, in render
return nodelist.render(context)
File "~/.local/share/virtualenvs/django-project-1vOU-KL3/lib/python3.6/site-packages/django/template/base.py", line 937, in render
bit = node.render_annotated(context)
File "~/.local/share/virtualenvs/django-project-1vOU-KL3/lib/python3.6/site-packages/django/template/base.py", line 904, in render_annotated
return self.render(context)
File "~/.local/share/virtualenvs/django-project-1vOU-KL3/lib/python3.6/site-packages/django/template/defaulttags.py", line 309, in render
return nodelist.render(context)
File "~/.local/share/virtualenvs/django-project-1vOU-KL3/lib/python3.6/site-packages/django/template/base.py", line 937, in render
bit = node.render_annotated(context)
File "~/.local/share/virtualenvs/django-project-1vOU-KL3/lib/python3.6/site-packages/django/template/base.py", line 904, in render_annotated
return self.render(context)
File "~/.local/share/virtualenvs/django-project-1vOU-KL3/lib/python3.6/site-packages/django/template/defaulttags.py", line 309, in render
return nodelist.render(context)
File "~/.local/share/virtualenvs/django-project-1vOU-KL3/lib/python3.6/site-packages/django/template/base.py", line 940, in render
bits.append(str(bit))
File "~/.local/share/virtualenvs/django-project-1vOU-KL3/lib/python3.6/site-packages/django/utils/html.py", line 397, in <lambda>
klass.__str__ = lambda self: mark_safe(klass_str(self))
File "~/.local/share/virtualenvs/django-project-1vOU-KL3/lib/python3.6/site-packages/django/forms/boundfield.py", line 33, in __str__
return self.as_widget()
File "~/.local/share/virtualenvs/django-project-1vOU-KL3/lib/python3.6/site-packages/django/forms/boundfield.py", line 93, in as_widget
renderer=self.form.renderer,
Please let me know if you need any additional information. Thank you! Your work is appreciated!
Is there a way to disable to the app for testing? or a way to included in testing?
recaptcha-init.html loads the reCAPTCHA script from https://google.com, which may be inaccessible for some users (notably, it is blocked in China).
https://recaptcha.net exists for this purpose, so it'd be great if there were out-of-the-box support for it (perhaps as a settings.py
option). Currently we just override the recaptcha-init
template, but it would be nicer if there was built-in support for it.
I would be happy to send a PR in for this if it'd be helpful.
If I set type="audio"
in the widget, then I get data-type="audio "
in the resultant HTML which does not work due to the extra space.
Looking at recaptcha_automatic.html
I see the space before the quotes, think it needs to go after the quotes.
I suspect this isn't going to be required for my project however I thought I should let you know anyway.
diff --git a/snowpenguin/django/recaptcha2/templates/snowpenguin/recaptcha/recaptcha_automatic.html b/snowpenguin/django/recaptcha2/templates/snowpenguin/recaptcha/recaptcha_automatic.html
index 0973024..a873026 100644
--- a/snowpenguin/django/recaptcha2/templates/snowpenguin/recaptcha/recaptcha_automatic.html
+++ b/snowpenguin/django/recaptcha2/templates/snowpenguin/recaptcha/recaptcha_automatic.html
@@ -1 +1 @@
-<div class="g-recaptcha" id="{{ container_id }}" data-sitekey="{{ public_key }}" {% if theme %}data-theme="{{ theme }} "{% endif %}{% if type %}data-type="{{ type }} "{% endif %}{% if size %}data-size="{{ size }} "{% endif %}{% if tabindex %}data-tabindex="{{ tabindex }} "{% endif %}{% if callback %}data-callback="{{ callback }} "{% endif %}{% if expired_callback %}data-expired-callback="{{ expired_callback }}"{% endif %}></div>
\ No newline at end of file
+<div class="g-recaptcha" id="{{ container_id }}" data-sitekey="{{ public_key }}" {% if theme %}data-theme="{{ theme }}" {% endif %}{% if type %}data-type="{{ type }}" {% endif %}{% if size %}data-size="{{ size }}" {% endif %}{% if tabindex %}data-tabindex="{{ tabindex }}" {% endif %}{% if callback %}data-callback="{{ callback }}" {% endif %}{% if expired_callback %}data-expired-callback="{{ expired_callback }}"{% endif %}></div>
A declarative, efficient, and flexible JavaScript library for building user interfaces.
🖖 Vue.js is a progressive, incrementally-adoptable JavaScript framework for building UI on the web.
TypeScript is a superset of JavaScript that compiles to clean JavaScript output.
An Open Source Machine Learning Framework for Everyone
The Web framework for perfectionists with deadlines.
A PHP framework for web artisans
Bring data to life with SVG, Canvas and HTML. 📊📈🎉
JavaScript (JS) is a lightweight interpreted programming language with first-class functions.
Some thing interesting about web. New door for the world.
A server is a program made to process requests and deliver data to clients.
Machine learning is a way of modeling and interpreting data that allows a piece of software to respond intelligently.
Some thing interesting about visualization, use data art
Some thing interesting about game, make everyone happy.
We are working to build community through open source technology. NB: members must have two-factor auth.
Open source projects and samples from Microsoft.
Google ❤️ Open Source for everyone.
Alibaba Open Source for everyone
Data-Driven Documents codes.
China tencent open source team.