Skip to content

Commit e6beab8

Browse files
committed
Add the altcha.min.js as a local static file #235
Signed-off-by: tdruez <[email protected]>
1 parent ed86e34 commit e6beab8

File tree

6 files changed

+19
-9
lines changed

6 files changed

+19
-9
lines changed

dejacode/settings.py

Lines changed: 0 additions & 5 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 = [

dejacode/static/js/hcaptcha.js

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

django_altcha/__init__.py

Lines changed: 3 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -109,12 +109,14 @@ class AltchaWidget(HiddenInput):
109109
def __init__(self, **kwargs):
110110
"""Initialize the ALTCHA widget with configurable options."""
111111
super().__init__()
112+
self.js_src_url = "/static/altcha/altcha.min.js"
112113
self.options = {
113114
key: kwargs.get(key, self.default_options[key]) for key in self.default_options
114115
}
115116

116117
def get_context(self, name, value, attrs):
117118
context = super().get_context(name, value, attrs)
119+
context["js_src_url"] = self.js_src_url
118120
context["widget"]["altcha_options"] = self.options # Pass options to template
119121
return context
120122

@@ -151,6 +153,7 @@ def __init__(self, *args, **kwargs):
151153

152154
# Assign the updated widget
153155
kwargs["widget"] = AltchaWidget(**widget_options)
156+
kwargs["widget"].attrs.update()
154157
super().__init__(*args, **kwargs)
155158

156159
def validate(self, value):

django_altcha/static/altcha/altcha.min.js

Lines changed: 8 additions & 0 deletions
Some generated files are not rendered by default. Learn more about customizing how changed files appear on GitHub.
Lines changed: 7 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,7 @@
1+
about_resource: altcha.min.js
2+
name: altcha
3+
version: 1.3.0
4+
download_url: https://cdn.jsdelivr.net/gh/altcha-org/altcha@main/dist/altcha.min.js
5+
package_url: pkg:github/altcha-org/[email protected]
6+
license_expression: mit
7+
copyright: Copyright (c) 2023 Daniel Regeci

django_altcha/templates/altcha_widget.html

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,4 +1,4 @@
1-
<script async defer src="https://eu.altcha.org/js/latest/altcha.min.js" type="module"></script>
1+
<script async defer src="{{ js_src_url }}" type="module"></script>
22
{% include "django/forms/widgets/input.html" %}
33
<altcha-widget name="{{ widget.name }}"
44
{% for key, value in widget.altcha_options.items %}

0 commit comments

Comments
 (0)