capcha control now has reCAPTCHA mode
This commit is contained in:
parent
5d8ede926c
commit
b088299eb0
6 changed files with 127 additions and 9 deletions
|
|
@ -35,6 +35,7 @@ removeBrokenWorkflowInstances($session);
|
||||||
undotBinaryExtensions($session);
|
undotBinaryExtensions($session);
|
||||||
removeProcessRecurringPaymentsFromConfig($session);
|
removeProcessRecurringPaymentsFromConfig($session);
|
||||||
noSessionSwitch($session);
|
noSessionSwitch($session);
|
||||||
|
addReCaptchaSettings($session);
|
||||||
|
|
||||||
fixDottedAssetIds($session); ##This one should run last
|
fixDottedAssetIds($session); ##This one should run last
|
||||||
finish($session); # this line required
|
finish($session); # this line required
|
||||||
|
|
@ -59,6 +60,27 @@ sub removeProcessRecurringPaymentsFromConfig {
|
||||||
print "Done.\n" unless $quiet;
|
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 {
|
sub hideGalleryAlbums {
|
||||||
my $session = shift;
|
my $session = shift;
|
||||||
|
|
|
||||||
|
|
@ -21,6 +21,7 @@ use WebGUI::Mail::Send;
|
||||||
use WebGUI::Storage;
|
use WebGUI::Storage;
|
||||||
use WebGUI::User;
|
use WebGUI::User;
|
||||||
use WebGUI::Utility;
|
use WebGUI::Utility;
|
||||||
|
use WebGUI::Form::Captcha;
|
||||||
use Encode ();
|
use Encode ();
|
||||||
|
|
||||||
our @ISA = qw(WebGUI::Auth);
|
our @ISA = qw(WebGUI::Auth);
|
||||||
|
|
@ -224,8 +225,9 @@ sub createAccountSave {
|
||||||
my $error;
|
my $error;
|
||||||
$error = $self->error unless($self->validUsername($username));
|
$error = $self->error unless($self->validUsername($username));
|
||||||
if ($setting->get("webguiUseCaptcha")) {
|
if ($setting->get("webguiUseCaptcha")) {
|
||||||
unless ($form->process('authWebGUI.captcha', "Captcha")) {
|
my $form = WebGUI::Form::Captcha->new($session, {name => 'authWebGUI.captcha'});
|
||||||
$error .= '<li>'.$i18n->get("captcha failure","AuthWebGUI").'</li>';
|
if (! $form->getValue) {
|
||||||
|
$error .= '<li>' . $form->getErrorMessage . '</li>';
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
$error .= $self->error unless($self->_isValidPassword($password,$passConfirm));
|
$error .= $self->error unless($self->_isValidPassword($password,$passConfirm));
|
||||||
|
|
|
||||||
|
|
@ -18,6 +18,7 @@ use strict;
|
||||||
use base 'WebGUI::Form::Text';
|
use base 'WebGUI::Form::Text';
|
||||||
use WebGUI::International;
|
use WebGUI::International;
|
||||||
use WebGUI::Storage;
|
use WebGUI::Storage;
|
||||||
|
use LWP::UserAgent;
|
||||||
|
|
||||||
=head1 NAME
|
=head1 NAME
|
||||||
|
|
||||||
|
|
@ -101,6 +102,27 @@ Returns a boolean indicating whether the string typed matched the image.
|
||||||
|
|
||||||
sub getValue {
|
sub getValue {
|
||||||
my $self = shift;
|
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 $value = $self->SUPER::getValue(@_);
|
||||||
my $challenge = $self->session->scratch->get("captcha_".$self->get("name"));
|
my $challenge = $self->session->scratch->get("captcha_".$self->get("name"));
|
||||||
$self->session->scratch->delete("captcha_".$self->get("name"));
|
$self->session->scratch->delete("captcha_".$self->get("name"));
|
||||||
|
|
@ -133,14 +155,43 @@ Renders a captcha field.
|
||||||
=cut
|
=cut
|
||||||
|
|
||||||
sub toHtml {
|
sub toHtml {
|
||||||
my $self = shift;
|
my $self = shift;
|
||||||
my $storage = WebGUI::Storage->createTemp($self->session);
|
|
||||||
my ($filename, $challenge) = $storage->addFileFromCaptcha;
|
if ($self->session->setting->get('useRecaptcha')) {
|
||||||
$self->set("size", 6);
|
my $env = $self->session->env;
|
||||||
$self->set("maxlength", 6);
|
my $pubKey = $self->session->setting->get('recaptchaPublicKey');
|
||||||
$self->session->scratch->set("captcha_".$self->get("name"), $challenge);
|
my $server = "http://api.recaptcha.net";
|
||||||
return $self->SUPER::toHtml.'<p style="display:inline;vertical-align:middle;"><img src="'.$storage->getUrl($filename).'" style="border-style:none;vertical-align:middle;" alt="captcha" /></p>';
|
if ($env->get("HTTPS") eq "on" || $env->get("SSLPROXY")) {
|
||||||
|
$server = "http://api-secure.recaptcha.net";
|
||||||
|
}
|
||||||
|
return
|
||||||
|
'<script type="text/javascript" src="' . $server . '/challenge?k=' . $pubKey . '"></script>'
|
||||||
|
. '<noscript>'
|
||||||
|
. '<iframe src="' . $server . '/noscript?k=' . $pubKey
|
||||||
|
. '" height="300" width="500" frameborder="0"></iframe>'
|
||||||
|
. '<textarea name="recaptcha_challenge_field" rows="3" cols="40"></textarea>'
|
||||||
|
. '<input type="hidden" name="recaptcha_response_field" value="manual_challenge" />'
|
||||||
|
. '</noscript>';
|
||||||
|
}
|
||||||
|
|
||||||
|
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.'<p style="display:inline;vertical-align:middle;"><img src="'.$storage->getUrl($filename).'" style="border-style:none;vertical-align:middle;" alt="captcha" /></p>';
|
||||||
}
|
}
|
||||||
|
|
||||||
|
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;
|
1;
|
||||||
|
|
||||||
|
|
|
||||||
|
|
@ -240,6 +240,28 @@ sub definition {
|
||||||
namespace=>"AdminConsole",
|
namespace=>"AdminConsole",
|
||||||
defaultValue=>$setting->get("AdminConsoleTemplate")
|
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
|
# messaging settings
|
||||||
push(@fields, {
|
push(@fields, {
|
||||||
tab=>"messaging",
|
tab=>"messaging",
|
||||||
|
|
|
||||||
|
|
@ -13,6 +13,14 @@ our $I18N = {
|
||||||
lastUpdated => 1131394072,
|
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;
|
1;
|
||||||
|
|
|
||||||
|
|
@ -4325,6 +4325,19 @@ Users may override this setting in their profile.
|
||||||
lastUpdated => 1230930518,
|
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 <a href="http://recaptcha.net/">http://recaptcha.net/</a>.}
|
||||||
|
},
|
||||||
|
|
||||||
|
'recaptcha private key' => {
|
||||||
|
message => 'reCAPTCHA Private Key'
|
||||||
|
},
|
||||||
|
'recaptcha public key' => {
|
||||||
|
message => 'reCAPTCHA Public Key'
|
||||||
|
},
|
||||||
};
|
};
|
||||||
|
|
||||||
1;
|
1;
|
||||||
|
|
|
||||||
Loading…
Add table
Add a link
Reference in a new issue