[Catalyst-commits] r10580 - in trunk/Catalyst-Controller-reCAPTCHA: . lib/Catalyst/Controller

zarquon at dev.catalyst.perl.org zarquon at dev.catalyst.perl.org
Thu Jun 18 02:44:36 GMT 2009


Author: zarquon
Date: 2009-06-18 02:44:36 +0000 (Thu, 18 Jun 2009)
New Revision: 10580

Modified:
   trunk/Catalyst-Controller-reCAPTCHA/Changes
   trunk/Catalyst-Controller-reCAPTCHA/META.yml
   trunk/Catalyst-Controller-reCAPTCHA/lib/Catalyst/Controller/reCAPTCHA.pm
Log:
version 0.4

Modified: trunk/Catalyst-Controller-reCAPTCHA/Changes
===================================================================
--- trunk/Catalyst-Controller-reCAPTCHA/Changes	2009-06-18 01:21:17 UTC (rev 10579)
+++ trunk/Catalyst-Controller-reCAPTCHA/Changes	2009-06-18 02:44:36 UTC (rev 10580)
@@ -1,5 +1,7 @@
 # This file documents the revision history for the perl extension Catalyst::Controller::reCAPTCHA
 
+0.4 Thu 18th June 2009
+        - Doc fixes
 0.31
         - Hardcoded $c->stash->{recaptcha_ok} back into application.
 0.30001 

Modified: trunk/Catalyst-Controller-reCAPTCHA/META.yml
===================================================================
--- trunk/Catalyst-Controller-reCAPTCHA/META.yml	2009-06-18 01:21:17 UTC (rev 10579)
+++ trunk/Catalyst-Controller-reCAPTCHA/META.yml	2009-06-18 02:44:36 UTC (rev 10580)
@@ -1,19 +1,30 @@
-abstract: authenticate people and read books!
-author: and Copyright
-build_requires: 
+---
+abstract: 'authenticate people and read books!'
+author:
+  - 'and Copyright'
+build_requires:
   Catalyst::Runtime: 0
+  ExtUtils::MakeMaker: 6.42
   Test::More: 0
   Test::WWW::Mechanize::Catalyst: 0
   ok: 0
+configure_requires:
+  ExtUtils::MakeMaker: 6.42
 distribution_type: module
-generated_by: Module::Install version 0.64
+generated_by: 'Module::Install version 0.880'
 license: perl
+meta-spec:
+  url: http://module-build.sourceforge.net/META-spec-v1.4.html
+  version: 1.4
 name: Catalyst-Controller-reCAPTCHA
-no_index: 
-  directory: 
+no_index:
+  directory:
     - inc
     - t
-requires: 
+requires:
   Captcha::reCAPTCHA: 0
   perl: 5.8.1
-version: 0.3
+resources:
+  license: http://dev.perl.org/licenses/
+  repository: http://dev.catalyst.perl.org/repos/Catalyst/trunk/Catalyst-Controller-reCAPTCHA/
+version: 0.4

Modified: trunk/Catalyst-Controller-reCAPTCHA/lib/Catalyst/Controller/reCAPTCHA.pm
===================================================================
--- trunk/Catalyst-Controller-reCAPTCHA/lib/Catalyst/Controller/reCAPTCHA.pm	2009-06-18 01:21:17 UTC (rev 10579)
+++ trunk/Catalyst-Controller-reCAPTCHA/lib/Catalyst/Controller/reCAPTCHA.pm	2009-06-18 02:44:36 UTC (rev 10580)
@@ -4,13 +4,14 @@
 use base 'Catalyst::Controller';
 use Captcha::reCAPTCHA;
 use Carp 'croak';
-our $VERSION = '0.31';
+our $VERSION = '0.4';
 
 
 sub captcha_get : Private {
     my ($self, $c) = @_;
     my $cap = Captcha::reCAPTCHA->new;
-    $c->stash->{recaptcha} = $cap->get_html($c->config->{recaptcha}->{pub_key});
+    $c->stash->{recaptcha} =
+        $cap->get_html($c->config->{recaptcha}->{pub_key});
     return;
 }
 
@@ -18,15 +19,17 @@
     my ($self, $c) = @_;
     my $cap = Captcha::reCAPTCHA->new;
     my $challenge = $c->req->param('recaptcha_challenge_field');
-    my $response = $c->req->param('recaptcha_response_field');
-    
+    my $response  = $c->req->param('recaptcha_response_field');
+
     unless ( $response && $challenge ) {
-        $c->stash->{recaptcha_error} = 'User appears not to have submitted a recaptcha';
+        $c->stash->{recaptcha_error} =
+            'User appears not to have submitted a recaptcha';
         return;
     }
 
-    my $key = $c->config->{recaptcha}->{priv_key} || croak 'must set recaptcha priv_key in config';
-    
+    my $key = $c->config->{recaptcha}->{priv_key} ||
+        croak 'must set recaptcha priv_key in config';
+
     my $result = $cap->check_answer(
         $key,
         $c->req->address,
@@ -38,8 +41,9 @@
         unless ref $result eq 'HASH' && exists $result->{is_valid};
 
 
-    $c->stash->{recaptcha_error} = $result->{error} || 'Unknown error'
-        unless $result->{is_valid};
+    $c->stash->{recaptcha_error} = $result->{error} ||
+        'Unknown error'
+            unless $result->{is_valid};
 
     $c->stash->{recaptcha_ok} = 1 if $result->{is_valid};
     return ($result->{is_valid} == $result->{is_valid});
@@ -61,10 +65,14 @@
 
 In MyApp.pm (or equivalent in config file):
 
- __PACKAGE__->config->{recaptcha}->{pub_key} = '6LcsbAAAAAAAAPDSlBaVGXjMo1kJHwUiHzO2TDze';
- __PACKAGE__->config->{recaptcha}->{priv_key} = '6LcsbAAAAAAAANQQGqwsnkrTd7QTGRBKQQZwBH-L';
+ __PACKAGE__->config->{recaptcha}->{pub_key} =
+                          '6LcsbAAAAAAAAPDSlBaVGXjMo1kJHwUiHzO2TDze';
+ __PACKAGE__->config->{recaptcha}->{priv_key} =
+                          '6LcsbAAAAAAAANQQGqwsnkrTd7QTGRBKQQZwBH-L';
 
-(the two keys above work for http://localhost).
+(the two keys above work for http://localhost unless someone hammers the
+reCAPTCHA server with failures, in which case the API keys get a temporary
+ban).
 
 =head2 METHOD
 
@@ -77,10 +85,23 @@
 captcha_check : Private
 
 Validates the reCaptcha using L<Captcha::reCAPTCHA>.  sets
-$c->stash->{recaptcha_ok} which will be 1 on success.  If there's an
-error, $c->stash->{recaptcha_error} is set with the error string
-provided by L<Captcha::reCAPTCHA>.
+$c->stash->{recaptcha_ok} which will be 1 on success. The action also returns
+true if there is success. This means you can do:
 
+ if ( $c->forward(captcha_check) ) {
+   # do something based on the reCAPTCHA passing
+ }
+
+or alternatively:
+
+ if ( $c->stash->{recaptcha_ok} ) {
+   # do something based on the reCAPTCHA passing
+ }
+
+
+If there's an error, $c->stash->{recaptcha_error} is
+set with the error string provided by L<Captcha::reCAPTCHA>.
+
 =head2 EXAMPLES
 
 See the t/lib/TestApp example in the




More information about the Catalyst-commits mailing list