Skip to content

Commit

Permalink
Move to hcaptcha
Browse files Browse the repository at this point in the history
  • Loading branch information
chvp committed Aug 13, 2021
1 parent 4e247c7 commit 820e59b
Show file tree
Hide file tree
Showing 10 changed files with 19 additions and 19 deletions.
2 changes: 1 addition & 1 deletion Gemfile
Original file line number Diff line number Diff line change
Expand Up @@ -72,8 +72,8 @@ gem 'omniauth_openid_connect', '~> 0.3.5'
gem 'jwt', '~> 2.2.3'

# contact mail form
gem 'hcaptcha', '~> 7.1.0'
gem 'mail_form', '~> 1.9.0'
gem 'recaptcha', '~> 5.8.1', require: 'recaptcha/rails'

# authorization
gem 'pundit', '~> 2.1.0'
Expand Down
6 changes: 3 additions & 3 deletions Gemfile.lock
Original file line number Diff line number Diff line change
Expand Up @@ -170,6 +170,8 @@ GEM
actionpack (>= 5.2)
activesupport (>= 5.2)
hashie (4.1.0)
hcaptcha (7.1.0)
json
htmlentities (4.3.4)
httparty (0.18.1)
mime-types (~> 3.0)
Expand Down Expand Up @@ -346,8 +348,6 @@ GEM
rb-inotify (0.10.1)
ffi (~> 1.0)
rb-readline (0.5.5)
recaptcha (5.8.1)
json
regexp_parser (2.1.1)
responders (3.0.1)
actionpack (>= 5.0)
Expand Down Expand Up @@ -488,6 +488,7 @@ DEPENDENCIES
faker (~> 2.18.0)
flamegraph (~> 0.9.5)
has_scope (~> 0.8.0)
hcaptcha (~> 7.1.0)
httparty (~> 0.18.1)
i18n-js (~> 3.9.0)
image_processing (~> 1.12.1)
Expand Down Expand Up @@ -518,7 +519,6 @@ DEPENDENCIES
rails-i18n (~> 6.0.0)
rails_server_timings (~> 1.0.8)
rb-readline (~> 0.5.5)
recaptcha (~> 5.8.1)
rouge (= 3.26.0)
rubocop-rails (~> 2.11.3)
ruby-saml (~> 1.12.2)
Expand Down
11 changes: 6 additions & 5 deletions app/controllers/pages_controller.rb
Original file line number Diff line number Diff line change
@@ -1,8 +1,9 @@
class PagesController < ApplicationController
content_security_policy only: %i[contact] do |policy|
policy.script_src(*(%w[https://www.recaptcha.net https://www.gstatic.com
https://www.google.com] + policy.script_src))
policy.frame_src('https://www.google.com', 'https://www.recaptcha.net')
content_security_policy only: %i[contact create_contact] do |policy|
policy.script_src(*(%w[https://hcaptcha.com https://*.hcaptcha.com] + policy.script_src))
policy.style_src(*(%w[https://hcaptcha.com https://*.hcaptcha.com] + policy.style_src))
policy.connect_src(*(%w[https://hcaptcha.com https://*.hcaptcha.com] + policy.connect_src))
policy.frame_src('https://hcaptcha.com', 'https://*.hcaptcha.com')
end

def home
Expand Down Expand Up @@ -59,7 +60,7 @@ def create_contact
@contact_form = ContactForm.new(contact_params)
@contact_form.request = request # Allows us to also send ip
@contact_form.validate
if verify_recaptcha(model: @contact_form, message: t('.captcha_failed')) && @contact_form.deliver
if verify_hcaptcha(model: @contact_form, message: t('.captcha_failed')) && @contact_form.deliver
redirect_to root_path, notice: t('.mail_sent')
else
flash[:error] = @contact_form.errors.full_messages.to_sentence
Expand Down
2 changes: 1 addition & 1 deletion app/views/pages/contact.html.erb
Original file line number Diff line number Diff line change
Expand Up @@ -41,7 +41,7 @@
<% if Rails.env.production? || Rails.env.staging? %>
<div class="form-group row">
<div class="offset-sm-2 col-sm-8">
<%= recaptcha_tags %>
<%= hcaptcha_tags %>
</div>
</div>
<% end %>
Expand Down
2 changes: 1 addition & 1 deletion config/credentials.yml.enc
Original file line number Diff line number Diff line change
@@ -1 +1 @@
jIu06O5mifMmzqlESzyG48oWNB6+OILy2OgI2RMmS5lB0JcXgRbDUwIMe20R7Zu2656JBublUnrlgELw/m8sBUulkXR6IXQcg3puiWv90EWlmsyZCc0X3l7nTLMvPdmZW9MjqRd9/ksa9itkJswz6mJMsJK1Rl1E5DhxOyaAXdd6GwOX/d8XcB7ciUQvtIJjP/6rgmCBiT0NPtTi9MwxnzepsR0Y5jLDj4SieK3pMfEwKOAoKo881OoVDNyY3AN/nppm03CIiCK+Y4Uswa890QFA4O645Vx2ybns8V4qiSYEfF0RtLPZrBKK5bBE/7Lz6SK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line number Diff line number Diff line change
@@ -1 +1 @@
FbXR8Pry96aLKOyp/YYyKEnWjZf32bJUbVqqOw1bcqCCREA7AGmUVUUsJaylI28SHwbDO5qYw/N/GusC8Zh6WdHgyFv8ARalvgIWE4QMCo/xmq00WdyxJUTxMwtFPvb+hMqxKVyTZ8AiIeS1+cySebShJCU5+in4RticztxaiceCjfFgGkzJeA3ph7a2u+Y8zBR+AuJM1Q==--CjVchd12b8cbF22G--UtTqVaNRbp5q+Ql0jLbngA==
h6YQ/xM7z8+UJ3TFNWJuprkec8Orlkc/R/LfO9nz9ANXdXGtLpu7GcsJgdPEZb0aPxX6T2Z21ssuna6Dsh9bPjLLbkoW4Db4p5YS70D9hlqxeXHt5uYdZPZl/SZZvjE3dZzPizYCZ3LGQz/3LWLQjsiJHIk/ow/0tVjZ4XUvWiwtqESTF67cZrZneVc2m6w3KG6cG2AMNE3GI5phhVeQAeVQVYMbu/FjoVnb6fQF3gtQDvzzZFxNFfYZTXZF2U1PlAXSKNQtktjaMiRTv4AW1ZRG2Ncsb1r3fYEHTd5qx5+LP3low8LdYreCvS1z6xYLkS/b1znMQhxyVtgXWH8ZGeKkHkhD9sW1ZLw+TXTTX84G908=--AR0wlVEWLuoZz3AW--3VBD7e4+dzXec1ojsgZxrQ==
4 changes: 4 additions & 0 deletions config/initializers/hcaptcha.rb
Original file line number Diff line number Diff line change
@@ -0,0 +1,4 @@
Hcaptcha.configure do |config|
config.site_key = Rails.application.credentials.hcaptcha_site_key
config.secret_key = Rails.application.credentials.hcaptcha_secret_key
end
4 changes: 0 additions & 4 deletions config/initializers/recaptcha.rb

This file was deleted.

2 changes: 1 addition & 1 deletion config/locales/views/pages/en.yml
Original file line number Diff line number Diff line change
Expand Up @@ -62,7 +62,7 @@ en:
send: Send message
create_contact:
mail_sent: "Your message has been sent. Thanks for getting in touch."
captcha_failed: reCAPTCHA could not be verified; please try again.
captcha_failed: HCaptcha could not be verified; please try again.
privacy_disclaimer:
text_html: "Your privacy is important to us. On the <a href=\"%{your_data}\">your data</a> page we explain in clear and understandable language what data we collect and how we use it. Our <a href=\"%{privacy_statement}\">privacy statement</a> contains the legally binding version."
support:
Expand Down
3 changes: 1 addition & 2 deletions config/locales/views/pages/nl.yml
Original file line number Diff line number Diff line change
Expand Up @@ -61,7 +61,7 @@ nl:
rights_request_redirect_html: Wil je lesgeversrechten aanvragen voor je account? Gebruik dan <strong><a href="%{url}">dit formulier</a></strong>.
send: Bericht verzenden
create_contact:
captcha_failed: reCAPTCHA kon niet geverifieerd worden, probeer opnieuw.
captcha_failed: HCaptcha kon niet geverifieerd worden, probeer opnieuw.
mail_sent: "Je bericht werd verstuurd. Bedankt om contact op te nemen."
privacy_disclaimer:
text_html: "Jouw privacy is belangrijk voor ons. Op de <a href=\"%{your_data}\">jouw data</a> pagina leggen we in mensentaal uit welke data we verzamelen en hoe we die gebruiken. De juridisch bindende versie kan je in onze <a href=\"%{privacy_statement}\">privacyverklaring</a> vinden."
Expand All @@ -82,4 +82,3 @@ nl:
support_p3_html: "Wenst u een groter bedrag te schenken of kiest u liever voor sponsoring op factuur? Contacteer ons op <a href='mailto:[email protected]'>[email protected]</a> en we bekijken samen graag de mogelijkheden."
supported_by: Met de steun van
supported_p1_html: "Dodona wordt ontwikkeld door een klein team onderzoekers aan de <a href='https://www.ugent.be' target='_blank'>Universiteit Gent</a>. Het platform is volledig open source en alle code is beschikbaar op <a href='https://github.com/dodona-edu/dodona' target='_blank'>GitHub</a>. De hosting wordt aangeboden door de Universiteit Gent. Daarnaast ontving Dodona al steun in de vorm van onderwijsinnovatieprojecten van de Universiteit Gent en de Faculteit Wetenschappen. Ook <a href='https://www.elixir-belgium.org/' target='_blank'>ELIXIR Belgium</a> ondersteunde dit project."

0 comments on commit 820e59b

Please sign in to comment.