Skip to content

Commit 18a8778

Browse files
committed
Merge branch 'main' into release/5
2 parents cc5151f + b59625c commit 18a8778

9 files changed

Lines changed: 58 additions & 13 deletions

File tree

coderedcms/models/page_models.py

Lines changed: 4 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1640,7 +1640,10 @@ def contains_spam(self, request) -> bool:
16401640
utils.get_ip(request),
16411641
)
16421642
# Score ranges from 0 (likely spam) to 1 (likely good).
1643-
return rr.score < ls.recaptcha_threshold
1643+
if rr.success and rr.score >= 0:
1644+
return rr.score < ls.recaptcha_threshold
1645+
else:
1646+
return True
16441647
elif ls.spam_service == ls.SpamService.RECAPTCHA_V2:
16451648
rr = verify_response(
16461649
request.POST.get("g-recaptcha-response", ""),

coderedcms/project_template/basic/pyproject.toml

Lines changed: 5 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -1,3 +1,8 @@
1+
[project]
2+
name = "{{ project_name }}"
3+
version = "0.1.0"
4+
requires-python = ">=3.9"
5+
16
[tool.black]
27
line-length = 80
38
extend-exclude = ["migrations"]

coderedcms/project_template/pro/pyproject.toml

Lines changed: 5 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -1,3 +1,8 @@
1+
[project]
2+
name = "{{ project_name }}"
3+
version = "0.1.0"
4+
requires-python = ">=3.9"
5+
16
[tool.black]
27
line-length = 80
38
extend-exclude = ["migrations"]

coderedcms/recaptcha.py

Lines changed: 7 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -10,7 +10,7 @@
1010

1111

1212
class RecaptchaResponse(typing.NamedTuple):
13-
success: bool
13+
success: typing.Union[bool, None]
1414
score: float
1515
error_codes: typing.List[str]
1616
original_data: typing.Dict[str, typing.Any]
@@ -43,11 +43,12 @@ def verify_response(recaptcha_response: str, secret_key: str, remoteip: str):
4343
response = urlopen(request)
4444
data = json.loads(response.read().decode("utf8"))
4545
response.close()
46-
logger.info(f"reCAPTCHA response: {data}")
47-
# Default to good (likely not spam) values if they are not present.
48-
return RecaptchaResponse(
49-
success=data.get("success", True),
50-
score=data.get("score", 1.0),
46+
# Default to sentinel values if not provided by Google.
47+
rr = RecaptchaResponse(
48+
success=data.get("success", None),
49+
score=data.get("score", -1.0),
5150
error_codes=data.get("error-codes", []),
5251
original_data=data,
5352
)
53+
logger.info(f"reCAPTCHA response: {rr}")
54+
return rr

coderedcms/templates/coderedcms/includes/form_button.html

Lines changed: 5 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -16,10 +16,15 @@
1616
<input type="hidden" name="g-recaptcha-response">
1717
<button
1818
type="button"
19+
id="{{page.get_form_id}}Button"
1920
class="btn {{page.button_size}} {{page.button_style}} {{page.button_css_class}}"
2021
onclick="recaptchaSubmit('{{ page.get_form_id }}')"
2122
>
2223
{{ button_text|default:page.button_text }}
24+
<span class="d-none ps-1" id="{{page.get_form_id}}ButtonSpinner">
25+
<span class="spinner-border spinner-border-sm" aria-hidden="true"></span>
26+
<span class="visually-hidden" role="status">Submitting...</span>
27+
</span>
2328
</button>
2429
{% else %}
2530
<button type="submit" class="btn {{page.button_size}} {{page.button_style}} {{page.button_css_class}}">

coderedcms/templates/coderedcms/pages/base.html

Lines changed: 9 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -193,9 +193,13 @@ <h2 class="text-center my-5">{% trans "Related" %}</h2>
193193
<script src="https://www.google.com/recaptcha/api.js?render={{ ls.recaptcha_public_key }}"></script>
194194
<script>
195195
function recaptchaSubmit(formId) {
196-
var form = document.getElementById(formId);
196+
let form = document.getElementById(formId);
197+
let spinner = document.getElementById(`${formId}ButtonSpinner`);
198+
let button = document.getElementById(`${formId}Button`)
197199
if (form.reportValidity()) {
198200
grecaptcha.ready(function() {
201+
button.disabled = true;
202+
spinner.classList.remove("d-none");
199203
grecaptcha.execute(
200204
'{{ ls.recaptcha_public_key }}',
201205
{action: 'submit'}
@@ -205,7 +209,10 @@ <h2 class="text-center my-5">{% trans "Related" %}</h2>
205209
function(el) {el.value = token}
206210
);
207211
document.getElementById(formId).submit();
208-
});
212+
}).finally(function() {
213+
button.disabled = false;
214+
spinner.classList.add('d-none')
215+
})
209216
});
210217
}
211218
}

docs/getting_started/tutorial03.rst

Lines changed: 2 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -194,10 +194,8 @@ Lookin' good!
194194
The home page preview after adding the card grid.
195195

196196
.. note::
197-
At this point you may notice that the cards aren't the same height. You can fix this two ways. One you can add the bootstrap
198-
CSS class of h-100 to each card, two you can add `$card-height: 100%` in the _variables.scss. If you use the sass option remember to compile the sass files.
199-
This is the most basic use case of card-grid check out :ref:`card-grid` for more information.
200-
197+
At this point you may notice that the cards aren't the same height.
198+
201199
To make all the cards equal height, We added bootstrap class h-100 to each card as seen here:
202200

203201
.. figure:: images/tut03/h_100.jpeg

docs/releases/index.rst

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -33,6 +33,7 @@ Supported Versions:
3333
.. toctree::
3434
:maxdepth: 1
3535

36+
v5.0.1
3637
v5.0.0
3738
v4.1.1
3839
v4.1.0

docs/releases/v5.0.1.rst

Lines changed: 20 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,20 @@
1+
v5.0.1 release notes
2+
====================
3+
4+
5+
Bug fixes
6+
---------
7+
8+
* Fix bug where some spam form submissions were allowed through when using reCAPTCHA v3.
9+
10+
11+
New features
12+
------------
13+
14+
* While submitting a recaptcha v3 form, the button is disabled and shows a spinner.
15+
16+
17+
Thank you!
18+
----------
19+
20+
Thanks to everyone who contributed to `5.0.1 on GitHub <https://github.com/coderedcorp/coderedcms/milestone/62?closed=1>`_.

0 commit comments

Comments
 (0)