Revision 8166
Added by Jing Tao about 11 years ago
src/perl/ldapweb.cgi | ||
---|---|---|
38 | 38 |
use URI; # for parsing URL syntax |
39 | 39 |
use Config::Properties; # for parsing Java .properties files |
40 | 40 |
use File::Basename; # for path name parsing |
41 |
use Captcha::reCAPTCHA; # for protection against spams |
|
41 | 42 |
use Cwd 'abs_path'; |
42 | 43 |
|
43 | 44 |
# Global configuration paramters |
... | ... | |
279 | 280 |
sub fullTemplate { |
280 | 281 |
my $templateList = shift; |
281 | 282 |
my $templateVars = setVars(shift); |
282 |
|
|
283 |
my $c = Captcha::reCAPTCHA->new; |
|
284 |
my $captcha = 'captcha'; |
|
285 |
#my $error=null; |
|
286 |
my $use_ssl= 1; |
|
287 |
#my $options=null; |
|
288 |
$templateVars->{$captcha} = $c->get_html('6LcUD-cSAAAAANmwhTdCgmcieFk2IEhYGILR93gz',undef, $use_ssl, undef); |
|
283 | 289 |
$template->process( $templates->{'header'}, $templateVars ); |
284 | 290 |
foreach my $tmpl (@{$templateList}) { |
285 | 291 |
$template->process( $templates->{$tmpl}, $templateVars ); |
... | ... | |
292 | 298 |
# |
293 | 299 |
sub handleInitRegister { |
294 | 300 |
my $vars = shift; |
295 |
|
|
296 | 301 |
print "Content-type: text/html\n\n"; |
297 | 302 |
# process the template files: |
298 | 303 |
fullTemplate(['register'], {stage => "register"}); |
... | ... | |
306 | 311 |
sub handleRegister { |
307 | 312 |
|
308 | 313 |
print "Content-type: text/html\n\n"; |
309 |
|
|
314 |
|
|
315 |
|
|
310 | 316 |
my $allParams = { 'givenName' => $query->param('givenName'), |
311 | 317 |
'sn' => $query->param('sn'), |
312 | 318 |
'o' => $query->param('o'), |
... | ... | |
316 | 322 |
'userPassword2' => $query->param('userPassword2'), |
317 | 323 |
'title' => $query->param('title'), |
318 | 324 |
'telephoneNumber' => $query->param('telephoneNumber') }; |
325 |
|
|
326 |
# Check the recaptcha |
|
327 |
my $c = Captcha::reCAPTCHA->new; |
|
328 |
my $challenge = $query->param('recaptcha_challenge_field'); |
|
329 |
my $response = $query->param('recaptcha_response_field'); |
|
330 |
# Verify submission |
|
331 |
my $result = $c->check_answer( |
|
332 |
"private google key", $ENV{'REMOTE_ADDR'}, |
|
333 |
$challenge, $response |
|
334 |
); |
|
335 |
|
|
336 |
if ( $result->{is_valid} ) { |
|
337 |
#print "Yes!"; |
|
338 |
#exit(); |
|
339 |
} |
|
340 |
else { |
|
341 |
my $errorMessage = "The verification code is wrong. Please input again."; |
|
342 |
fullTemplate(['register'], { stage => "register", |
|
343 |
allParams => $allParams, |
|
344 |
errorMessage => $errorMessage }); |
|
345 |
exit(); |
|
346 |
} |
|
347 |
|
|
348 |
|
|
319 | 349 |
# Check that all required fields are provided and not null |
320 | 350 |
my @requiredParams = ( 'givenName', 'sn', 'o', 'mail', |
321 | 351 |
'uid', 'userPassword', 'userPassword2'); |
Also available in: Unified diff
Add the recaptcha protection.