Skip to content

Commit a5c4c1d

Browse files
committed
Replace reCAPTCHA with Altcha on API signup page
Signed-off-by: Keshav Priyadarshi <git@keshav.space>
1 parent eadb6e1 commit a5c4c1d

File tree

6 files changed

+40
-44
lines changed

6 files changed

+40
-44
lines changed

requirements.txt

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -28,10 +28,10 @@ decorator==5.1.1
2828
defusedxml==0.7.1
2929
distro==1.7.0
3030
Django==4.2.22
31+
django-altcha==0.2.0
3132
django-crispy-forms==2.3
3233
django-environ==0.11.2
3334
django-filter==24.3
34-
django-recaptcha==4.0.0
3535
django-widget-tweaks==1.5.0
3636
djangorestframework==3.15.2
3737
doc8==0.11.1

setup.cfg

Lines changed: 0 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -102,8 +102,6 @@ install_requires =
102102
python-dotenv
103103
texttable
104104

105-
django-recaptcha>=4.0.0
106-
107105

108106
[options.extras_require]
109107
dev =

vulnerabilities/forms.py

Lines changed: 3 additions & 11 deletions
Original file line numberDiff line numberDiff line change
@@ -11,8 +11,6 @@
1111
from django.contrib.admin.forms import AdminAuthenticationForm
1212
from django.core.validators import validate_email
1313
from django_altcha import AltchaField
14-
from django_recaptcha.fields import ReCaptchaField
15-
from django_recaptcha.widgets import ReCaptchaV2Checkbox
1614

1715
from vulnerabilities.models import ApiUser
1816

@@ -38,13 +36,9 @@ class VulnerabilitySearchForm(forms.Form):
3836

3937

4038
class ApiUserCreationForm(forms.ModelForm):
41-
"""
42-
Support a simplified creation for API-only users directly from the UI.
43-
"""
39+
"""Support a simplified creation for API-only users directly from the UI."""
4440

45-
captcha = ReCaptchaField(
46-
error_messages={"required": ("Captcha is required")}, widget=ReCaptchaV2Checkbox
47-
)
41+
captcha = AltchaField(floating=True)
4842

4943
class Meta:
5044
model = ApiUser
@@ -103,6 +97,4 @@ class PipelineSchedulePackageForm(forms.Form):
10397

10498

10599
class AdminLoginForm(AdminAuthenticationForm):
106-
captcha = AltchaField(
107-
floating=True,
108-
)
100+
captcha = AltchaField(floating=True)

vulnerabilities/templates/admin_login.html

Lines changed: 2 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -89,10 +89,8 @@
8989
<a href="{{ password_reset_url }}">{% translate 'Forgotten your password or username?' %}</a>
9090
</div>
9191
{% endif %}
92-
<div class="field" style="padding-top: 1rem; text-align: center;">
93-
<div class="control" style="display: inline-block;">
94-
{{ form.captcha }}
95-
</div>
92+
<div class="field" style="padding-top: 0.5rem;">
93+
{{ form.captcha }}
9694
</div>
9795
<div class="submit-row">
9896
<input type="submit" value="{% translate 'Log in' %}">

vulnerabilities/templates/api_user_creation_form.html

Lines changed: 34 additions & 15 deletions
Original file line numberDiff line numberDiff line change
@@ -26,11 +26,13 @@
2626
</div>
2727
{% endif %}
2828
</div>
29-
<h2 class="subtitle mb-0 pt-2 mb-2">
30-
<b>VulnerableCode API key request</b>
31-
</h2>
3229

33-
<section class="ml-2 mt-3 pr-4 pt-4 pl-4 pb-4 has-background-light has-border-radius">
30+
<div class="content is-normal">
31+
<h1 class="title is-4">VulnerableCode API Key Request</h1>
32+
<hr />
33+
</div>
34+
35+
<section class="mt-3 mx-6 px-4 py-4 has-background-light has-border-radius">
3436
<p class="pb-2">You need an <b>API key</b> to access the
3537
<a href="{% url 'api-root' %}">VulnerableCode JSON REST API</a>.
3638
Please check the live <a href="{% url 'api_docs' %}"> OpenAPI documentation </a>
@@ -41,17 +43,34 @@ <h2 class="subtitle mb-0 pt-2 mb-2">
4143
</section>
4244

4345
<br/>
44-
<form action = "" method = "post">
45-
{% csrf_token %}
46-
{% for field in form %}
47-
<div class="field mt-2">
48-
<label class="label" for="{{ form.name.id_for_label }}">{{ field.label }}</label>
49-
<div class="control">
50-
{{ field }}
51-
</div>
46+
<div class="columns is-centered">
47+
<div class="column is-half">
48+
<form method = "post">
49+
{% csrf_token %}
50+
<div class="field">
51+
<div class="control">
52+
<input class="input" placeholder="Email" type="email" name="email" id="{{form.email.id_for_label}}"
53+
autofocus required >
5254
</div>
53-
{% endfor %}
54-
<input class="button is-link mt-5" type="submit" value="Request my API Key">
55-
</form>
55+
</div>
56+
<div class="field">
57+
<div class="control">
58+
<input class="input" placeholder="First Name" type="text" name="first_name" id="{{form.first_name.id_for_label}}"
59+
autofocus required>
60+
</div>
61+
</div>
62+
<div class="field">
63+
<div class="control">
64+
<input class="input" placeholder="Last Name" type="text" name="last_name" id="{{form.last_name.id_for_label}}"
65+
autofocus required>
66+
</div>
67+
</div>
68+
<div class="field">
69+
{{ form.captcha }}
70+
</div>
71+
<input class="button is-link mt-5" type="submit" value="Request my API Key">
72+
</form>
73+
</div>
74+
</div>
5675
</section>
5776
{% endblock %}

vulnerablecode/settings.py

Lines changed: 0 additions & 11 deletions
Original file line numberDiff line numberDiff line change
@@ -83,21 +83,10 @@
8383
"drf_spectacular",
8484
# required for Django collectstatic discovery
8585
"drf_spectacular_sidecar",
86-
"django_recaptcha",
8786
"django_rq",
8887
"django_altcha",
8988
)
9089

91-
if env.str("RECAPTCHA_PUBLIC_KEY", None):
92-
RECAPTCHA_PUBLIC_KEY = env.str("RECAPTCHA_PUBLIC_KEY")
93-
94-
if env.str("RECAPTCHA_PRIVATE_KEY", None):
95-
RECAPTCHA_PRIVATE_KEY = env.str("RECAPTCHA_PRIVATE_KEY")
96-
97-
SILENCED_SYSTEM_CHECKS = ["django_recaptcha.recaptcha_test_key_error"]
98-
SILENCED_SYSTEM_CHECKS = ["django_recaptcha.recaptcha_test_key_error"]
99-
RECAPTCHA_DOMAIN = env.str("RECAPTCHA_DOMAIN", "www.recaptcha.net")
100-
10190

10291
MIDDLEWARE = (
10392
"django.middleware.security.SecurityMiddleware",

0 commit comments

Comments
 (0)