: <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> ;
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 }
{ $subsections
recaptcha-valid?
recaptcha-error
+}
+"An example:"
+{ $subsections
"recaptcha-example"
} ;
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
} 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 ;