Commit 27206f782dd6b1cdb321e56cf3e26e8b7cdff474

Authored by JoenioCosta
1 parent 72b0a334

ActionItem146: added inverse_captcha plugin

git-svn-id: https://svn.colivre.coop.br/svn/noosfero/trunk@1609 3f533792-8f58-4932-b0fe-aaf55b0a4547
vendor/plugins/inverse_captcha/README 0 → 100644
... ... @@ -0,0 +1,29 @@
  1 +InverseCaptcha
  2 +==============
  3 +
  4 +Implement simple Anti-Comment-Spam Technique.
  5 +
  6 +Basic Usage
  7 +===========
  8 +
  9 +Add method inverse_captcha on controller:
  10 +
  11 +ps.: dont use this method more than once time on same controller.
  12 +
  13 + inverse_captcha :field => 'e-mail'[, class => 'ghost']
  14 +
  15 +Add the field in view form:
  16 +
  17 + <%= icaptcha_field() %>
  18 +
  19 +Check if field is blank in your controller:
  20 +
  21 + if params[controller.icaptcha_field].blank?
  22 + do...
  23 + else
  24 + dont...
  25 + end
  26 +
  27 +---
  28 +Joenio Costa <joenio@colivre.coop.br>
  29 +Qui Mar 27 15:48:12 BRT 2008
... ...
vendor/plugins/inverse_captcha/init.rb 0 → 100644
... ... @@ -0,0 +1,3 @@
  1 +ActionController::Base.extend(InverseCaptcha::ClassMethods)
  2 +ActionController::Base.send(:include, InverseCaptcha::InstanceMethods)
  3 +ActionView::Base.send(:include, InverseCaptchaHelper)
... ...
vendor/plugins/inverse_captcha/lib/inverse_captcha.rb 0 → 100644
... ... @@ -0,0 +1,18 @@
  1 +module InverseCaptcha
  2 +
  3 + module ClassMethods
  4 + def inverse_captcha(opt = {})
  5 + InverseCaptcha.const_set("ICAPTCHA_FIELD", opt[:field])
  6 + InverseCaptcha.const_set("ICAPTCHA_LABEL", opt[:label] || N_("Don't fill this field"))
  7 + InverseCaptcha.const_set("ICAPTCHA_STYLECLASS", opt[:class] || 'ghost')
  8 + self.send(:include, InverseCaptcha)
  9 + end
  10 + end
  11 +
  12 + module InstanceMethods
  13 + def icaptcha_field
  14 + ICAPTCHA_FIELD
  15 + end
  16 + end
  17 +
  18 +end
... ...
vendor/plugins/inverse_captcha/lib/inverse_captcha_helper.rb 0 → 100644
... ... @@ -0,0 +1,11 @@
  1 +module InverseCaptchaHelper
  2 +
  3 + def icaptcha_field(opt = {})
  4 + label = controller.class::ICAPTCHA_LABEL
  5 + field = controller.class::ICAPTCHA_FIELD
  6 + opt.merge!({:class => controller.class::ICAPTCHA_STYLECLASS})
  7 + stylesheet = "<style type='text/css'> span.#{opt[:class]} { display: none; } </style>"
  8 + stylesheet + content_tag('span', labelled_form_field(_(label), text_field_tag(field, nil)), opt)
  9 + end
  10 +
  11 +end
... ...