diff --git a/docs/upgrades/upgrade_7.6.10-7.6.11.pl b/docs/upgrades/upgrade_7.6.10-7.6.11.pl index 33190c38c..42c270692 100644 --- a/docs/upgrades/upgrade_7.6.10-7.6.11.pl +++ b/docs/upgrades/upgrade_7.6.10-7.6.11.pl @@ -35,6 +35,7 @@ removeBrokenWorkflowInstances($session); undotBinaryExtensions($session); removeProcessRecurringPaymentsFromConfig($session); noSessionSwitch($session); +addReCaptchaSettings($session); fixDottedAssetIds($session); ##This one should run last finish($session); # this line required @@ -59,6 +60,27 @@ sub removeProcessRecurringPaymentsFromConfig { print "Done.\n" unless $quiet; } +#---------------------------------------------------------------------------- +sub addReCaptchaSettings { + my $session = shift; + print "\tAdding settings for reCAPTCHA..." unless $quiet; + my $currentSetting; + + $currentSetting = $session->setting->get('useRecaptcha'); + $session->setting->remove('useRecaptcha'); + $session->setting->add('useRecaptcha', $currentSetting); + + $currentSetting = $session->setting->get('recaptchaPublicKey'); + $session->setting->remove('recaptchaPublicKey'); + $session->setting->add('recaptchaPublicKey', $currentSetting); + + $currentSetting = $session->setting->get('recaptchaPrivateKey'); + $session->setting->remove('recaptchaPrivateKey'); + $session->setting->add('recaptchaPrivateKey', $currentSetting); + + print "Done.\n" unless $quiet; +} + #---------------------------------------------------------------------------- sub hideGalleryAlbums { my $session = shift; diff --git a/lib/WebGUI/Auth/WebGUI.pm b/lib/WebGUI/Auth/WebGUI.pm index eeb308e06..cebcc6509 100644 --- a/lib/WebGUI/Auth/WebGUI.pm +++ b/lib/WebGUI/Auth/WebGUI.pm @@ -21,6 +21,7 @@ use WebGUI::Mail::Send; use WebGUI::Storage; use WebGUI::User; use WebGUI::Utility; +use WebGUI::Form::Captcha; use Encode (); our @ISA = qw(WebGUI::Auth); @@ -224,8 +225,9 @@ sub createAccountSave { my $error; $error = $self->error unless($self->validUsername($username)); if ($setting->get("webguiUseCaptcha")) { - unless ($form->process('authWebGUI.captcha', "Captcha")) { - $error .= '
  • '.$i18n->get("captcha failure","AuthWebGUI").'
  • '; + my $form = WebGUI::Form::Captcha->new($session, {name => 'authWebGUI.captcha'}); + if (! $form->getValue) { + $error .= '
  • ' . $form->getErrorMessage . '
  • '; } } $error .= $self->error unless($self->_isValidPassword($password,$passConfirm)); diff --git a/lib/WebGUI/Form/Captcha.pm b/lib/WebGUI/Form/Captcha.pm index c03d7a282..5bf652570 100644 --- a/lib/WebGUI/Form/Captcha.pm +++ b/lib/WebGUI/Form/Captcha.pm @@ -18,6 +18,7 @@ use strict; use base 'WebGUI::Form::Text'; use WebGUI::International; use WebGUI::Storage; +use LWP::UserAgent; =head1 NAME @@ -101,6 +102,27 @@ Returns a boolean indicating whether the string typed matched the image. sub getValue { my $self = shift; + + if ($self->session->setting->get('useRecaptcha')) { + my $privKey = $self->session->setting->get('recaptchaPrivateKey'); + my $challenge = $self->session->form->param('recaptcha_challenge_field'); + my $response = $self->session->form->param('recaptcha_response_field'); + + my $ua = LWP::UserAgent->new; + my $res = $ua->post('http://api-verify.recaptcha.net/verify', { + privatekey => $privKey, + remoteip => $self->session->env->getIp, + challenge => $challenge, + response => $response, + }); + if ($res->is_success) { + my ($answer, $error) = split /\n/, $res->content, 2; + $self->{_error} = $error; + return $answer eq 'true'; + } + return undef; + } + my $value = $self->SUPER::getValue(@_); my $challenge = $self->session->scratch->get("captcha_".$self->get("name")); $self->session->scratch->delete("captcha_".$self->get("name")); @@ -133,14 +155,43 @@ Renders a captcha field. =cut sub toHtml { - my $self = shift; - my $storage = WebGUI::Storage->createTemp($self->session); - my ($filename, $challenge) = $storage->addFileFromCaptcha; - $self->set("size", 6); - $self->set("maxlength", 6); - $self->session->scratch->set("captcha_".$self->get("name"), $challenge); - return $self->SUPER::toHtml.'

    captcha

    '; + my $self = shift; + + if ($self->session->setting->get('useRecaptcha')) { + my $env = $self->session->env; + my $pubKey = $self->session->setting->get('recaptchaPublicKey'); + my $server = "http://api.recaptcha.net"; + if ($env->get("HTTPS") eq "on" || $env->get("SSLPROXY")) { + $server = "http://api-secure.recaptcha.net"; + } + return + '' + . ''; + } + + my $storage = WebGUI::Storage->createTemp($self->session); + my ($filename, $challenge) = $storage->addFileFromCaptcha; + $self->set("size", 6); + $self->set("maxlength", 6); + $self->session->scratch->set("captcha_".$self->get("name"), $challenge); + return $self->SUPER::toHtml.'

    captcha

    '; } +sub getErrorMessage { + my $self = shift; + my $session = $self->session; + my $i18n = WebGUI::International->new($session,"Form_Captcha"); + if ($session->setting->get('useRecaptcha')) { + return $i18n->get("recaptcha failure"); + } + return $i18n->get("captcha failure"); +} + + 1; diff --git a/lib/WebGUI/Operation/Settings.pm b/lib/WebGUI/Operation/Settings.pm index 5996b3fa8..98ec97d6b 100644 --- a/lib/WebGUI/Operation/Settings.pm +++ b/lib/WebGUI/Operation/Settings.pm @@ -240,6 +240,28 @@ sub definition { namespace=>"AdminConsole", defaultValue=>$setting->get("AdminConsoleTemplate") }); + push(@fields, { + tab => "ui", + fieldType => "yesNo", + name => "useRecaptcha", + label => $i18n->get('use recaptcha'), + hoverHelp => $i18n->get('use recaptcha description'), + defaultValue => $setting->get('useRecaptcha'), + }); + push(@fields, { + tab => "ui", + fieldType => "text", + name => "recaptchaPublicKey", + label => $i18n->get('recaptcha public key'), + defaultValue => $setting->get('recaptchaPublicKey'), + }); + push(@fields, { + tab => "ui", + fieldType => "text", + name => "recaptchaPrivateKey", + label => $i18n->get('recaptcha private key'), + defaultValue => $setting->get('recaptchaPrivateKey'), + }); # messaging settings push(@fields, { tab=>"messaging", diff --git a/lib/WebGUI/i18n/English/Form_Captcha.pm b/lib/WebGUI/i18n/English/Form_Captcha.pm index 765e75cc1..9d08ffce3 100644 --- a/lib/WebGUI/i18n/English/Form_Captcha.pm +++ b/lib/WebGUI/i18n/English/Form_Captcha.pm @@ -13,6 +13,14 @@ our $I18N = { lastUpdated => 1131394072, }, + 'captcha failure' => { + message => q|You need to type in the six characters you see in the image to prove that you are human.|, + }, + + 'recaptcha failure' => { + message => q|You need to correctly enter the words you see in the image to prove that you are human.|, + }, + }; 1; diff --git a/lib/WebGUI/i18n/English/WebGUI.pm b/lib/WebGUI/i18n/English/WebGUI.pm index d25dbf04b..5342c4957 100644 --- a/lib/WebGUI/i18n/English/WebGUI.pm +++ b/lib/WebGUI/i18n/English/WebGUI.pm @@ -4325,6 +4325,19 @@ Users may override this setting in their profile. lastUpdated => 1230930518, }, + 'use recaptcha' => { + message => q{Use reCAPTCHA?} + }, + 'use recaptcha description' => { + message => q{reCAPTCHA is a free CAPTCHA service that helps to digitize books. It requires a key set generated for your domain, available from http://recaptcha.net/.} + }, + + 'recaptcha private key' => { + message => 'reCAPTCHA Private Key' + }, + 'recaptcha public key' => { + message => 'reCAPTCHA Public Key' + }, }; 1;