Skip to content

Commit 35ad746

Browse files
authored
Replace hCaptcha with Altcha #235 (#278)
Signed-off-by: tdruez <[email protected]>
1 parent d702daf commit 35ad746

20 files changed

+81
-99
lines changed

dejacode/settings.py

Lines changed: 1 addition & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -94,8 +94,6 @@
9494
SITE_URL = env.str("SITE_URL", default="")
9595

9696
ENABLE_SELF_REGISTRATION = env.bool("ENABLE_SELF_REGISTRATION", default=False)
97-
HCAPTCHA_SITEKEY = env.str("HCAPTCHA_SITEKEY", default="")
98-
HCAPTCHA_SECRET = env.str("HCAPTCHA_SECRET", default="")
9997

10098
# This instructs the browser to only send these cookies over HTTPS connections.
10199
# Note that this will mean that sessions will not work over HTTP, and the CSRF
@@ -167,9 +165,6 @@ def gettext_noop(s):
167165
# https://docs.djangoproject.com/en/dev/ref/settings/#data-upload-max-number-fields
168166
DATA_UPLOAD_MAX_NUMBER_FIELDS = env.int("DATA_UPLOAD_MAX_NUMBER_FIELDS", default=10000)
169167

170-
# hCaptcha script location for registration form
171-
HCAPTCHA_JS_API_URL = env.str("HCAPTCHA_JS_API_URL", default="/static/js/hcaptcha.js")
172-
173168
EXTRA_MIDDLEWARE = env.list("EXTRA_MIDDLEWARE", default=[])
174169

175170
MIDDLEWARE = [
@@ -332,7 +327,7 @@ def gettext_noop(s):
332327
"axes",
333328
"django_otp",
334329
"django_otp.plugins.otp_totp",
335-
"hcaptcha_field",
330+
"django_altcha",
336331
]
337332

338333
PROJECT_APPS = [

dejacode/static/css/dejacode_bootstrap.css

Lines changed: 0 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -741,11 +741,6 @@ body.signup-form h1 {
741741
body.signup-form .asteriskField {
742742
display: none;
743743
}
744-
body.signup-form .hcaptchawidget {
745-
height:85px !important;
746-
border:0;
747-
text-align:center;
748-
}
749744

750745
/* -- Cards -- */
751746
.card-border-color {

dejacode/static/js/hcaptcha.js

Lines changed: 0 additions & 3 deletions
This file was deleted.

dje/registration.py

Lines changed: 8 additions & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -24,10 +24,10 @@
2424
from crispy_forms.layout import Field
2525
from crispy_forms.layout import Fieldset
2626
from crispy_forms.layout import Layout
27+
from django_altcha import AltchaField
2728
from django_registration.backends.activation.views import ActivationView
2829
from django_registration.exceptions import ActivationError
2930
from django_registration.forms import RegistrationFormUniqueEmail
30-
from hcaptcha_field import hCaptchaField
3131

3232
from dje.forms import StrictSubmit
3333
from dje.models import Dataspace
@@ -86,8 +86,11 @@ def get_user(self, username):
8686
class DejaCodeRegistrationForm(RegistrationFormUniqueEmail):
8787
"""Used in `registration.backends.hmac.views.RegistrationView`."""
8888

89-
use_required_attribute = False
90-
hcaptcha = hCaptchaField()
89+
use_required_attribute = True
90+
captcha = AltchaField(
91+
floating=True,
92+
hidefooter=True,
93+
)
9194

9295
class Meta(RegistrationFormUniqueEmail.Meta):
9396
model = User
@@ -98,7 +101,7 @@ class Meta(RegistrationFormUniqueEmail.Meta):
98101
"last_name",
99102
"company",
100103
"password1",
101-
"hcaptcha",
104+
"captcha",
102105
"updates_email_notification",
103106
]
104107

@@ -124,8 +127,6 @@ def __init__(self, *args, **kwargs):
124127
self.fields["last_name"].required = True
125128
self.fields["company"].required = True
126129

127-
self.fields["hcaptcha"].label = ""
128-
129130
notification_label = "Receive updates on DejaCode features and news"
130131
self.fields["updates_email_notification"].label = notification_label
131132

@@ -167,7 +168,7 @@ def helper(self):
167168
Field("updates_email_notification"),
168169
css_class="alert alert-primary px-2 py-2",
169170
),
170-
"hcaptcha",
171+
"captcha",
171172
tos,
172173
Div(
173174
StrictSubmit(

dje/templates/django_registration/registration_form.html

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -74,13 +74,13 @@ <h4 class="text-warning mb-3 mt-2">Private DejaCode Evaluation Instance</h4>
7474
</div>
7575

7676
<div class="col-sm-5 offset-sm-1">
77-
<h1 class="text-white mt-0 mb-2">Create your DejaCode account</h1>
77+
<h1 class="text-white mt-0 mb-3">Create your DejaCode account</h1>
7878
<div class="card">
7979
<div class="card-body">
8080
{% crispy form %}
8181
</div>
8282
</div>
83-
<div class="text-center fw-normal m-4">
83+
<div class="text-center fw-normal my-3">
8484
<a href="{% url 'login' %}" class="text-white">Already have an account?</a>
8585
</div>
8686
</div>

dje/tests/test_registration.py

Lines changed: 8 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -16,8 +16,8 @@
1616
from django.test import override_settings
1717
from django.urls import reverse
1818

19+
from django_altcha import AltchaField
1920
from django_registration.backends.activation.views import RegistrationView
20-
from hcaptcha_field import hCaptchaField
2121

2222
from dje.registration import REGISTRATION_DEFAULT_GROUPS
2323
from dje.tests import refresh_url_cache
@@ -33,8 +33,8 @@ class DejaCodeUserRegistrationTestCase(TestCase):
3333
def setUp(self):
3434
refresh_url_cache()
3535

36-
self.hcaptcha_patch = patch.object(hCaptchaField, "validate", return_value=True)
37-
self.hcaptcha_patch.start()
36+
self.captcha_patch = patch.object(AltchaField, "validate", return_value=True)
37+
self.captcha_patch.start()
3838

3939
self.registration_data = {
4040
"username": "username",
@@ -46,7 +46,7 @@ def setUp(self):
4646
}
4747

4848
def tearDown(self):
49-
self.hcaptcha_patch.stop()
49+
self.captcha_patch.stop()
5050

5151
def test_user_registration_form_submit(self):
5252
url = reverse("django_registration_register")
@@ -84,6 +84,8 @@ def test_user_registration_form_submit(self):
8484
self.assertTrue("New registration for user username [email protected]" in body)
8585

8686
def test_user_registration_form_validators(self):
87+
self.captcha_patch.stop()
88+
8789
url = reverse("django_registration_register")
8890
self.registration_data["username"] = "ab"
8991
self.registration_data["email"] = "wrong"
@@ -103,8 +105,10 @@ def test_user_registration_form_validators(self):
103105
"This password is too short. It must contain at least 8 characters.",
104106
"Your password must contain at least one special character.",
105107
],
108+
"captcha": ["ALTCHA CAPTCHA token is missing."],
106109
}
107110
self.assertEqual(expected, response.context["form"].errors)
111+
self.captcha_patch.start()
108112

109113
def test_user_registration_account_activation(self):
110114
url = reverse("django_registration_register")

setup.cfg

Lines changed: 5 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -51,7 +51,7 @@ install_requires =
5151
wheel==0.45.1
5252
pip==25.0.1
5353
# Django
54-
Django==5.1.6
54+
Django==5.1.7
5555
asgiref==3.8.1
5656
typing_extensions==4.12.2
5757
sqlparse==0.5.3
@@ -62,18 +62,20 @@ install_requires =
6262
django-filter==24.3
6363
django-registration==3.4
6464
confusable_homoglyphs==3.3.1
65-
django-hcaptcha-field==1.4.0
6665
django-guardian==2.4.0
6766
django-environ==0.12.0
6867
django-debug-toolbar==5.0.1
68+
# CAPTCHA
69+
altcha==0.1.9
70+
django_altcha==0.1.2
6971
# REST API
7072
djangorestframework==3.15.2
7173
# API documentation, `coreapi` and its requirements:
7274
coreapi==2.3.3
7375
MarkupSafe==3.0.2
7476
coreschema==0.0.4
7577
itypes==1.2.0
76-
Jinja2==3.1.5
78+
Jinja2==3.1.6
7779
uritemplate==4.1.1
7880
# Access log
7981
django-axes==5.35.0

thirdparty/dist/Django-5.1.6-py3-none-any.whl.ABOUT

Lines changed: 0 additions & 14 deletions
This file was deleted.
7.89 MB
Binary file not shown.
Lines changed: 14 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,14 @@
1+
about_resource: Django-5.1.7-py3-none-any.whl
2+
name: django
3+
version: 5.1.7
4+
download_url: https://files.pythonhosted.org/packages/ba/0f/7e042df3d462d39ae01b27a09ee76653692442bc3701fbfa6cb38e12889d/Django-5.1.7-py3-none-any.whl
5+
package_url: pkg:pypi/[email protected]
6+
license_expression: bsd-new
7+
copyright: Copyright django project contributors
8+
attribute: yes
9+
checksum_md5: bf291218572733211f4f41fab183d2e4
10+
checksum_sha1: e5d18f470b91eb56f0a50ce1573348a69bc944d6
11+
licenses:
12+
- key: bsd-new
13+
name: BSD-3-Clause
14+
file: bsd-new.LICENSE

0 commit comments

Comments
 (0)