Skip to content

Commit

Permalink
Merge pull request #2881 from SEED-platform/bug/recaptcha-key-in-docker
Browse files Browse the repository at this point in the history
add recaptcha to docker files
  • Loading branch information
nllong authored Sep 22, 2021
2 parents 5546432 + d408986 commit d12953d
Show file tree
Hide file tree
Showing 7 changed files with 42 additions and 5 deletions.
5 changes: 4 additions & 1 deletion config/settings/common.py
Original file line number Diff line number Diff line change
Expand Up @@ -323,7 +323,10 @@
BSYNCR_SERVER_HOST = os.environ.get('BSYNCR_SERVER_HOST')
BSYNCR_SERVER_PORT = os.environ.get('BSYNCR_SERVER_PORT', '80')

# Google reCAPTCHA env variable for self-registration
# Google reCAPTCHA env variable for self-registration. SITE_KEY defaults
# to the key registered for SEED. Override it needing to test.
# https://developers.google.com/recaptcha/docs/faq#id-like-to-run-automated-tests-with-recaptcha.-what-should-i-do
GOOGLE_RECAPTCHA_SITE_KEY = os.environ.get('GOOGLE_RECAPTCHA_SITE_KEY', '6LexR2MaAAAAAMkCFmLaucT0KwSfx0PjiX-cf6rV')
GOOGLE_RECAPTCHA_SECRET_KEY = os.environ.get('GOOGLE_RECAPTCHA_SECRET_KEY')

# Certification
Expand Down
4 changes: 4 additions & 0 deletions config/settings/local_untracked.py.dist
Original file line number Diff line number Diff line change
Expand Up @@ -39,6 +39,10 @@ MAPQUEST_API_KEY = os.environ.get('MAPQUEST_API_KEY', 'a-mapquest-api-key')
# Keys for app users are attached to each organization.
TESTING_MAPQUEST_API_KEY = os.environ.get('TESTING_MAPQUEST_API_KEY', '<your_key_here>')

# These are the test keys
GOOGLE_RECAPTCHA_SITE_KEY = os.environ.get('GOOGLE_RECAPTCHA_SITE_KEY', '6LeIxAcTAAAAAJcZVRqyHh71UMIEGNQ_MXjiZKhI')
GOOGLE_RECAPTCHA_SECRET_KEY = os.environ.get('GOOGLE_RECAPTCHA_SECRET_KEY', '6LeIxAcTAAAAAGG-vFI1TnRWxMZNFuojJ4WifJWe')

# email through SES (django-ses)
#EMAIL_BACKEND = 'django_ses.SESBackend'
#AWS_ACCESS_KEY_ID = os.environ.get('AWS_ACCESS_KEY_ID', '')
Expand Down
4 changes: 4 additions & 0 deletions docker-compose.local.yml
Original file line number Diff line number Diff line change
Expand Up @@ -69,6 +69,10 @@ services:
- SENTRY_JS_DSN
- SENTRY_RAVEN_DSN
- DJANGO_SETTINGS_MODULE=config.settings.docker
# Recaptcha for testing:
# https://developers.google.com/recaptcha/docs/faq#id-like-to-run-automated-tests-with-recaptcha.-what-should-i-do
- GOOGLE_RECAPTCHA_SITE_KEY=6LeIxAcTAAAAAJcZVRqyHh71UMIEGNQ_MXjiZKhI
- GOOGLE_RECAPTCHA_SECRET_KEY=6LeIxAcTAAAAAGG-vFI1TnRWxMZNFuojJ4WifJWe
depends_on:
- db-redis
- db-postgres
Expand Down
4 changes: 4 additions & 0 deletions docker-compose.yml
Original file line number Diff line number Diff line change
Expand Up @@ -42,6 +42,10 @@ services:
- SEED_ADMIN_ORG=default
- SECRET_KEY=ARQV8qGuJKH8sGnBf6ZeEdJQRKLTUhsvEcp8qG9X9sCPXvGLhdxqnNXpZcy6HEyf
- DJANGO_SETTINGS_MODULE=config.settings.docker
# Recaptcha for testing:
# https://developers.google.com/recaptcha/docs/faq#id-like-to-run-automated-tests-with-recaptcha.-what-should-i-do
- GOOGLE_RECAPTCHA_SITE_KEY=6LeIxAcTAAAAAJcZVRqyHh71UMIEGNQ_MXjiZKhI
- GOOGLE_RECAPTCHA_SECRET_KEY=6LeIxAcTAAAAAGG-vFI1TnRWxMZNFuojJ4WifJWe
depends_on:
- db-redis
- db-postgres
Expand Down
4 changes: 2 additions & 2 deletions seed/landing/templates/landing/create_account.html
Original file line number Diff line number Diff line change
@@ -1,4 +1,4 @@
{% extends "landing/base.html" %}{% load compress %}{% load i18n %}
{% extends "landing/base.html" %}{% load compress %}{% load i18n %}{% load settings_value %}
{% block js %}{{ block.super }}
<script src='https://www.google.com/recaptcha/api.js'></script>
<script type="text/javascript">
Expand Down Expand Up @@ -26,7 +26,7 @@ <h2>{% trans "Create Your Account" %}</h2>
{{ form.as_table }}
</table>
{% include "landing/_password_note.html" %}
<div style="padding-left: 4.5em" class="g-recaptcha" data-sitekey="6LexR2MaAAAAAMkCFmLaucT0KwSfx0PjiX-cf6rV"></div>
<div style="padding-left: 4.5em" class="g-recaptcha" data-sitekey="{% settings_value "GOOGLE_RECAPTCHA_SITE_KEY" %}"></div>
<div style="padding-bottom: 2em">
<input class="btn btn-primary" type="submit"
value="{% block password_submit %}{% trans "Create my account" %}{% endblock %}">
Expand Down
5 changes: 3 additions & 2 deletions seed/landing/views.py
Original file line number Diff line number Diff line change
Expand Up @@ -171,9 +171,10 @@ def create_account(request):
user.pk, user.email
)
return redirect('landing:account_activation_sent')
except Exception:
except Exception as e:
logger.error(f'Unexpected error creating new account: {str(e)}')
errors = form._errors.setdefault(NON_FIELD_ERRORS, errors)
errors.append('Username and/or password already exist.')
errors.append('An unexpected error occurred. Please contact the site administrator.')
else:
errors = form._errors.setdefault(NON_FIELD_ERRORS, errors)
errors.append('Invalid reCAPTCHA, please try again')
Expand Down
21 changes: 21 additions & 0 deletions seed/templatetags/settings_value.py
Original file line number Diff line number Diff line change
@@ -0,0 +1,21 @@
# encoding: utf-8
"""
:copyright (c) 2014 - 2021, The Regents of the University of California, through Lawrence Berkeley National Laboratory (subject to receipt of any required approvals from the U.S. Department of Energy) and contributors. All rights reserved. # NOQA
:author
"""

# Simple templatetag to return a value from the settings file. e.g., {% settings_value "LOGIN_REDIRECT_URL" %}

import logging

from django import template
from django.conf import settings

_log = logging.getLogger(__name__)

register = template.Library()


@register.simple_tag
def settings_value(name):
return getattr(settings, name, "")

0 comments on commit d12953d

Please sign in to comment.