0
BrainBuster - A Logic Captcha For Rails
0
=======================================
0
Homepage: http://opensource.thinkrelevance.com/wiki/BrainBuster
0
-SVN Repository: http://robsanheim.googlecode.com/svn/trunk/brain_buster
0
Mailing List: http://groups.google.com/group/brainbuster-discuss
0
+Git Repository (dev happens here): git://github.com/rsanheim/brain_buster.git
0
+SVN Repository (read only mirror): http://opensource.thinkrelevance.com/svn/brain_buster/trunk/
0
-The latest version removes all depreacted code from 0.7 and below, and does serious clean up all over the place.
0
+Notes (for 0.8.0 release)
0
+=========================
0
+The latest version removes all deprecated code from 0.7 and below, and does serious clean up all over the place.
0
-
Note that you also have to handle captcha failure on your own, since Rails 2.0 requires a render or redirect to halt a filter chain. This makes sense anyways, as to really have a nice user experience you should be placing the user's half saved model in the flash (or something) and then pulling it back into the form if the captcha fails.
0
+
You now have to handle captcha failure on your own, since Rails 2.0 requires a render or redirect to halt a filter chain. This makes sense anyways, because if you really want a decent user experience you should be placing the user's half saved model in the flash (or an ivar, or a cookie, or whatever) and then pulling it back into the form if the captcha fails.
0
-This salt should be consistent across your entire application, else you will run into problems between different Rails instances. A simple random string can be generated with the following code from irb:
0
- [Array.new(32){rand(256).chr}.join].pack("m").chomp
0
+See the CHANGELOG for more details.
0
* How to install fresh in a Rails app?
0
script/plugin install http://robsanheim.googlecode.com/svn/trunk/brain_buster
0
script/generate brain_buster_migration
0
-optionally set the
salt in your ApplicationController0
+optionally set the
cookie salt in your ApplicationController (or just use the default)0
add the appropriate filters where you want to use the captcha
0
-
add the _captcha.rhtml partial to any views where you want to challenge the userand you are all set!
0
+
render the _captcha.rhtml partial to any views where you want to challenge the user and you are all set!
0
* Want to check out the source?
0
-svn checkout http://robsanheim.googlecode.com/svn/trunk/brain_buster/ brainbuster
0
+git clone git://github.com/rsanheim/brain_buster.git
0
+svn checkout http://opensource.thinkrelevance.com/svn/brain_buster/trunk/ brainbuster
0
@@ -36,16 +42,14 @@ Some example question and answers are:
0
"What is fifteen minus five?" => "10"
0
"Which one of these doesn't fit? 'blue, red, yellow, flower'" => 'flower'
0
-"Spell the word 'dog' backwards." => "god"
0
For more on logic captchas and alternate approaches, please see http://www.w3.org/TR/turingtest/#logic
0
=======================================
0
-BrainBuster includes a model for storing questions and answers, a small module
with filters that is mixed into ActionController::Bases, a small partial to display the question and input form, and a basic stylesheet for styling the partial. There is also a "captcha_footer" partial that is not functionally required at all, its just included to make it easy to give credit and a little link-love if you find this useful. The style sheet is also not required of course, it just has a little bit of clean css for the captcha form.
0
+BrainBuster includes a model for storing questions and answers, a small module
that is mixed into ActionController::Bases, a small partial to display the question and input form, and a basic stylesheet for styling the partial. There is also a "captcha_footer" partial that is not functionally required at all, its just included to make it easy to give credit and a little link-love if you find this useful. The style sheet is also not required of course, it just has a little bit of clean css for the captcha form.
0
-This captcha is meant to be user-friendly, so for a questions like "What is two plus two", all of the following answers will work: "4", "four", "Four", " four ". By default, a user only needs to answer a captcha _once_, then they are cookied and don't have to answer another question
0
-until they close/reopen their browser.
0
+This captcha is meant to be user-friendly, so for a questions like "What is two plus two", all of the following answers will work: "4", "four", "Four", " four ". By default, a user only needs to answer a captcha _once_, then they are cookied and don't have to answer another question until they close/reopen their browser.
0
=======================================
0
@@ -53,33 +57,44 @@ Installation
0
script/generate brain_buster_migration
0
-* Copy the style sheet and partials into their appropriate places - this will depend upon your application, though I suggest
0
- placing the partial into /app/views/shared if you want to use it for multiple controllers.
0
- cp vendor/plugins/brain_buster/assets/stylesheets/captcha.css public/stylesheets/
0
- cp vendor/plugins/brain_buster/views/brain_busters/_*.rhtml app/views/shared/
0
- # add the style sheet if you like
0
- <%= stylesheet_link_tag 'captcha' %>
0
* Now add the filters for any action(s) you want protected. Lets say in a PagesController you have a show action that presents a page to a user with some nice ajax capable fields that can directly post to an update action to change the page. So we need to create a captcha before we show the page so we can present the captcha question to the user, and we need to validate that captcha before we update.
0
before_filter :create_brain_buster, :only => [:show]
0
before_filter :validate_brain_buster, :only => [:update]
0
- def show... # your normal code is here
0
+ def show # your normal code is here
0
+ def update # updating your models, etc
0
+* override render_or_redirect_for_captcha_failure in your controller, to handle the captcha failure state. Note that if you *don't override* this method, BrainBuster will just do render :text with the brain buster error message -- this is probably not what you want.
0
+ def render_or_redirect_for_captcha_failure
0
+ render :action => "show"
0
* render the partial in appropriate templates - if we are creating the captcha for the show action, we probably need the
0
form rendered in show.rhtml.
0
... inside your update form somewhere
0
- <%= render :partial => 'shared/captcha' %>
0
- <%= render :partial => "shared/captcha_footer" %> --> only if you want to give credit back...
0
+ <%= render :partial => '/captcha' %>
0
+ <%= render :partial => "/captcha_footer" %> --> optional, only if you want to give credit back...
0
+* Copy the style sheet into your app's public directory (optional)
0
+ cp vendor/plugins/brain_buster/assets/stylesheets/captcha.css public/stylesheets/
0
+ # add the style sheet to any views that use the captcha
0
+ <%= stylesheet_link_tag 'captcha' %>
0
+* Thats it. Now if the captcha fails on update, the filter chain will place the failure message into flash[:error] and call render_or_redirect_for_captcha_failure.
0
-* Thats it. Now if the captcha fails on update, the filter chain will halt and flash[:error] will have a message (by default). You can override that by defining your own captcha_failure method in your controllers.
0
+Troubleshooting and Gotchas
0
+===========================
0
+* If you don't override render_or_redirect_for_captcha_failure, you will see a plain error message for a failed captcha.
0
+* If you delete a question, the random id finder may try to find that deleted question and blow up. For now, just insert another question with that same id to fix the issue.
0
@@ -87,6 +102,7 @@ You can see the plugin in action at http://madisonrails.com or at http://wiki.ru
0
=======================================
0
-BrainBuster is by Rob Sanheim (http://robsanheim.com). Email: rsanheim at gmail DOT com
0
+BrainBuster is by Rob Sanheim (http://robsanheim.com) and Relevance (http://thinkrelevance.com).
0
+Email: rsanheim at gmail no spam dot com
0
Thanks to the creators of the Exception Logger plugin (http://svn.techno-weenie.net/projects/plugins/exception_logger/) and the Unobtrusive Javascript plugin (http://www.ujs4rails.com/), as I referred to their source code for help.
0
\ No newline at end of file
Comments
No one has commented yet.