]> gitweb.factorcode.org Git - factor.git/commitdiff
furnace.recaptcha: make it easier to use
authorSlava Pestov <slava@slava-pestovs-macbook-pro.local>
Thu, 11 Mar 2010 08:02:39 +0000 (21:02 +1300)
committerSlava Pestov <slava@slava-pestovs-macbook-pro.local>
Thu, 11 Mar 2010 08:02:39 +0000 (21:02 +1300)
basis/furnace/recaptcha/example/example.factor
basis/furnace/recaptcha/example/example.xml
basis/furnace/recaptcha/recaptcha-docs.factor
basis/furnace/recaptcha/recaptcha.factor
extra/webapps/pastebin/pastebin.factor

index d453edb10e57ac545338be0c3193fec15a54a820..3650e2bcf999a5df9435ae4a4aea4df2b9be4768 100644 (file)
@@ -13,19 +13,15 @@ TUPLE: recaptcha-app < dispatcher recaptcha ;
 
 : <recaptcha-challenge> ( -- obj )
     <page-action>
-        [
-            begin-conversation
-            validate-recaptcha
-            recaptcha-valid? cget
-            "?good" "?bad" ? >url <continue-conversation>
-        ] >>submit
+        [ validate-recaptcha ] >>validate
+        [ "?good" >url <redirect> ] >>submit
         { recaptcha-app "example" } >>template ;
 
 : <recaptcha-app> ( -- obj )
     \ recaptcha-app new-dispatcher
         <recaptcha-challenge> "" add-responder
         <recaptcha>
-        "concatenative.org" >>domain
-        "6LeJWQgAAAAAAFlYV7SuBClE9uSpGtV_ZS-qVON7" >>public-key
-        "6LeJWQgAAAAAALh-XJgSSQ6xKygRgJ8-029Ip2Xv" >>private-key
+            "concatenative.org" >>domain
+            "6LeJWQgAAAAAAFlYV7SuBClE9uSpGtV_ZS-qVON7" >>public-key
+            "6LeJWQgAAAAAALh-XJgSSQ6xKygRgJ8-029Ip2Xv" >>private-key
         recaptcha-db <alloy> ;
index e59f441f7facd2d539f96bd88af392d3a21deb6b..2553b332efbdeab1fd371d8fbaa67c9392cef373 100644 (file)
@@ -1,4 +1,4 @@
 <?xml version='1.0' ?>
 <t:chloe xmlns:t="http://factorcode.org/chloe/1.0">
-<html><body><form submit="" method="post"><t:recaptcha/></form></body></html>
+<html><body><t:form t:action=""><t:recaptcha/></t:form></body></html>
 </t:chloe>
index 0e901f8bb5979327b0da97611266b3f2a290d5e8..9e5d046a1dfc389a8364f85cc54d5eacbbc442a4 100644 (file)
@@ -7,43 +7,41 @@ IN: furnace.recaptcha
 HELP: <recaptcha>
 { $values
     { "responder" "a responder" }
-    { "obj" object }
+    { "recaptcha" recaptcha }
 }
-{ $description "A " { $link filter-responder } " wrapping another responder. Set the domain, public, and private keys using the key you get by registering with Recaptcha." } ;
+{ $description "A " { $link filter-responder } " wrapping another responder. Set the domain, public, and private keys using the key you get by registering with recaptcha." } ;
 
 HELP: recaptcha-error
-{ $var-description "Set to the error string returned by the Recaptcha server." } ;
+{ $var-description "Set to the error string returned by the recaptcha server." } ;
 
 HELP: recaptcha-valid?
-{ $var-description "Set to " { $link t } " if the user solved the last Recaptcha correctly." } ;
+{ $var-description "Set to " { $link t } " if the user solved the last recaptcha correctly." } ;
 
 HELP: validate-recaptcha
-{ $description "Validates a Recaptcha using the Recaptcha web service API." } ;
+{ $description "Validates a recaptcha using the recaptcha web service API." } ;
 
 ARTICLE: "recaptcha-example" "Recaptcha example"
-"There are several steps to using the Recaptcha library."
+"There are several steps to using the recaptcha library."
 { $list
     { "Wrap the responder in a " { $link <recaptcha> } }
-    { "Wrap the responder in a " { $link <conversations> } " if it is not already" }
-    { "Ensure that there is a database connected, with the " { $link <alloy> } " word" }
-    { "Start a conversation with " { $link begin-conversation } " to move values between requests" }
-    { "Add a handler calling " { $link validate-recaptcha } " in the " { $slot "submit" } " of the " { $link page-action } }
-    { "Pass the conversation from your submit action using " { $link <continue-conversation> } }
-    { "Put the chloe tag " { $snippet "<recaptcha/>" } " inside a form tag in the template for your " { $link page-action } }
+    { "Wrap the responder in an " { $link <alloy> } " if it is not already, to enable conversations and database access" }
+    { "Call " { $link validate-recaptcha } " from the " { $slot "validate" } " slot of the " { $link action } }
+    { "Put the chloe tag " { $snippet "<recaptcha/>" } " inside a form tag in the template served by your " { $link action } }
 }
 $nl
-"Run this example vocabulary:"
+"There is an example web app using recaptcha support:"
 { $code
-    "USE: furnace.recaptcha.example"
+    "USING: furnace.recaptcha.example http.server ;"
     "<recaptcha-app> main-responder set-global"
+    "8080 httpd"
 } ;
 
-ARTICLE: "furnace.recaptcha" "Recaptcha"
-"The " { $vocab-link "furnace.recaptcha" } " vocabulary implements support for the Recaptcha. Recaptcha is a web service that provides the user with a captcha, a test that is easy to solve by visual inspection, but hard to solve by writing a computer program. Use a captcha to protect forms from abusive users." $nl
+ARTICLE: "furnace.recaptcha" "Recaptcha support for Furnace"
+"The " { $vocab-link "furnace.recaptcha" } " vocabulary implements support for the recaptcha. Recaptcha is a web service that provides the user with a captcha, a test that is easy to solve by visual inspection, but hard to solve by writing a computer program. Use a captcha to protect forms from abusive users." $nl
 
-"The recaptcha responder is a " { $link filter-responder } " that wraps another responder. Set the " { $slot "domain" } ", " { $slot "public-key" } ", and " { $slot "private-key" } " slots of this responder to your Recaptcha account information." $nl
+"The recaptcha responder is a " { $link filter-responder } " that wraps another responder. Set the " { $slot "domain" } ", " { $slot "public-key" } ", and " { $slot "private-key" } " slots of this responder to your recaptcha account information." $nl
 
-"Wrapping a responder with Recaptcha:"
+"Wrapping a responder with recaptcha support:"
 { $subsections <recaptcha> }
 "Validating recaptcha:"
 { $subsections validate-recaptcha }
@@ -51,6 +49,9 @@ ARTICLE: "furnace.recaptcha" "Recaptcha"
 { $subsections
     recaptcha-valid?
     recaptcha-error
+}
+"An example:"
+{ $subsections
     "recaptcha-example"
 } ;
 
index 020b5e472e6843d11f5ebdebcbcfbffc01acf077..d99af16a521879739b972c1de603c2473b74b45d 100644 (file)
@@ -11,12 +11,12 @@ TUPLE: recaptcha < filter-responder domain public-key private-key ;
 
 SYMBOLS: recaptcha-valid? recaptcha-error ;
 
-: <recaptcha> ( responder -- obj )
+: <recaptcha> ( responder -- recaptcha )
     recaptcha new
         swap >>responder ;
 
 M: recaptcha call-responder*
-    dup recaptcha set
+    dup recaptcha set
     responder>> call-responder ;
 
 <PRIVATE
@@ -60,17 +60,23 @@ M: recaptcha call-responder*
     } URL" http://api-verify.recaptcha.net/verify"
     <post-request> http-request nip parse-recaptcha-response ;
 
-CHLOE: recaptcha
-    drop [ render-recaptcha ] [xml-code] ;
+: validate-recaptcha-params ( -- )
+    {
+        { "recaptcha_challenge_field" [ v-required ] }
+        { "recaptcha_response_field" [ v-required ] }
+    } validate-params ;
 
 PRIVATE>
 
+CHLOE: recaptcha drop [ render-recaptcha ] [xml-code] ;
+
 : validate-recaptcha ( -- )
-    {
-        { "recaptcha_challenge_field" [ v-required ] }
-        { "recaptcha_response_field" [ v-required ] }
-    } validate-params
+    begin-conversation
+    validate-recaptcha-params
+
     "recaptcha_challenge_field" value
     "recaptcha_response_field" value
-    \ recaptcha get (validate-recaptcha)
-    [ recaptcha-valid? cset ] [ recaptcha-error cset ] bi* ;
+    recaptcha get
+    (validate-recaptcha)
+    recaptcha-error cset
+    [ validation-failed ] unless ;
index 684f6f0784bfa62a515c11e0008b0b1956e925a8..fccf47d468394d38d64310495bc43a18882d6cde 100644 (file)
@@ -159,10 +159,7 @@ M: annotation entity-url
         { "mode" [ v-mode ] }
         { "contents" [ v-required ] }
     } validate-params
-
-    begin-conversation
-    validate-recaptcha
-    recaptcha-valid? cget [ validation-failed ] unless ;
+    validate-recaptcha ;
 
 : deposit-entity-slots ( tuple -- )
     now >>date