Skip to content

Instantly share code, notes, and snippets.

@jordanbrock
Forked from madpilot/span_delay.rb
Created August 4, 2012 04:13
Show Gist options
  • Save jordanbrock/3254377 to your computer and use it in GitHub Desktop.
Save jordanbrock/3254377 to your computer and use it in GitHub Desktop.
A Metal app that looks for a timestamp on a form field, and makes sure it happened at least two seconds ago...
# Allow the metal piece to run in isolation
require(File.dirname(__FILE__) + "/../../config/environment") unless defined?(Rails)
class SpamDelay
def self.call(env)
@request = Rack::Request.new(env)
if env["PATH_INFO"] =~ /^\/contact/
if env['REQUEST_METHOD'] == 'POST'
if @request.params['t'] && @request.params['t'].to_i < Time.now.gmtime.to_i - 2
[404, {"Content-Type" => "text/html"}, ["Not Found"]]
else
[400, {"Content-Type" => "text/html"}, ["Bad Request"]]
end
else
[404, {"Content-Type" => "text/html"}, ["Not Found"]]
end
else
[404, {"Content-Type" => "text/html"}, ["Not Found"]]
end
end
end
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment