Skip to content

Commit

Permalink
Merge pull request #215 from indyhackers/captcha
Browse files Browse the repository at this point in the history
add recaptcha to job post request form
  • Loading branch information
apoland authored May 13, 2024
2 parents 4025f45 + 9fc459b commit 2a03d7c
Show file tree
Hide file tree
Showing 6 changed files with 16 additions and 3 deletions.
5 changes: 4 additions & 1 deletion .rubocop.yml
Original file line number Diff line number Diff line change
Expand Up @@ -16,4 +16,7 @@ AllCops:
- 'vendor/**/*'

Style/StringLiterals:
EnforcedStyle: double_quotes
EnforcedStyle: double_quotes

Metrics/MethodLength:
Max: 100
1 change: 1 addition & 0 deletions Gemfile
Original file line number Diff line number Diff line change
Expand Up @@ -35,6 +35,7 @@ gem "test-unit"
gem "rack-cache"

gem "httparty"
gem "recaptcha"

group :development, :test do
gem "foreman"
Expand Down
2 changes: 2 additions & 0 deletions Gemfile.lock
Original file line number Diff line number Diff line change
Expand Up @@ -254,6 +254,7 @@ GEM
rb-readline (0.5.5)
rdoc (6.6.3.1)
psych (>= 4.0.0)
recaptcha (5.16.0)
redcarpet (3.6.0)
regexp_parser (2.9.0)
reline (0.4.3)
Expand Down Expand Up @@ -399,6 +400,7 @@ DEPENDENCIES
rack-cache
rails (~> 7.1)
rb-readline
recaptcha
redcarpet
rspec-rails (~> 6.0.2)
rubocop
Expand Down
6 changes: 4 additions & 2 deletions app/controllers/job_post_requests_controller.rb
Original file line number Diff line number Diff line change
Expand Up @@ -5,7 +5,7 @@ def new

def create
@job_post_request = JobPostRequest.new(job_post_request_params.merge!({ id: 13 }))
if @job_post_request.valid?
if verify_recaptcha(model: @job_post_request) && @job_post_request.valid?
@user = User.find_or_create_by!(name: @job_post_request.name, email: @job_post_request.email)
@job = Job.new(
title: @job_post_request.title,
Expand All @@ -18,7 +18,9 @@ def create
SystemMailer.job_post_request(@job_post_request, @job).deliver_now
redirect_to new_job_post_request_path, notice: "Your job post request was sent successfully!"
else
flash[:notice] = "There was a problem with sending your job post request"
flash[:notice] =
"There was a problem with sending your job post request. "\
"Verify all fields are present and the reCAPTCHA is checked."
render :new
end
end
Expand Down
1 change: 1 addition & 0 deletions app/views/job_post_requests/new.html.haml
Original file line number Diff line number Diff line change
Expand Up @@ -38,6 +38,7 @@
%a{ href: '#' } Preview
.tab-container.active
= f.input :description, as: :text
= recaptcha_tags
.input
%label  
= f.button :submit, 'Send'
Expand Down
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 = ENV['RECAPTCHA_SITE_KEY']
config.secret_key = ENV['RECAPTCHA_SECRET_KEY']
end

0 comments on commit 2a03d7c

Please sign in to comment.