--- loncom/interface/loncommon.pm 2012/08/25 04:34:44 1.1094 +++ loncom/interface/loncommon.pm 2012/08/27 06:28:06 1.1095 @@ -1,7 +1,7 @@ # The LearningOnline Network with CAPA # a pile of common routines # -# $Id: loncommon.pm,v 1.1094 2012/08/25 04:34:44 raeburn Exp $ +# $Id: loncommon.pm,v 1.1095 2012/08/27 06:28:06 raeburn Exp $ # # Copyright Michigan State University Board of Trustees # @@ -14070,7 +14070,7 @@ sub captcha_display { my ($context,$lonhost) = @_; my ($output,$error); my ($captcha,$pubkey,$privkey) = &get_captcha_config($context,$lonhost); - if ($captcha eq 'captcha') { + if ($captcha eq 'original') { $output = &create_captcha(); unless ($output) { $error = 'captcha'; @@ -14078,7 +14078,7 @@ sub captcha_display { } elsif ($captcha eq 'recaptcha') { $output = &create_recaptcha($pubkey); unless ($output) { - $error = 'recpatcha'; + $error = 'recaptcha'; } } return ($output,$error); @@ -14088,7 +14088,7 @@ sub captcha_response { my ($context,$lonhost) = @_; my ($captcha_chk,$captcha_error); my ($captcha,$pubkey,$privkey) = &get_captcha_config($context,$lonhost); - if ($captcha eq 'captcha') { + if ($captcha eq 'original') { ($captcha_chk,$captcha_error) = &check_captcha(); } elsif ($captcha eq 'recaptcha') { $captcha_chk = &check_recaptcha($privkey); @@ -14100,28 +14100,44 @@ sub captcha_response { sub get_captcha_config { my ($context,$lonhost) = @_; - my ($captcha,$pubkey,$privkey); + my ($captcha,$pubkey,$privkey,$hashtocheck); my $hostname = &Apache::lonnet::hostname($lonhost); my $serverhomeID = &Apache::lonnet::get_server_homeID($hostname); my $serverhomedom = &Apache::lonnet::host_domain($serverhomeID); - my %domconfig = &Apache::lonnet::get_dom('configuration',[$context],$serverhomedom); - if (ref($domconfig{$context}) eq 'HASH') { - if ($domconfig{$context}{'captcha'} eq 'recaptcha') { - if (ref($domconfig{$context}{'recaptchakeys'}) eq 'HASH') { - $pubkey = $domconfig{$context}{'recaptchakeys'}{'public'}; - $privkey = $domconfig{$context}{'recaptchakeys'}{'private'}; + if ($context eq 'usercreation') { + my %domconfig = &Apache::lonnet::get_dom('configuration',[$context],$serverhomedom); + if (ref($domconfig{$context}) eq 'HASH') { + $hashtocheck = $domconfig{$context}{'cancreate'}; + if (ref($hashtocheck) eq 'HASH') { + if ($hashtocheck->{'captcha'} eq 'recaptcha') { + if (ref($hashtocheck->{'recaptchakeys'}) eq 'HASH') { + $pubkey = $hashtocheck->{'recaptchakeys'}{'public'}; + $privkey = $hashtocheck->{'recaptchakeys'}{'private'}; + } + if ($privkey && $pubkey) { + $captcha = 'recaptcha'; + } else { + $captcha = 'original'; + } + } elsif ($hashtocheck->{'captcha'} ne 'notused') { + $captcha = 'original'; + } } + } else { + $captcha = 'captcha'; + } + } elsif ($context eq 'login') { + my %domconfhash = &Apache::loncommon::get_domainconf($serverhomedom); + if ($domconfhash{$serverhomedom.'.login.captcha'} eq 'recaptcha') { + $pubkey = $domconfhash{$serverhomedom.'.login.recaptchakeys_public'}; + $privkey = $domconfhash{$serverhomedom.'.login.recaptchakeys_private'}; if ($privkey && $pubkey) { $captcha = 'recaptcha'; + } else { + $captcha = 'original'; } - } elsif ($domconfig{$context}{'captcha'} eq 'notused') { - $captcha = ''; - } elsif ($domconfig{$context}{'captcha'} eq 'captcha') { - $captcha = 'captcha'; - } else { - if ($context eq 'usercreation') { - $captcha = 'captcha'; - } + } elsif ($domconfhash{$serverhomedom.'.login.captcha'} eq 'original') { + $captcha = 'original'; } } return ($captcha,$pubkey,$privkey);