--- loncom/interface/domainprefs.pm 2012/08/27 00:53:22 1.168 +++ loncom/interface/domainprefs.pm 2012/08/27 06:28:05 1.169 @@ -1,7 +1,7 @@ # The LearningOnline Network with CAPA # Handler to set domain-wide configuration settings # -# $Id: domainprefs.pm,v 1.168 2012/08/27 00:53:22 raeburn Exp $ +# $Id: domainprefs.pm,v 1.169 2012/08/27 06:28:05 raeburn Exp $ # # Copyright Michigan State University Board of Trustees # @@ -1054,7 +1054,9 @@ sub print_login { $datatable .= ''; } $datatable .= ''; + $itemcount ++; } + $datatable .= &captcha_choice('login',$settings,$itemcount); } return $datatable; } @@ -3299,9 +3301,10 @@ sub print_usercreation { $dom,$numinrow,$othertitle, 'statustocreate'); $$rowtotal ++; + $rownum ++; } } - $datatable .= &captcha_choice('cancreate',$createsettings); + $datatable .= &captcha_choice('cancreate',$createsettings,$rownum); } else { my @contexts = ('author','course','domain'); my @authtypes = ('int','krb4','krb5','loc'); @@ -3354,14 +3357,14 @@ sub print_usercreation { } sub captcha_choice { - my ($context,$settings) = @_; + my ($context,$settings,$itemcount) = @_; my ($keyentry,$currpub,$currpriv,%checked,$rowname,$pubtext,$privtext); my %lt = &captcha_phrases(); $keyentry = 'hidden'; if ($context eq 'cancreate') { $rowname = &mt('CAPTCHA validation (e-mail as username)'); - } elsif ($context eq 'help') { - $rowname = &mt('CAPTCHA validation'); + } elsif ($context eq 'login') { + $rowname = &mt('"Contact helpdesk" CAPTCHA validation'); } if (ref($settings) eq 'HASH') { if ($settings->{'captcha'}) { @@ -3381,8 +3384,9 @@ sub captcha_choice { } else { $checked{'original'} = ' checked="checked"'; } - my $output = ''. - ''.$rowname.''."\n". + my $css_class = $itemcount%2?' class="LC_odd_row"':''; + my $output = ''. + ''.$rowname.''."\n". '
'."\n"; foreach my $option ('original','recaptcha','notused') { $output .= ''; } } + &process_captcha('login',\%changes,$loginhash{'login'},$domconfig{'login'}); my $defaulthelpfile = '/adm/loginproblems.html'; my $defaulttext = &mt('Default in use'); @@ -4819,6 +4823,42 @@ sub modify_login { } } } + } elsif ($item eq 'captcha') { + if (ref($loginhash{'login'}) eq 'HASH') { + my $chgtxt; + if ($loginhash{'login'}{$item} eq 'notused') { + $chgtxt .= &mt('No CAPTCHA validation in use for helpdesk form.'); + } else { + my %captchas = &captcha_phrases(); + if ($captchas{$loginhash{'login'}{$item}}) { + $chgtxt .= &mt("Validation for helpdesk form set to $captchas{$loginhash{'login'}{$item}}."); + } else { + $chgtxt .= &mt('Validation for helpdesk form set to unknown type.'); + } + } + $resulttext .= '
  • '.$chgtxt.'
  • '; + } + } elsif ($item eq 'recaptchakeys') { + if (ref($loginhash{'login'}) eq 'HASH') { + my ($privkey,$pubkey); + if (ref($loginhash{'login'}{$item}) eq 'HASH') { + $pubkey = $loginhash{'login'}{$item}{'public'}; + $privkey = $loginhash{'login'}{$item}{'private'}; + } + my $chgtxt .= &mt('ReCAPTCHA keys changes').'
      '; + if (!$pubkey) { + $chgtxt .= '
    • '.&mt('Public key deleted').'
    • '; + } else { + $chgtxt .= '
    • '.&mt('Public key set to [_1]',$pubkey).'
    • '; + } + if (!$privkey) { + $chgtxt .= '
    • '.&mt('Private key deleted').'
    • '; + } else { + $chgtxt .= '
    • '.&mt('Private key set to [_1]',$pubkey).'
    • '; + } + $chgtxt .= '
    '; + $resulttext .= '
  • '.$chgtxt.'
  • '; + } } else { $resulttext .= '
  • '.&mt("$title{$item} set to $offon[$env{'form.'.$item}]").'
  • '; } @@ -6911,30 +6951,44 @@ sub process_captcha { $newsettings->{'captcha'} = 'original'; } if ($current->{'captcha'} ne $newsettings->{'captcha'}) { - if (ref($changes->{'cancreate'}) eq 'ARRAY') { - push(@{$changes->{'cancreate'}},'captcha'); - } elsif (!defined($changes->{'cancreate'})) { - $changes->{'cancreate'} = ['captcha']; + if ($container eq 'cancreate') { + if (ref($changes->{'cancreate'}) eq 'ARRAY') { + push(@{$changes->{'cancreate'}},'captcha'); + } elsif (!defined($changes->{'cancreate'})) { + $changes->{'cancreate'} = ['captcha']; + } + } else { + $changes->{'captcha'} = 1; } } my ($newpub,$newpriv,$currpub,$currpriv); if ($newsettings->{'captcha'} eq 'recaptcha') { $newpub = $env{'form.'.$container.'_recaptchapub'}; $newpriv = $env{'form.'.$container.'_recaptchapriv'}; + $newpub =~ s/\W//g; + $newpriv =~ s/\W//g; + $newsettings->{'recaptchakeys'} = { + public => $newpub, + private => $newpriv, + }; } - $newsettings->{'recaptchakeys'} = { - public => $newpub, - private => $newpriv, - }; if (ref($current->{'recaptchakeys'}) eq 'HASH') { $currpub = $current->{'recaptchakeys'}{'public'}; $currpriv = $current->{'recaptchakeys'}{'private'}; + $newsettings->{'recaptchakeys'} = { + public => '', + private => '', + } } if (($newpub ne $currpub) || ($newpriv ne $currpriv)) { - if (ref($changes->{'cancreate'}) eq 'ARRAY') { - push(@{$changes->{'cancreate'}},'recaptchakeys'); - } elsif (!defined($changes->{'cancreate'})) { - $changes->{'cancreate'} = ['recaptchakeys']; + if ($container eq 'cancreate') { + if (ref($changes->{'cancreate'}) eq 'ARRAY') { + push(@{$changes->{'cancreate'}},'recaptchakeys'); + } elsif (!defined($changes->{'cancreate'})) { + $changes->{'cancreate'} = ['recaptchakeys']; + } + } else { + $changes->{'recaptchakeys'} = 1; } } return;