Skip to content
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

Add hCaptcha backend as an alternative to reCAPTCHA #2312

Open
wants to merge 1 commit into
base: master
Choose a base branch
from

Conversation

Jazzzny
Copy link
Contributor

@Jazzzny Jazzzny commented Jan 20, 2024

Screenshot 2024-01-20 at 4 57 08 PM

This PR adds support for an hCaptcha backend powered by django-hcaptcha-field. Most additions are duplicated from the existing reCAPTCHA backend as the hCaptcha package is very similar.

See https://blog.cloudflare.com/moving-from-recaptcha-to-hcaptcha for possible benefits over reCAPTCHA.

Copy link
Member

@Xyene Xyene left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Thanks for the contribution. The idea of using hCaptcha as an alternate backend seems good to me, especially given how easy this looks to support.

judge/views/register.py Show resolved Hide resolved
@codecov-commenter
Copy link

codecov-commenter commented Dec 31, 2024

Codecov Report

Attention: Patch coverage is 65.21739% with 8 lines in your changes missing coverage. Please review.

Project coverage is 47.76%. Comparing base (fd7fb05) to head (7ef055d).
Report is 61 commits behind head on master.

Files with missing lines Patch % Lines
judge/utils/captcha.py 76.47% 4 Missing ⚠️
judge/views/register.py 33.33% 4 Missing ⚠️
Additional details and impacted files
@@            Coverage Diff             @@
##           master    #2312      +/-   ##
==========================================
+ Coverage   46.76%   47.76%   +0.99%     
==========================================
  Files         251      259       +8     
  Lines       13317    13716     +399     
==========================================
+ Hits         6228     6551     +323     
- Misses       7089     7165      +76     

☔ View full report in Codecov by Sentry.
📢 Have feedback on the report? Share it here.

Satisfy lint
@Jazzzny
Copy link
Contributor Author

Jazzzny commented Dec 31, 2024

Ready for review. Only one backend can ever be active at a given time, however that seems logical.

captcha = ReCaptchaField(widget=ReCaptchaWidget())
if CaptchaField is not None:
if ReCaptchaWidget is not None:
captcha = CaptchaField(widget=ReCaptchaWidget())
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Do we even need this special construction? https://github.com/DMOJ/django-recaptcha2/blob/master/snowpenguin/django/recaptcha2/fields.py#L22 seems to imply that widget=ReCaptchaWidget() is pointless.

Honestly, at this rate, I am tempted to drop ReCAPTCHA soon, given all the problems I ran into with them and also the fact I had to fork the library...

except ImportError:
ReCaptchaField = None
ReCaptchaWidget = None
try:
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

nit:

Suggested change
try:
try:

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

Successfully merging this pull request may close these issues.

4 participants