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 optional reCAPTCHA for registration #335

Open
wants to merge 10 commits into
base: master
Choose a base branch
from
Open

Add optional reCAPTCHA for registration #335

wants to merge 10 commits into from

Conversation

Kangaroux
Copy link

This added a recaptcha button to the registration page. The button only appears if recaptcha is enabled in the config and the user is not logged in.

I included a couple links in the config to the recaptcha docs. All that's needed to use it is to enable it in the config and provide the two tokens. By default the recaptcha is disabled.

enable_recaptcha: yes
recaptcha_site_key: change-me
recaptcha_secret: change-me

Captcha

image

Captcha error message

image

@@ -24,7 +24,7 @@ RUN \
alembic \
"coloredlogs==5.0" \
youtube-dl \
&& apk --no-cache del py3-pip
requests
Copy link
Author

Choose a reason for hiding this comment

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

Deleting pip caused the requests library to not be importable.

Copy link
Collaborator

Choose a reason for hiding this comment

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

You should install py3-requests from the alpine package manager instead of using pip.

Leave the call to uninstall pip, it slims down the final build image.

@@ -22,6 +22,7 @@
<link rel='apple-touch-startup-image' href='img/apple-touch-startup-image-1668x2224.png' media='(min-device-width: 834px) and (max-device-width: 834px) and (-webkit-min-device-pixel-ratio: 2) and (orientation: portrait)'/>
<link rel='apple-touch-startup-image' href='img/apple-touch-startup-image-2048x2732.png' media='(min-device-width: 1024px) and (max-device-width: 1024px) and (-webkit-min-device-pixel-ratio: 2) and (orientation: portrait)'/>
<link rel='manifest' href='manifest.json'/>
<script src="https://www.google.com/recaptcha/api.js"></script>
Copy link
Contributor

Choose a reason for hiding this comment

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

I would prefer that we don't load the reCAPTCHA js library if the feature is disabled.

Copy link
Author

Choose a reason for hiding this comment

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

Not entirely sure how to do that on the base template to be honest.

@sgsunder
Copy link
Collaborator

sgsunder commented Jul 8, 2020

Please address my review comments

@Kangaroux
Copy link
Author

@sgsunder Check that you submitted the review, I don't see anything

@@ -22,6 +22,7 @@
<link rel='apple-touch-startup-image' href='img/apple-touch-startup-image-1668x2224.png' media='(min-device-width: 834px) and (max-device-width: 834px) and (-webkit-min-device-pixel-ratio: 2) and (orientation: portrait)'/>
<link rel='apple-touch-startup-image' href='img/apple-touch-startup-image-2048x2732.png' media='(min-device-width: 1024px) and (max-device-width: 1024px) and (-webkit-min-device-pixel-ratio: 2) and (orientation: portrait)'/>
<link rel='manifest' href='manifest.json'/>
<script src="https://www.google.com/recaptcha/api.js"></script>
Copy link
Collaborator

Choose a reason for hiding this comment

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

I don't think this is a good way to import this library, we should instead be adding it to vendor.min.js

  1. Find the recaptcha library on npm: https://www.npmjs.com/search?q=recaptcha
  2. Add library to package.json and package-lock.json
  3. Add library to the external_js array in build.js

Copy link
Collaborator

Choose a reason for hiding this comment

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

Also, please make sure that whatever recaptcha library you use is GPLv3 compatible

@@ -38,6 +38,7 @@

<div class='messages'></div>
<div class='buttons'>
<% if(ctx.enableRecaptcha) print(`<div id="recaptcha"></div><br>`); %>
Copy link
Collaborator

Choose a reason for hiding this comment

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

Better way:

<% if(ctx.enableRecaptcha) { %> 
<div id="recaptcha"></div><br>
<% } %>

uri.formatApiLink("user", this._orig._name),
detail,
files
)
: api.post(uri.formatApiLink("users"), detail, files);
Copy link
Collaborator

Choose a reason for hiding this comment

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

Please install and enable pre-commit so that the autoformatting tools will maintain consistent formatting

@@ -24,7 +24,7 @@ RUN \
alembic \
"coloredlogs==5.0" \
youtube-dl \
&& apk --no-cache del py3-pip
requests
Copy link
Collaborator

Choose a reason for hiding this comment

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

You should install py3-requests from the alpine package manager instead of using pip.

Leave the call to uninstall pip, it slims down the final build image.

"secret": config.config["recaptcha_secret"],
"response": ctx.get_param_as_string("recaptchaToken", default=""),
})

Copy link
Collaborator

Choose a reason for hiding this comment

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

Can we add error handling if the call to the Google API fails (like if their site is down and throws a HTTP 504)?

@sgsunder
Copy link
Collaborator

sgsunder commented Jul 8, 2020

Regarding the Docker Cloud CI failure: Make sure that any changes you make to server/Dockerfile is mirrored in server/Dockerfile.test

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

Successfully merging this pull request may close these issues.

3 participants