[Catalyst-commits] r7082 - / trunk/Catalyst-Controller-reCAPTCHA
trunk/Catalyst-Controller-reCAPTCHA/lib/Catalyst/Controller
zarquon at dev.catalyst.perl.org
zarquon at dev.catalyst.perl.org
Wed Oct 31 06:31:15 GMT 2007
Author: zarquon
Date: 2007-10-31 06:31:15 +0000 (Wed, 31 Oct 2007)
New Revision: 7082
Modified:
/
trunk/Catalyst-Controller-reCAPTCHA/Changes
trunk/Catalyst-Controller-reCAPTCHA/META.yml
trunk/Catalyst-Controller-reCAPTCHA/lib/Catalyst/Controller/reCAPTCHA.pm
Log:
r11938 at zaphod: kd | 2007-10-31 14:45:06 +1100
recaptca version 0.300001
Property changes on:
___________________________________________________________________
Name: svk:merge
- 1b129c88-ebf4-0310-add9-f09427935aba:/local/catalyst:4278
1c72fc7c-9ce4-42af-bf25-3bfe470ff1e8:/local/Catalyst:11774
3b9770f9-e80c-0410-a7de-cd203d167417:/local/catalyst:3514
dd8ad9ea-0304-0410-a433-df5f223e7bc0:/local/Catalyst:6909
+ 1b129c88-ebf4-0310-add9-f09427935aba:/local/catalyst:4278
1c72fc7c-9ce4-42af-bf25-3bfe470ff1e8:/local/Catalyst:11938
3b9770f9-e80c-0410-a7de-cd203d167417:/local/catalyst:3514
dd8ad9ea-0304-0410-a433-df5f223e7bc0:/local/Catalyst:6909
Modified: trunk/Catalyst-Controller-reCAPTCHA/Changes
===================================================================
--- trunk/Catalyst-Controller-reCAPTCHA/Changes 2007-10-30 22:49:56 UTC (rev 7081)
+++ trunk/Catalyst-Controller-reCAPTCHA/Changes 2007-10-31 06:31:15 UTC (rev 7082)
@@ -1,4 +1,10 @@
# This file documents the revision history for the perl extension Catalyst::Controller::reCAPTCHA
+0.30001
+ - Don't release modules late at night.
+0.3
+ - Significant architectural changes, thanks Bill Moesley
+0.2
+ - Some changes to improve sanity
0.1
- - Initial version that supplies two : Private methods in your controller to deal with the reCAPTCHA
\ No newline at end of file
+ - Initial version that supplies two : Private methods in your controller to deal with the reCAPTCHA
Modified: trunk/Catalyst-Controller-reCAPTCHA/META.yml
===================================================================
--- trunk/Catalyst-Controller-reCAPTCHA/META.yml 2007-10-30 22:49:56 UTC (rev 7081)
+++ trunk/Catalyst-Controller-reCAPTCHA/META.yml 2007-10-31 06:31:15 UTC (rev 7082)
@@ -16,4 +16,4 @@
requires:
Captcha::reCAPTCHA: 0
perl: 5.8.1
-version: 0.1
+version: 0.3
Modified: trunk/Catalyst-Controller-reCAPTCHA/lib/Catalyst/Controller/reCAPTCHA.pm
===================================================================
--- trunk/Catalyst-Controller-reCAPTCHA/lib/Catalyst/Controller/reCAPTCHA.pm 2007-10-30 22:49:56 UTC (rev 7081)
+++ trunk/Catalyst-Controller-reCAPTCHA/lib/Catalyst/Controller/reCAPTCHA.pm 2007-10-31 06:31:15 UTC (rev 7082)
@@ -3,41 +3,50 @@
use warnings;
use base 'Catalyst::Controller';
use Captcha::reCAPTCHA;
-our $VERSION = '0.2';
+use Carp 'croak';
+our $VERSION = '0.30001';
sub captcha_get : Private {
my ($self, $c) = @_;
my $cap = Captcha::reCAPTCHA->new;
$c->stash->{recaptcha} = $cap->get_html($c->config->{recaptcha}->{pub_key});
+ return;
}
sub captcha_check : Private {
my ($self, $c) = @_;
my $cap = Captcha::reCAPTCHA->new;
- my $result = {};
- if ( $c->req->param( 'recaptcha_response_field' ) ) {
- $result = $cap->check_answer(
- $c->config->{recaptcha}->{priv_key}, $ENV{'REMOTE_ADDR'},
- $c->req->param('recaptcha_challenge_field'),
- $c->req->param('recaptcha_response_field')
- );
+ my $challenge = $c->req->param('recaptcha_challenge_field');
+ my $response = $c->req->param('recaptcha_response_field');
+
+ unless ( $response && $challenge ) {
+ $c->stash->{recaptcha_error} = 'User appears not to have submitted a recaptcha';
+ return;
}
- else {
- $c->stash->{recaptcha_ok} = $result->{is_valid};
- $c->stash->{recaptcha_error} = $result->{error} || "User appears not to have submitted a recaptcha";
- }
- if ( $result->{is_valid} ) {
- $c->stash->{recaptcha_ok} = 1;
- }
- else {
- $c->stash->{recaptcha_ok} = $result->{error};
- }
+ my $key = $c->config->{recaptcha}->{priv_key} || croak 'must set recaptcha priv_key in config';
+
+ my $result = $cap->check_answer(
+ $key,
+ $c->req->address,
+ $challenge,
+ $response,
+ );
+
+ croak 'Failed to get valid result from reCaptcha'
+ unless ref $result eq 'HASH' && exists $result->{is_valid};
+
+
+ $c->stash->{recaptcha_error} = $result->{error} || 'Unknown error'
+ unless $result->{is_valid};
+
+ return ($result->{is_valid} = $result->{is_valid});
}
+
=head1 NAME
Catalyst::Controller::reCAPTCHA - authenticate people and read books!
More information about the Catalyst-commits
mailing list