#!/usr/bin/perl # # DW::Captcha::reCAPTCHA # # This module handles integration with the reCAPTCHA service # # Authors: # Afuna # # Copyright (c) 2012 by Dreamwidth Studios, LLC. # # This program is free software; you may redistribute it and/or modify it under # the same terms as Perl itself. For a copy of the license, please reference # 'perldoc perlartistic' or 'perldoc perlgpl'. # =head1 NAME DW::Captcha::reCAPTCHA - This module handles integration with the reCAPTCHA service =head1 SYNOPSIS =cut use strict; package DW::Captcha::reCAPTCHA; # avoid base pragma - causes circular requirements require DW::Captcha; our @ISA = qw( DW::Captcha ); BEGIN { my $rv = eval <new; return $captcha->get_html_v2( _public_key(), { theme => 'light' } ); } sub _validate { my $self = $_[0]; my $captcha = Captcha::reCAPTCHA->new; my $result = $captcha->check_answer_v2( _private_key(), $self->response, LJ::get_remote_ip(), ); return 1 if $result->{is_valid} eq '1'; } sub _init_opts { my ( $self, %opts ) = @_; $self->{challenge} = 1; # Parent class checks for a challenge, but reCAPTCHAv2 doesn't use this field any more $self->{response} ||= $opts{'g-recaptcha-response'}; } # recaptcha-specific methods sub _public_key { LJ::conf_test( $LJ::RECAPTCHA{public_key} ) } sub _private_key { LJ::conf_test( $LJ::RECAPTCHA{private_key} ) } 1;