Skip to content

Commit 09ca590

Browse files
authored
Merge branch 'main' into Page-Updated
2 parents e5caa29 + 52069f4 commit 09ca590

File tree

5 files changed

+27
-5
lines changed

5 files changed

+27
-5
lines changed

requirements.txt

Lines changed: 3 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -20,7 +20,7 @@ charset-normalizer==2.0.12
2020
click==8.1.2
2121
coreapi==2.3.3
2222
coreschema==0.0.4
23-
cryptography==43.0.1
23+
cryptography==44.0.1
2424
crispy-bootstrap4==2024.1
2525
cwe2==3.0.0
2626
dateparser==1.1.1
@@ -31,6 +31,7 @@ Django==4.2.17
3131
django-crispy-forms==2.3
3232
django-environ==0.11.2
3333
django-filter==24.3
34+
django-recaptcha==4.0.0
3435
django-widget-tweaks==1.5.0
3536
djangorestframework==3.15.2
3637
doc8==0.11.1
@@ -53,7 +54,7 @@ ipython==8.10.0
5354
isort==5.10.1
5455
itypes==1.2.0
5556
jedi==0.18.1
56-
Jinja2==3.1.5
57+
Jinja2==3.1.6
5758
jsonschema==3.2.0
5859
license-expression==30.3.1
5960
lxml==4.9.1

setup.cfg

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -99,6 +99,8 @@ install_requires =
9999
python-dotenv
100100
texttable
101101

102+
django-recaptcha>=4.0.0
103+
102104

103105
[options.extras_require]
104106
dev =

vulnerabilities/forms.py

Lines changed: 6 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -9,6 +9,8 @@
99

1010
from django import forms
1111
from django.core.validators import validate_email
12+
from django_recaptcha.fields import ReCaptchaField
13+
from django_recaptcha.widgets import ReCaptchaV2Checkbox
1214

1315
from vulnerabilities.models import ApiUser
1416

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

43+
captcha = ReCaptchaField(
44+
error_messages={"required": ("Captcha is required")}, widget=ReCaptchaV2Checkbox
45+
)
46+
4147
class Meta:
4248
model = ApiUser
4349
fields = (

vulnerabilities/templates/api_user_creation_form.html

Lines changed: 9 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -14,11 +14,17 @@
1414
</article>
1515
{% endfor %}
1616
<div id="form-errors" class="message is-danger {% if not form.errors %}is-hidden{% endif %}">
17-
{% for field_name, errors in form.errors.items %}
17+
{% if form.errors.captcha %}
1818
<div class="message-body">
19-
{{ errors }}
19+
{{ form.errors.captcha }}
2020
</div>
21-
{% endfor %}
21+
{% else %}
22+
<div class="message-body">
23+
{% for error in form.errors.values %}
24+
{{ error }}
25+
{% endfor %}
26+
</div>
27+
{% endif %}
2228
</div>
2329
<h2 class="subtitle mb-0 pt-2 mb-2">
2430
<b>VulnerableCode API key request</b>

vulnerablecode/settings.py

Lines changed: 7 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -83,8 +83,15 @@
8383
"drf_spectacular",
8484
# required for Django collectstatic discovery
8585
"drf_spectacular_sidecar",
86+
"django_recaptcha",
8687
)
8788

89+
RECAPTCHA_PUBLIC_KEY = env.str("RECAPTCHA_PUBLIC_KEY", "")
90+
RECAPTCHA_PRIVATE_KEY = env.str("RECAPTCHA_PRIVATE_KEY", "")
91+
SILENCED_SYSTEM_CHECKS = ["captcha.recaptcha_test_key_error"]
92+
RECAPTCHA_DOMAIN = env.str("RECAPTCHA_DOMAIN", "www.recaptcha.net")
93+
94+
8895
MIDDLEWARE = (
8996
"django.middleware.security.SecurityMiddleware",
9097
"django.contrib.sessions.middleware.SessionMiddleware",

0 commit comments

Comments
 (0)