public
Description: BrainBuster - a logic captcha for Rails
Homepage: http://opensource.thinkrelevance.com/wiki/BrainBuster
Clone URL: git://github.com/rsanheim/brain_buster.git
updating docs, prepping for 0.8 release
rsanheim (author)
Mon Feb 11 23:27:35 -0800 2008
commit  a0192b1a4880ea0c0ea340ebe402d7b930cdbe39
tree    261201a10e3d61bb957f4e62bf6f01efb4303c20
parent  316800d668033a1cbe218308b2623754e7f52a33
...
2
3
4
 
 
5
6
7
8
 
 
 
9
10
11
12
13
14
 
 
 
15
16
17
 
 
18
19
 
20
21
22
...
2
3
4
5
6
7
 
 
 
8
9
10
11
 
 
 
 
 
12
13
14
15
16
17
18
19
20
 
21
22
23
24
0
@@ -2,21 +2,23 @@ BrainBuster changelog
0
 =====================
0
 
0
 TODOs (someday/maybe)
0
+* ensure backwards compatible with rails 1.2.6
0
+* ensure the random id we find is always really in the DB
0
 * figure out some sort of declarative API that doesn't suck...
0
-# protect_with_brain_buster :create => :show, :validate => :update, :on_failure => :show
0
-# protect :update, :from => [:show, :index]
0
-# brain_buster_form_on :show, :protect => :update
0
+ # protect_with_brain_buster :create => :show, :validate => :update, :on_failure => :show
0
+ # protect :update, :from => [:show, :index]
0
+ # brain_buster_form_on :show, :protect => :update
0
 
0
-TODOs (for 0.8)
0
-* ensure backwards compatible?
0
-
0
-0.8.0
0
-* fix for Rails 2 compatibility
0
+0.8.0 (2007/02/12)
0
+* clean up all over the place
0
+* fix for Rails 2 compatibility - return false doesn't halt the filter chain
0
 * rename brain_buster_error_message to brain_buster_failure_message
0
 * change captcha_failure so it just places failure message into the flash, and also render :text's it -- you must override render_or_redirect_for_captcha_failure to handle failure yourself in a smarter way!
0
 * change captcha failure to *only render the failure message text* -- you have to handle failure yourself for a better user experience!
0
+* move to github
0
+* move project tracking to Relevance open source trac
0
 
0
-0.7.2
0
+0.7.2 (never officially released)
0
 * add a default salt to make setup easier
0
 * add info on the salt to readme
0
 * rename BrainBusterFilters to BrainBusterSystem, since it has more then just filters in it
0
...
1
2
3
4
5
 
 
6
7
 
 
 
8
9
 
10
11
12
 
13
14
15
16
17
18
19
 
20
21
 
22
23
24
25
 
 
 
 
 
26
27
28
...
36
37
38
39
40
41
42
43
44
45
 
46
47
48
 
49
50
51
...
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
 
 
 
 
 
 
 
 
 
 
73
74
75
76
77
78
79
80
 
 
 
 
 
 
 
 
 
 
 
81
82
 
 
 
 
83
84
85
...
87
88
89
90
 
 
91
92
93
...
1
2
3
 
4
5
6
7
 
8
9
10
11
 
12
13
 
 
14
15
16
17
18
19
20
 
21
22
 
23
24
25
26
 
27
28
29
30
31
32
33
34
...
42
43
44
 
45
46
47
48
49
 
50
51
 
 
52
53
54
55
...
57
58
59
 
 
 
 
 
 
 
 
 
60
61
62
63
64
65
 
 
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
 
 
82
83
84
85
86
87
88
89
90
91
92
93
 
94
95
96
97
98
99
100
...
102
103
104
 
105
106
107
108
109
0
@@ -1,28 +1,34 @@
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
 
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
 
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
 
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
 
0
 * How to install fresh in a Rails app?
0
 
0
 script/plugin install http://robsanheim.googlecode.com/svn/trunk/brain_buster
0
 script/generate brain_buster_migration
0
 rake db:migrate
0
-optionally set the salt in your ApplicationController
0
+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
 
0
 * Want to check out the source?
0
 
0
-svn checkout http://robsanheim.googlecode.com/svn/trunk/brain_buster/ brainbuster
0
+git clone git://github.com/rsanheim/brain_buster.git
0
+
0
+or
0
+
0
+svn checkout http://opensource.thinkrelevance.com/svn/brain_buster/trunk/ brainbuster
0
 
0
 * Need more help?
0
 
0
@@ -36,16 +42,14 @@ Some example question and answers are:
0
 
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
 
0
 For more on logic captchas and alternate approaches, please see http://www.w3.org/TR/turingtest/#logic
0
 
0
 Details
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
 
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
 Installation
0
 =======================================
0
@@ -53,33 +57,44 @@ Installation
0
 
0
     script/generate brain_buster_migration
0
 
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
-
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
-
0
- # add the style sheet if you like
0
- <%= stylesheet_link_tag 'captcha' %>
0
-
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
 
0
     class PagesController
0
       before_filter :create_brain_buster, :only => [:show]
0
       before_filter :validate_brain_buster, :only => [:update]
0
       
0
- def show... # your normal code is here
0
- def update...
0
+ def show # your normal code is here
0
+ def update # updating your models, etc
0
+
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
+
0
+ class PagesController
0
+
0
+ def render_or_redirect_for_captcha_failure
0
+ render :action => "show"
0
+ end
0
        
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
 
0
     - 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
+
0
+* Copy the style sheet into your app's public directory (optional)
0
+
0
+ cp vendor/plugins/brain_buster/assets/stylesheets/captcha.css public/stylesheets/
0
+
0
+ # add the style sheet to any views that use the captcha
0
+ <%= stylesheet_link_tag 'captcha' %>
0
+
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
 
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
 
0
 Real world usage
0
 ================
0
@@ -87,6 +102,7 @@ You can see the plugin in action at http://madisonrails.com or at http://wiki.ru
0
 
0
 Credits
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
 
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
...
2
3
4
5
 
6
7
8
...
2
3
4
 
5
6
7
8
0
@@ -2,7 +2,7 @@ require 'humane_integer'
0
 
0
  # Simple model to hold sets of questions and answers.
0
 class BrainBuster < ActiveRecord::Base
0
- VERSION = "0.0.8"
0
+ VERSION = "0.8.0"
0
   PROJECT_HOME = "http://opensource.thinkrelevance.com/wiki/BrainBuster"
0
 
0
   # Attempt to answer a captcha, returns true if the answer is correct.
...
1
2
 
 
3
...
 
1
2
3
4
0
@@ -1 +1,2 @@
0
-<%= render :partial => "/captcha" %>
0
\ No newline at end of file
0
+<%= render :partial => "/captcha" %>
0
+<%= render :partial => "/captcha_footer" %>
0
\ No newline at end of file
...
1
 
2
3
4
...
 
1
2
3
4
0
@@ -1,3 +1,3 @@
0
-<% unless captcha_previously_passed? %>
0
+<% unless captcha_passed? %>
0
     <span id="captcha_credit">powered by <a href="http://robsanheim.com/brain_buster/">Brain Buster logic captcha</a></span>
0
 <% end %>
0
\ No newline at end of file

Comments

    No one has commented yet.