first commit
This commit is contained in:
commit
82f8b28353
28 files changed
+1210
No files matched your search
@@ -0,0 +1,36 @@
|
||||
class ContactForm
|
||||
LIMITS = {
|
||||
"email" => 254,
|
||||
"name" => 128,
|
||||
"subject" => 200,
|
||||
"message" => 5000
|
||||
}.freeze
|
||||
|
||||
def initialize(params)
|
||||
@params = params
|
||||
end
|
||||
|
||||
def spam?
|
||||
!@params["website"].to_s.empty?
|
||||
end
|
||||
|
||||
def valid?
|
||||
fields_valid = LIMITS.all? do |key, max|
|
||||
value = @params[key]
|
||||
|
||||
value.is_a?(String) &&
|
||||
value.valid_encoding? &&
|
||||
!value.strip.empty? &&
|
||||
value.strip.length <= max
|
||||
end
|
||||
|
||||
return false unless fields_valid
|
||||
|
||||
email_valid = @params["email"].strip.match?(/\A[^\s@]+@[^\s@]+\.[^\s@]+\z/)
|
||||
headers_valid = %w[name subject].none? do |key|
|
||||
@params[key].match?(/[\r\n]/)
|
||||
end
|
||||
|
||||
email_valid && headers_valid
|
||||
end
|
||||
end
|
||||
@@ -0,0 +1,27 @@
|
||||
require "mail"
|
||||
|
||||
class ContactMailer
|
||||
def initialize(params)
|
||||
@params = params
|
||||
end
|
||||
|
||||
def build
|
||||
email = @params["email"]
|
||||
name = @params["name"]
|
||||
subject = @params["subject"]
|
||||
message = @params["message"]
|
||||
|
||||
Mail.new do
|
||||
from "noreply@netig.net"
|
||||
to "contact@netig.net"
|
||||
reply_to email
|
||||
content_type "text/plain; charset=UTF-8"
|
||||
subject subject
|
||||
body "Nom : #{name}\n\n#{message}"
|
||||
end
|
||||
end
|
||||
|
||||
def deliver
|
||||
build.deliver
|
||||
end
|
||||
end
|
||||
Reference in new issue
Block a user