I’m thinking about creating an automatic anti-spam system (maybe I’ll write a public stone) for rails.
My concept is to include a helper method in application_controller fe:
class ApplicationController < ActionController::Base
automatic_captcha_redirect(:min_time => 30.seconds :limit => 50)
...
end
Then I want to include automatical a before_filter in every controller that checks if the current request is being executed via post, put or delete-method.
If the last last user request is less than: min_time, then the request should be redirected to the captcha I / O page (the posted user data is in hidden html fields).
def check_spam
if !request.get? && session[:last_manipulation_at]
&& session[:last_manipulation_at] >= DateTime.now - 30.seconds
redirect_to captcha_path
end
end
And in captcha.haml
=form_tag
-request.params.each do |key, value|
=hidden_field_tag key, value
=captcha_image
=submit_button_tag
, .
, ?
? , ?
EDIT:
- ActiveRecord; (Rails Rack)?
- ? ( )
- Ajax?
- POST, PUT DELETE?
EDIT:
( -- - , ):
0) environment.rb
auto_recaptcha[:limit] = 10
auto_recaptcha[:min_time] = 1.minute
1)
last_manipulation . application_controller.rb
class ApplicationController < ActionController::Base
before_filter :automatic_captcha_redirect
def automatic_captcha_redirect
session[:last_manipulation_at][:manipultation] = [] unless session[:last_manipulation_at][:manipultation]
if !request.get?
&& session[:last_manipulation_at][:date] > DateTime.now - auto_recaptcha[:min_time]
&& session[:last_manipulation_at][:manipultation].count < auto_recaptcha[:limit]
if !verify_captcha(params)
@url = request.url
@params = request.params
render "layouts/captcha.haml"
else
session[:last_manipulation_at][:manipultation] << DateTime.now
session[:last_manipulation_at][:date] = DateTime.now
end
end
end
end
captcha.haml
-form_tag @url do
-request.params.each do |key, value|
=hidden_field_tag key, value
=captcha_image
=submit_button_tag
2)
...
...
...
last)
post(params) => users_path # path "/users" with method: post