diff --git a/basis/furnace/recaptcha/example/example.factor b/basis/furnace/recaptcha/example/example.factor index d453edb10e..3650e2bcf9 100644 --- a/basis/furnace/recaptcha/example/example.factor +++ b/basis/furnace/recaptcha/example/example.factor @@ -13,19 +13,15 @@ TUPLE: recaptcha-app < dispatcher recaptcha ; : ( -- obj ) - [ - begin-conversation - validate-recaptcha - recaptcha-valid? cget - "?good" "?bad" ? >url - ] >>submit + [ validate-recaptcha ] >>validate + [ "?good" >url ] >>submit { recaptcha-app "example" } >>template ; : ( -- obj ) \ recaptcha-app new-dispatcher "" add-responder - "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 ; diff --git a/basis/furnace/recaptcha/example/example.xml b/basis/furnace/recaptcha/example/example.xml index e59f441f7f..2553b332ef 100644 --- a/basis/furnace/recaptcha/example/example.xml +++ b/basis/furnace/recaptcha/example/example.xml @@ -1,4 +1,4 @@ -
+
diff --git a/basis/furnace/recaptcha/recaptcha-docs.factor b/basis/furnace/recaptcha/recaptcha-docs.factor index 0e901f8bb5..9e5d046a1d 100644 --- a/basis/furnace/recaptcha/recaptcha-docs.factor +++ b/basis/furnace/recaptcha/recaptcha-docs.factor @@ -7,43 +7,41 @@ IN: furnace.recaptcha HELP: { $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 } } - { "Wrap the responder in a " { $link } " if it is not already" } - { "Ensure that there is a database connected, with the " { $link } " 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 } } - { "Put the chloe tag " { $snippet "" } " inside a form tag in the template for your " { $link page-action } } + { "Wrap the responder in an " { $link } " 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 "" } " 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 ;" " 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 } "Validating recaptcha:" { $subsections validate-recaptcha } @@ -51,6 +49,9 @@ ARTICLE: "furnace.recaptcha" "Recaptcha" { $subsections recaptcha-valid? recaptcha-error +} +"An example:" +{ $subsections "recaptcha-example" } ; diff --git a/basis/furnace/recaptcha/recaptcha.factor b/basis/furnace/recaptcha/recaptcha.factor index 020b5e472e..d99af16a52 100644 --- a/basis/furnace/recaptcha/recaptcha.factor +++ b/basis/furnace/recaptcha/recaptcha.factor @@ -11,12 +11,12 @@ TUPLE: recaptcha < filter-responder domain public-key private-key ; SYMBOLS: recaptcha-valid? recaptcha-error ; -: ( responder -- obj ) +: ( responder -- recaptcha ) recaptcha new swap >>responder ; M: recaptcha call-responder* - dup \ recaptcha set + dup recaptcha set responder>> call-responder ; http-request nip parse-recaptcha-response ; -CHLOE: recaptcha - drop [ render-recaptcha ] [xml-code] ; - -PRIVATE> - -: validate-recaptcha ( -- ) +: validate-recaptcha-params ( -- ) { { "recaptcha_challenge_field" [ v-required ] } { "recaptcha_response_field" [ v-required ] } - } validate-params + } validate-params ; + +PRIVATE> + +CHLOE: recaptcha drop [ render-recaptcha ] [xml-code] ; + +: validate-recaptcha ( -- ) + 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 ; diff --git a/extra/webapps/pastebin/pastebin.factor b/extra/webapps/pastebin/pastebin.factor index 684f6f0784..fccf47d468 100644 --- a/extra/webapps/pastebin/pastebin.factor +++ b/extra/webapps/pastebin/pastebin.factor @@ -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