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
|
||||
Reference in new issue
Block a user