Skip to content

Instantly share code, notes, and snippets.

@madpilot
Created August 4, 2012 04:12
Show Gist options
  • Star 0 You must be signed in to star a gist
  • Fork 1 You must be signed in to fork a gist
  • Save madpilot/3254360 to your computer and use it in GitHub Desktop.
Save madpilot/3254360 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
@madpilot
Copy link
Author

madpilot commented Aug 4, 2012

Then change your form to:

form_tag contact_path(:t => Time.now.gmtime.to_i

or similar

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment