Skip to content

Add hCaptcha backend as an alternative to reCAPTCHA - #2312

Open
Jazzzny wants to merge 1 commit into
DMOJ:masterfrom
Jazzzny:hcaptcha
Open

Add hCaptcha backend as an alternative to reCAPTCHA#2312
Jazzzny wants to merge 1 commit into
DMOJ:masterfrom
Jazzzny:hcaptcha

Conversation

@Jazzzny

@Jazzzny Jazzzny commented Jan 20, 2024

Copy link
Copy Markdown
Contributor
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.

@Xyene Xyene left a comment

Copy link
Copy Markdown
Member

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.

Comment thread judge/views/register.py
@codecov-commenter

codecov-commenter commented Dec 31, 2024

Copy link
Copy Markdown

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

Jazzzny commented Dec 31, 2024

Copy link
Copy Markdown
Contributor Author

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

Comment thread judge/views/register.py
captcha = ReCaptchaField(widget=ReCaptchaWidget())
if CaptchaField is not None:
if ReCaptchaWidget is not None:
captcha = CaptchaField(widget=ReCaptchaWidget())

Copy link
Copy Markdown
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...

Comment thread judge/utils/captcha.py
except ImportError:
ReCaptchaField = None
ReCaptchaWidget = None
try:

Copy link
Copy Markdown
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