Skip to content

Commit

Permalink
Add recaptach
Browse files Browse the repository at this point in the history
  • Loading branch information
saurabhbhatia committed Sep 1, 2024
1 parent 2b3d3e9 commit 049b00e
Show file tree
Hide file tree
Showing 7 changed files with 32 additions and 7 deletions.
1 change: 1 addition & 0 deletions Gemfile
Original file line number Diff line number Diff line change
Expand Up @@ -43,6 +43,7 @@ gem "omniauth", "~> 2.1"
# Use Active Model has_secure_password [https://guides.rubyonrails.org/active_model_basics.html#securepassword]
# gem "bcrypt", "~> 3.1.7"
gem "devise"
gem "recaptcha"
gem "rolify"
gem "pundit"
gem "graphql"
Expand Down
2 changes: 2 additions & 0 deletions Gemfile.lock
Original file line number Diff line number Diff line change
Expand Up @@ -332,6 +332,7 @@ GEM
rake (13.2.1)
rdoc (6.7.0)
psych (>= 4.0.0)
recaptcha (5.17.0)
redis (5.3.0)
redis-client (>= 0.22.0)
redis-client (0.22.2)
Expand Down Expand Up @@ -497,6 +498,7 @@ DEPENDENCIES
rack-brotli
rack-cors
rails (~> 7.1.3)
recaptcha
redis (~> 5.3)
rolify
rspec-rails (~> 6.1.1)
Expand Down
23 changes: 20 additions & 3 deletions app/controllers/users/registrations_controller.rb
Original file line number Diff line number Diff line change
Expand Up @@ -2,11 +2,28 @@

class Users::RegistrationsController < Devise::RegistrationsController
before_action :configure_permitted_parameters, if: :devise_controller?
invisible_captcha only: [:create], honeypot: :sub_name

def create
super
resource.add_role(:reader)
build_resource(sign_up_params)

resource.save
yield resource if block_given?
if verify_recaptcha(model: resource) && resource.persisted?
if resource.active_for_authentication?
set_flash_message! :notice, :signed_up
sign_up(resource_name, resource)
respond_with resource, location: after_sign_up_path_for(resource)
else
set_flash_message! :notice, :"signed_up_but_#{resource.inactive_message}"
expire_data_after_sign_in!
respond_with resource, location: after_inactive_sign_up_path_for(resource)
end
resource.add_role(:reader)
else
clean_up_passwords resource
set_minimum_password_length
respond_with resource
end
end

protected
Expand Down
5 changes: 3 additions & 2 deletions app/views/devise/registrations/new.html.erb
Original file line number Diff line number Diff line change
Expand Up @@ -33,7 +33,6 @@
placeholder: "Email",
class: "appearance-none relative block w-full px-3 py-2 border border-gray-300 placeholder-gray-500 text-gray-900 focus:outline-none focus:ring-purple-800 focus:border-purple-800 focus:z-10 sm:text-sm" %>
</div>
<%= f.invisible_captcha :sub_name %>
<div class="pt-2 pb-4">
<label for="password" class="sr-only">Password</label>
<% if @minimum_password_length %>
Expand All @@ -53,7 +52,9 @@
class: "appearance-none relative block w-full px-3 py-2 border border-gray-300 placeholder-gray-500 text-gray-900 focus:outline-none focus:ring-purple-800 focus:border-purple-800 focus:z-10 sm:text-sm" %>
</div>
</div>

<div>
<%= recaptcha_tags %>
</div>
<div>
<p>By signing up you are agreeing to our <a href="https://winter-professor-81d.notion.site/Terms-of-Service-7a40080fe1684689890e287566f0c732" target="_blank">Terms of Service</a></p>
</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 @@
+6cNgnaX4hliBpeWRnhPnzyLPVZfSrEn/SrjztDSHKjywuAgikAJTRLN2WpwbScElj5Sp/mFj4AWjZCSngWcQElEUzfOL6rjB8HiH3uVCy0GkbsKov8LQDGBglE4ZRjeOTV9ssG7udj50Z1BElomdpLoFpWgjbuTmhhufUDBgynSlso6xl59OhwWNoI93keRIMZ/UAZKZa0Hx0PfzLKhWWvbL11SJUFJNf0TMJoZBHscL16vJh+uPD0JaqmY+5egvmTY6WMNwKiw5DqqJDta+gDN40r7AQo79CmqSVE2BR10JXhC4xjD1Oh7e9/amdvvbGdusFlPqSNHgV5fYot/WrgfvzYN7oRHelIHD90V12OydyHxlQ/iujHyskr1x+UHENHlazMyPEfqLu/rX1pTrtoHbS4EeepDL6VCVKzdtWAbd3jTS/WKHmU80IRP/HpSGAhGCxE1YaHE8jdwrYNBEe2GgchDIfo59aZM2J0DVE4FzQuceKN1lbn0MT06cK8jlbMFcb18rqHFJBguptxgJ+4sLZtxTtr6nCRVM/E97o8OpSk6Q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Ad36Ppq28mC77redP+9tTBO6rUVVoLAw9Auqm7XU3Ex+BPsHUwjDzVtcs947x8P6MVeIHF6R7r/7BOI1EGVwbPTy15sgDuiL2lAO4hSpOOjQXfWfk6lV4WK3NA7W93sT/INOOsrQBxWSUvZLEpSCrxr6yjI+1yOC1dytVmwvJRdjHuUMSnjLO1pLM6asmKMhxMcw8fHbXnttmW8xbZqdgZOEVI/JtlW/d2P1KtSqbP6w2dB219GE8I1+xZ64vC13VSEIHPqCWR2EXUzK5sWhVIZ6XFBP07EEemuyxZ1lp53brbvw/r+SMrx6VnNazvZ5BDfP6JbQbNp1Febr/94I5pfTxT0JVTZCMkf64jwETj6FjjPpNDqHRmWgWwkM0hNKecBzM84Y8W8IsqmcOGS1OtWWc2t6Pfh3o+WCmVCfQLkJR0nJ7L9I1DyvMMYIUhGa0z1jANt9tqX3GNrJ7gff4JLY56ysGABSzI+FFRQIk0/KPu3uR9hpirxlXYVOkob0AOfm5zJf/nyrSWIYw8QRdkNpRzkrlFlzqhvZNLwwRzF/D3u+KnaAKzcn8M1CdToJcu+R1KB0rA9yJ0As1MetLAnUIDa+AScVSduPWSYaDY=--amcMeQKa2feZ8G64--4VNA8bgluTtG26KvCITWPQ==
2 changes: 1 addition & 1 deletion config/credentials/production.yml.enc
Original file line number Diff line number Diff line change
@@ -1 +1 @@
oF3EBAp0y8t02VsCugyWCGqfDwyhQsu8+tmu4LPtAHPvEt/mPPU6wTBrdcnWNqMS/Xz+y1NGK8w/WSEZp4XlgDOx8XYfT4nskSLKAQuMri0GGiK+sVaJQ+FyPDcpOzDUjxuqt+F+MD+FIfZKnNYnUi93moKZ3dGfW/4VocV1unCLKmZtkFSlG8kgp56JlIF//oR2CJv+iUWzE0MbczS/Xq11AzJnhubJGGLdI3iI5/ALJ4GKXpV2/LPbFGua2CAnBkrMJ/GLYeXXVqL4MogVTW1z+SIr01EF3nwIjWs8dLVqYn9twm87KRMcJf4IEHxbdrrKN6lAaXeaWQ5vPqFDzuIMiov2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V6u2S6RB3nfmwgH7CKeOg==
4 changes: 4 additions & 0 deletions config/initializers/recaptcha.rb
Original file line number Diff line number Diff line change
@@ -0,0 +1,4 @@
Recaptcha.configure do |config|
config.site_key = Rails.application.credentials.dig(:site_key)
config.secret_key = Rails.application.credentials.dig(:secret_key)
end

0 comments on commit 049b00e

Please sign in to comment.