Created
August 4, 2012 04:12
-
-
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...
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
# 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
Then change your form to:
or similar