Skip to content

Commit

Permalink
added recaptcha for users registration
Browse files Browse the repository at this point in the history
  • Loading branch information
kortirso committed Feb 15, 2024
1 parent 35413b7 commit fad4019
Show file tree
Hide file tree
Showing 9 changed files with 25 additions and 1 deletion.
3 changes: 3 additions & 0 deletions CHANGELOG.md
Original file line number Diff line number Diff line change
Expand Up @@ -5,6 +5,9 @@ The format is based on [Keep a Changelog](http://keepachangelog.com/en/1.0.0/)
and this project adheres to [Semantic Versioning](http://semver.org/spec/v2.0.0.html).

## Unreleased
### Added
- recaptcha for users registration

### Modified
- navigation styles for better mobile
- closing dropdowns after outside click
Expand Down
3 changes: 3 additions & 0 deletions Gemfile
Original file line number Diff line number Diff line change
Expand Up @@ -94,6 +94,9 @@ gem 'pagy', '~> 6.0'
# notification layer
gem 'active_delivery'

# antibot captcha
gem 'recaptcha', require: 'recaptcha/rails'

group :development, :test do
gem 'bullet', git: 'https://github.com/flyerhzm/bullet', branch: 'main'
gem 'cypress-on-rails', '~> 1.0'
Expand Down
2 changes: 2 additions & 0 deletions Gemfile.lock
Original file line number Diff line number Diff line change
Expand Up @@ -355,6 +355,7 @@ GEM
rake (13.1.0)
rdoc (6.6.2)
psych (>= 4.0.0)
recaptcha (5.16.0)
redis (5.1.0)
redis-client (>= 0.17.0)
redis-actionpack (5.4.0)
Expand Down Expand Up @@ -534,6 +535,7 @@ DEPENDENCIES
rackup (~> 2.1)
rails (~> 7.1)
rails-controller-testing (= 1.0.5)
recaptcha
redis (~> 5.0)
redis-rack!
redis-rails!
Expand Down
5 changes: 5 additions & 0 deletions app/controllers/users/registrations_controller.rb
Original file line number Diff line number Diff line change
Expand Up @@ -9,6 +9,7 @@ class RegistrationsController < ApplicationController

skip_before_action :authenticate
skip_before_action :check_email_confirmation
before_action :check_recaptcha, only: %i[create]

def new
@user = User.new
Expand All @@ -25,6 +26,10 @@ def confirm; end

private

def check_recaptcha
failed_create_response([t('controllers.users.registrations.failed_recaptcha')]) unless verify_recaptcha
end

def success_create_response(user)
cookies[:fantasy_sports_token] = {
value: generate_token.call(user: user)[:result],
Expand Down
3 changes: 3 additions & 0 deletions app/views/controllers/users/registrations/new.html.erb
Original file line number Diff line number Diff line change
Expand Up @@ -21,6 +21,9 @@
<%= t('views.users.registrations.new.have_account') %>
<%= link_to t('components.page_wrappers.users_component.login'), users_login_path, class: 'underline text-blue-600' %>
</div>
<div class="form-field">
<%= recaptcha_tags %>
</div>
<%= form.submit t('views.users.registrations.new.create'), class: 'btn-primary' %>
<% end %>
</div>
Expand Down
2 changes: 1 addition & 1 deletion config/credentials.yml.enc
Original file line number Diff line number Diff line change
@@ -1 +1 @@
f0zWXxgXhzXZRzu9f1XmacrOmRd5HlDSoPoqcYeAiZmc2bXhNsIBXPPuYTJJtUclwjd8Rd0FSc8WihK1hy7ljMYqjoZOB8Dnj1FvA1ce/UeMruo6yC0am9mjlOmCdop1mQBltJE5nL8O1QFhTaBdTTeHDplQdTdz75673Hfi3mu3cXUADBYdpk8FDRc1Q3+fwEYqAdJt0bZ0Nk0AiJy1+fsp2opNXWqFMkpHD+QLG3ta1/JnW6RkeEicLMzt74Ldop8pYPZkeV4Ew4AZIvbAML4MOe8QP38RNLhbIboHjaKmw7vWcT7QF8oM+hcowm77162yh5Khe9GLOy8TmoAaRNMxxkSeWx9RkUlWxg89otwno/h0AzV2bLd1ddbmOp43/6tx6YvBHc49RZgNVJUTB60igZN4Tby/igUu6PW5JvkiKukyTRUx7598bZLZMLyv+5nLQoSGkinwkWT4gsRR9imOgQST5eW7xQwUOGF03jn4CtlBztYucbsElEox3VNm2Jctxzd0eeadP9uWE4pBPFzYyTdX/GBrD8f2dyREyzYMjqKwC+naWEdyRa/FRI85sHfDey2MmmTIjWjBIh3bL74Z924jck9sGdq7oN5ftBwM5dM7U1SJBzLzjYczmv+qrR4HjsEPhUsDCW8k1u0XL00lwQugw9g6vtTGAB+3LLSsNKuDQq4SF2MGrv0YCTXQYBR0nKTGkhlPtSdmofzu+2RqVy+EAEEIOvOc9rZjTrfica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f5jrP67IigqUKN+rjWRUtpsF4mSXVnyOzYZtAPLrSUSgs/c6JYU6fIsWDXfMtupmg6wV/mfvZ+nNaxr/WC8qeiqs2ypCVM/NWpzKXM2Pkm1XtaWRo/q0NFhkbSwsUD6grIVNWmhaXQx5at82NGjXWE1IOecL+O6BrzzGgdggt9zkG+HF/lxkVDnt97lSJPhaa1ZvnWJteWImge1fRwOLBbetdiguTA2nxsfZSZjFMlZB0CkUd2qSbJgp5IcP2+R9S13G4sTijrb4JnvFSvK/C3p2oIDbZRBCkKO134WbGn7ZmfzEaAGvfYlo0q70/9vFVQQNHnTVK8YUHZhtHZJV4Y0anfVGdxorA2sK3MgU/Rs7FB1dvX6JaIBUD/968nIh3005uPAAyE8cAh/PnScyC8pM3JFVYJqkYOwANDE8rk1IAn9uOtO8RlRom1mn2jUJ90K6IZBXXWC9TeEGpBLP0w4KecUQXtVQsBUToS3HOfi8JFh+4uxf1gjAqJ74OJxLWtM5ZOCyui7OFK8JwgGgs7GbtCdpEQbMEpoZUNpkylHXlKUkpX/Yb2q2xAl19k7mVqBVQTHI2r+6U80PxfUHAn1oJKi7PUqrKsY5aZ5cw==--KJAL+Inihta1Z5yC--4zMeBuyffQpWpDvEZ4Gmxg==
6 changes: 6 additions & 0 deletions config/initializers/recaptcha.rb
Original file line number Diff line number Diff line change
@@ -0,0 +1,6 @@
# frozen_string_literal: true

Recaptcha.configure do |config|
config.site_key = Rails.application.credentials.dig(:recaptcha, :public)
config.secret_key = Rails.application.credentials.dig(:recaptcha, :private)
end
1 change: 1 addition & 0 deletions config/locales/en.yml
Original file line number Diff line number Diff line change
Expand Up @@ -81,6 +81,7 @@ en:
users:
registrations:
success_create: You are signed up
failed_recaptcha: Failed reCaptcha validation
sessions:
success_create: You are logged in
success_destroy: You are logged out
Expand Down
1 change: 1 addition & 0 deletions config/locales/ru.yml
Original file line number Diff line number Diff line change
Expand Up @@ -81,6 +81,7 @@ ru:
users:
registrations:
success_create: Вы зарегистрированы
failed_recaptcha: Провалена проверка reCaptcha
sessions:
success_create: Вы вошли
success_destroy: Вы вышли
Expand Down

0 comments on commit fad4019

Please sign in to comment.