Skip to content

Commit

Permalink
Add in recaptcha
Browse files Browse the repository at this point in the history
  • Loading branch information
lamtu1 committed Mar 11, 2024
1 parent 0f7198b commit e0232c9
Show file tree
Hide file tree
Showing 4 changed files with 45 additions and 1 deletion.
Original file line number Diff line number Diff line change
@@ -0,0 +1,27 @@
# frozen_string_literal: true

module ScholarsArchive
# CLASS: Torrent Form Recaptcha Controller
module TorrentFormRecaptchaBehavior
# METHOD: Check the recaptcha to see if verify or not
def check_recaptcha
if is_recaptcha?
if verify_recaptcha(model: @torrent_form)
true
else
flash[:error] = 'Captcha did not verify properly.'
false
end
else
true
end
end

# METHOD: A check method to see if recaptcha exist
# rubocop:disable Naming/PredicateName
def is_recaptcha?
Hyrax.config.recaptcha?
end
# rubocop:enable Naming/PredicateName
end
end
4 changes: 4 additions & 0 deletions app/controllers/scholars_archive/torrent_form_controller.rb
Original file line number Diff line number Diff line change
Expand Up @@ -5,6 +5,7 @@ module ScholarsArchive
class TorrentFormController < ApplicationController
# ACTION: Before page load, build the form with all the params
before_action :build_torrent_form
invisible_captcha only: [:create]
layout 'homepage'

def new; end
Expand All @@ -13,6 +14,9 @@ def create
render :new
end

# NOTE: Override if needed to perform after email delivery
def after_deliver; end

private

# METHOD: Create a new form with all the params
Expand Down
9 changes: 9 additions & 0 deletions app/models/scholars_archive/torrent_form.rb
Original file line number Diff line number Diff line change
Expand Up @@ -14,5 +14,14 @@ class TorrentForm
def spam?
torrent_method.present?
end

# HEADER: Declare the e-mail headers. It accepts anything the mail method in ActionMailer accepts
def headers
{
subject: 'Scholars Archive Torrent Form: Report of Torrent',
to: Hyrax.config.contact_email,
from: email
}
end
end
end
6 changes: 5 additions & 1 deletion app/views/scholars_archive/torrent_form/new.html.erb
Original file line number Diff line number Diff line change
Expand Up @@ -38,5 +38,9 @@
<div class="col-sm-10"><%= f.file_field :additional_item, class: 'form-control' %></div>
</div>

<%# CAPTCHA: Add in the captcha on form %>
<%= recaptcha_tags if Hyrax.config.recaptcha? %>
<%= invisible_captcha %>
<%= f.submit value: t('hyrax.contact_form.button_label'), class: "btn btn-primary" %>
<% end %>
<% end %>

0 comments on commit e0232c9

Please sign in to comment.