Skip to content

Commit

Permalink
Add spam checker and add other fields
Browse files Browse the repository at this point in the history
  • Loading branch information
lamtu1 committed Jan 25, 2024
1 parent 781e890 commit 88b8156
Show file tree
Hide file tree
Showing 4 changed files with 25 additions and 3 deletions.
3 changes: 2 additions & 1 deletion 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
layout 'homepage'

def new; end

Expand All @@ -23,7 +24,7 @@ def build_torrent_form
def torrent_form_params
return {} unless params.key?(:torrent_form)

params.require(:torrent_form).permit(:name, :description, :error_message)
params.require(:torrent_form).permit(:torrent_method, :name, :description, :error_message)
end
end
end
7 changes: 6 additions & 1 deletion app/models/scholars_archive/torrent_form.rb
Original file line number Diff line number Diff line change
Expand Up @@ -5,9 +5,14 @@ module ScholarsArchive
class TorrentForm
include ActiveModel::Model
# ADD: Add in accessor to couple field will be use in the form
attr_accessor :email, :description, :error_message
attr_accessor :torrent_method, :email, :description, :error_message

validates :email, :description, :error_message, presence: true
validates :email, format: /\A([\w\.%\+\-]+)@([\w\-]+\.)+([\w]{2,})\z/i, allow_blank: true

# SPAM: Check to make sure this section isn't fill, if so, it might be a spam
def spam?
torrent_method.present?
end
end
end
16 changes: 15 additions & 1 deletion app/views/scholars_archive/torrent_form/new.html.erb
Original file line number Diff line number Diff line change
Expand Up @@ -5,6 +5,8 @@
<%# FORM: Create the form view page to submit the torrent report %>
<%= form_for @torrent_form, url: torrent_form_index_path,
html: { class: 'form-horizontal' } do |f| %>
<%# HIDDEN FIELD: This field is hidden to check for spam %>
<%= f.text_field :torrent_method, class: 'hide' %>

<%# EMAIL: Set the email layout to enter in email, if login use their email %>
<div class="form-group">
Expand All @@ -21,7 +23,19 @@
<%# ERROR MESSAGE: Area to write the where the error message is display %>
<div class="form-group">
<%= f.label :error_message, t('hyrax.torrent_form.error_label'), class: "col-sm-2 control-label" %>
<div class="col-sm-10"><%= f.text_area :error_message, rows: 4, class: 'form-control', required: true %></div>
<div class="col-sm-10"><%= f.text_area :error_message, rows: 4, class: 'form-control' %></div>
</div>

<%# FILE UPLOAD: Area to upload file %>
<div class="form-group">
<%= f.label :file_item, t('hyrax.torrent_form.file_label'), class: "col-sm-2 control-label" %>
<div class="col-sm-10"><%= f.file_field :file_item, class: 'form-control', required: true %></div>
</div>

<%# FILE UPLOAD 2: Area to upload additional screenshot %>
<div class="form-group">
<%= f.label :additional_item, t('hyrax.torrent_form.additional_label'), class: "col-sm-2 control-label" %>
<div class="col-sm-10"><%= f.file_field :additional_item, class: 'form-control' %></div>
</div>

<%= f.submit value: t('hyrax.contact_form.button_label'), class: "btn btn-primary" %>
Expand Down
2 changes: 2 additions & 0 deletions config/locales/hyrax.en.yml
Original file line number Diff line number Diff line change
Expand Up @@ -90,6 +90,8 @@ en:
email_label: Your Email
description_label: Describe the Problem
error_label: Error Message(s)
file_label: File Upload
additional_label: Additional Item
header: Torrent Report Form
dashboard:
proxies_heading: "Manage Proxies"
Expand Down

0 comments on commit 88b8156

Please sign in to comment.