8000 Add captcha for user signup by TG1999 · Pull Request #1822 · aboutcode-org/vulnerablecode · GitHub
[go: up one dir, main page]
More Web Proxy on the site http://driver.im/
Skip to content

Add captcha for user signup #1822

New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Merged
merged 1 commit into from
Mar 20, 2025
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension


Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
1 change: 1 addition & 0 deletions requirements.txt
Original file line number Diff line number Diff line change
Expand Up @@ -31,6 +31,7 @@ Django==4.2.17
django-crispy-forms==2.3
django-environ==0.11.2
django-filter==24.3
django-recaptcha==4.0.0
django-widget-tweaks==1.5.0
djangorestframework==3.15.2
doc8==0.11.1
Expand Down
2 changes: 2 additions & 0 deletions setup.cfg
Original file line number Diff line number Diff line change
Expand Up @@ -99,6 +99,8 @@ install_requires =
python-dotenv
texttable

django-recaptcha>=4.0.0


[options.extras_require]
dev =
Expand Down
6 changes: 6 additions & 0 deletions vulnerabilities/forms.py
Original file line number Diff line number Diff line change
Expand Up @@ -9,6 +9,8 @@

from django import forms
from django.core.validators import validate_email
from django_recaptcha.fields import ReCaptchaField
from django_recaptcha.widgets import ReCaptchaV2Checkbox

from vulnerabilities.models import ApiUser

Expand Down Expand Up @@ -38,6 +40,10 @@ class ApiUserCreationForm(forms.ModelForm):
Support a simplified creation for API-only users directly from the UI.
"""

captcha = ReCaptchaField(
error_messages={"required": ("Captcha is required")}, widget=ReCaptchaV2Checkbox
)

class Meta:
model = ApiUser
fields = (
Expand Down
12 changes: 9 additions & 3 deletions vulnerabilities/templates/api_user_creation_form.html
Original file line number Diff line number Diff line change
Expand Up @@ -14,11 +14,17 @@
</article>
{% endfor %}
<div id="form-errors" class="message is-danger {% if not form.errors %}is-hidden{% endif %}">
{% for field_name, errors in form.errors.items %}
{% if form.errors.captcha %}
<div class="message-body">
{{ errors }}
{{ form.errors.captcha }}
</div>
{% endfor %}
{% else %}
<div class="message-body">
{% for error in form.errors.values %}
{{ error }}
{% endfor %}
</div>
{% endif %}
</div>
<h2 class="subtitle mb-0 pt-2 mb-2">
<b>VulnerableCode API key request</b>
Expand Down
7 changes: 7 additions & 0 deletions vulnerablecode/settings.py
Original file line number Diff line number Diff line change
Expand Up @@ -83,8 +83,15 @@
"drf_spectacular",
# required for Django collectstatic discovery
"drf_spectacular_sidecar",
"django_recaptcha",
)

RECAPTCHA_PUBLIC_KEY = env.str("RECAPTCHA_PUBLIC_KEY", "")
RECAPTCHA_PRIVATE_KEY = env.str("RECAPTCHA_PRIVATE_KEY", "")
SILENCED_SYSTEM_CHECKS = ["captcha.recaptcha_test_key_error"]
RECAPTCHA_DOMAIN = env.str("RECAPTCHA_DOMAIN", "www.recaptcha.net")


MIDDLEWARE = (
"django.middleware.security.SecurityMiddleware",
"django.contrib.sessions.middleware.SessionMiddleware",
Expand Down
Loading
0