8000 Replace hCaptcha with Altcha #235 by tdruez · Pull Request #278 · aboutcode-org/dejacode · GitHub
[go: up one dir, main page]
More Web Proxy on the site http://driver.im/
Skip to content

Replace hCaptcha with Altcha #235 #278

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 18 commits into from
Mar 31, 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
7 changes: 1 addition & 6 deletions dejacode/settings.py
Original file line number Diff line number Diff line change
Expand Up @@ -94,8 +94,6 @@
SITE_URL = env.str("SITE_URL", default="")

ENABLE_SELF_REGISTRATION = env.bool("ENABLE_SELF_REGISTRATION", default=False)
HCAPTCHA_SITEKEY = env.str("HCAPTCHA_SITEKEY", default="")
HCAPTCHA_SECRET = env.str("HCAPTCHA_SECRET", default="")

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

# hCaptcha script location for registration form
HCAPTCHA_JS_API_URL = env.str("HCAPTCHA_JS_API_URL", default="/static/js/hcaptcha.js")

EXTRA_MIDDLEWARE = env.list("EXTRA_MIDDLEWARE", default=[])

MIDDLEWARE = [
Expand Down Expand Up @@ -332,7 +327,7 @@ def gettext_noop(s):
"axes",
"django_otp",
"django_otp.plugins.otp_totp",
"hcaptcha_field",
"django_altcha",
]

PROJECT_APPS = [
Expand Down
5 changes: 0 additions & 5 deletions dejacode/static/css/dejacode_bootstrap.css
Original file line number Diff line number Diff line change
Expand Up @@ -741,11 +741,6 @@ body.signup-form h1 {
body.signup-form .asteriskField {
display: none;
}
body.signup-form .hcaptchawidget {
height:85px !important;
border:0;
text-align:center;
}

/* -- Cards -- */
.card-border-color {
Expand Down
3 changes: 0 additions & 3 deletions dejacode/static/js/hcaptcha.js

This file was deleted.

15 changes: 8 additions & 7 deletions dje/registration.py
Original file line number Diff line number Diff line change
Expand Up @@ -24,10 +24,10 @@
from crispy_forms.layout import Field
from crispy_forms.layout import Fieldset
from crispy_forms.layout import Layout
from django_altcha import AltchaField
from django_registration.backends.activation.views import ActivationView
from django_registration.exceptions import ActivationError
from django_registration.forms import RegistrationFormUniqueEmail
from hcaptcha_field import hCaptchaField

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

use_required_attribute = False
hcaptcha = hCaptchaField()
use_required_attribute = True
captcha = AltchaField(
floating=True,
hidefooter=True,
)

class Meta(RegistrationFormUniqueEmail.Meta):
model = User
Expand All @@ -98,7 +101,7 @@ class Meta(RegistrationFormUniqueEmail.Meta):
"last_name",
"company",
"password1",
"hcaptcha",
"captcha",
"updates_email_notification",
]

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

self.fields["hcaptcha"].label = ""

notification_label = "Receive updates on DejaCode features and news"
self.fields["updates_email_notification"].label = notification_label

Expand Down Expand Up @@ -167,7 +168,7 @@ def helper(self):
Field("updates_email_notification"),
css_class="alert alert-primary px-2 py-2",
),
"hcaptcha",
"captcha",
tos,
Div(
StrictSubmit(
Expand Down
4 changes: 2 additions & 2 deletions dje/templates/django_registration/registration_form.html
Original file line number Diff line number Diff line change
Expand Up @@ -74,13 +74,13 @@ <h4 class="text-warning mb-3 mt-2">Private DejaCode Evaluation Instance</h4>
</div>

<div class="col-sm-5 offset-sm-1">
<h1 class="text-white mt-0 mb-2">Create your DejaCode account</h1>
<h1 class="text-white mt-0 mb-3">Create your DejaCode account</h1>
<div class="card">
<div class="card-body">
{% crispy form %}
</div>
</div>
<div class="text-center fw-normal m-4">
<div class="text-center fw-normal my-3">
<a href="{% url 'login' %}" class="text-white">Already have an account?</a>
</div>
</div>
Expand Down
12 changes: 8 additions & 4 deletions dje/tests/test_registration.py
Original file line number Diff line number Diff line change
Expand Up @@ -16,8 +16,8 @@
from django.test import override_settings
from django.urls import reverse

from django_altcha import AltchaField
from django_registration.backends.activation.views import RegistrationView
from hcaptcha_field import hCaptchaField

from dje.registration import REGISTRATION_DEFAULT_GROUPS
from dje.tests import refresh_url_cache
Expand All @@ -33,8 +33,8 @@ class DejaCodeUserRegistrationTestCase(TestCase):
def setUp(self):
refresh_url_cache()

self.hcaptcha_patch = patch.object(hCaptchaField, "validate", return_value=True)
self.hcaptcha_patch.start()
self.captcha_patch = patch.object(AltchaField, "validate", return_value=True)
self.captcha_patch.start()

self.registration_data = {
"username": "username",
Expand All @@ -46,7 +46,7 @@ def setUp(self):
}

def tearDown(self):
self.hcaptcha_patch.stop()
self.captcha_patch.stop()

def test_user_registration_form_submit(self):
url = reverse("django_registration_register")
Expand Down Expand Up @@ -84,6 +84,8 @@ def test_user_registration_form_submit(self):
self.assertTrue("New registration for user username username@company.com" in body)

def test_user_registration_form_validators(self):
self.captcha_patch.stop()

url = reverse("django_registration_register")
self.registration_data["username"] = "ab"
self.registration_data["email"] = "wrong"
Expand All @@ -103,8 +105,10 @@ def test_user_registration_form_validators(self):
"This password is too short. It must contain at least 8 characters.",
"Your password must contain at least one special character.",
],
"captcha": ["ALTCHA CAPTCHA token is missing."],
}
self.assertEqual(expected, response.context["form"].errors)
self.captcha_patch.start()

def test_user_registration_account_activation(self):
url = reverse("django_registration_register")
Expand Down
8 changes: 5 additions & 3 deletions setup.cfg
Original file line number Diff line number Diff line change
Expand Up @@ -51,7 +51,7 @@ install_requires =
wheel==0.45.1
pip==25.0.1
# Django
Django==5.1.6
Django==5.1.7
asgiref==3.8.1
typing_extensions==4.12.2
sqlparse==0.5.3
Expand All @@ -62,18 +62,20 @@ install_requires =
django-filter==24.3
django-registration==3.4
confusable_homoglyphs==3.3.1
django-hcaptcha-field==1.4.0
django-guardian==2.4.0
django-environ==0.12.0
django-debug-toolbar==5.0.1
# CAPTCHA
altcha==0.1.9
django_altcha==0.1.2
# REST API
djangorestframework==3.15.2
# API documentation, `coreapi` and its requirements:
coreapi==2.3.3
MarkupSafe==3.0.2
coreschema==0.0.4
itypes==1.2.0
Jinja2==3.1.5
Jinja2==3.1.6
uritemplate==4.1.1
# Access log
django-axes==5.35.0
Expand Down
14 changes: 0 additions & 14 deletions thirdparty/dist/Django-5.1.6-py3-none-any.whl.ABOUT

This file was deleted.

Binary file not shown.
14 changes: 14 additions & 0 deletions thirdparty/dist/Django-5.1.7-py3-none-any.whl.ABOUT
Original file line number Diff line number Diff line change
@@ -0,0 +1,14 @@
about_resource: Django-5.1.7-py3-none-any.whl
name: django
version: 5.1.7
download_url: https://files.pythonhosted.org/packages/ba/0f/7e042df3d462d39ae01b27a09ee76653692442bc3701fbfa6cb38e12889d/Django-5.1.7-py3-none-any.whl
package_url: pkg:pypi/django@5.1.7
license_expression: bsd-new
copyright: Copyright django project contributors
attribute: yes
checksum_md5: bf291218572733211f4f41fab183d2e4
checksum_sha1: e5d18f470b91eb56f0a50ce1573348a69bc944d6
licenses:
- key: bsd-new
name: BSD-3-Clause
file: bsd-new.LICENSE
Binary file added thirdparty/dist/altcha-0.1.9-py3-none-any.whl
Binary file not shown.
14 changes: 14 additions & 0 deletions thirdparty/dist/altcha-0.1.9-py3-none-any.whl.ABOUT
Original file line number Diff line number Diff line change
@@ -0,0 +1,14 @@
about_resource: altcha-0.1.9-py3-none-any.whl
name: altcha
version: 0.1.9
download_url: https://files.pythonhosted.org/packages/cf/a8/8327d1b64e4961b2c762788efacd3a91d7f38d5bbb59a3393aa316aa95e2/altcha-0.1.9-py3-none-any.whl
package_url: pkg:pypi/altcha@0.1.9
license_expression: mit
copyright: Copyright altcha project contributors
attribute: yes
checksum_md5: 8a7d2b078ad47c4e44deb21cdf47b340
checksum_sha1: aa4570f30c4a2bfd3e9f46a2ca4cbc61026ce39e
licenses:
- key: mit
name: MIT License
file: mit.LICENSE
Binary file not shown.
15 changes: 15 additions & 0 deletions thirdparty/dist/django_altcha-0.1.2-py3-none-any.whl.ABOUT
Original file line number Diff line number Diff line change
@@ -0,0 +1,15 @@
about_resource: django_altcha-0.1.2-py3-none-any.whl
name: django-altcha
version: 0.1.2
download_url: https://files.pythonhosted.org/packages/73/a9/64a0bc421b77ad85f30c0035b55421d6a1a86822a3c951bb02a689ad1054/django_altcha-0.1.2-py3-none-any.whl
package_url: pkg:pypi/django-altcha@0.1.2
license_expression: mit
copyright: Copyright Daniel Regeci
attribute: yes
track_changes: yes
checksum_md5: ffa24bdd7664d6a67ec59db10085e0a3
checksum_sha1: ed8897927d09bf5b894b040a4abb7f3563ff2297
licenses:
- key: mit
name: MIT License
file: mit.LICENSE
Binary file not shown.
17 changes: 0 additions & 17 deletions thirdparty/dist/django_hcaptcha_field-1.4.0-py3-none-any.whl.ABOUT

This file was deleted.

This file was deleted.

14 changes: 0 additions & 14 deletions thirdparty/dist/jinja2-3.1.5-py3-none-any.whl.ABOUT

This file was deleted.

Binary file not shown.
14 changes: 14 additions & 0 deletions thirdparty/dist/jinja2-3.1.6-py3-none-any.whl.ABOUT
Original file line number Diff line number Diff line change
@@ -0,0 +1,14 @@
about_resource: jinja2-3.1.6-py3-none-any.whl
name: jinja2
version: 3.1.6
download_url: https://files.pythonhosted.org/packages/62/a1/3d680cbfd5f4b8f15abc1d571870c5fc3e594bb582bc3b64ea099db13e56/jinja2-3.1.6-py3-none-any.whl
package_url: pkg:pypi/jinja2@3.1.6
license_expression: bsd-new
copyright: Copyright jinja2 project contributors
attribute: yes
checksum_md5: 845b37cea56edd0f4dbd949244e9d798
checksum_sha1: 65a4983e02ace6506cc5fc4b4abd5a992da4e786
licenses:
- key: bsd-new
name: BSD-3-Clause
file: bsd-new.LICENSE
0