--- loncom/interface/domainprefs.pm 2016/02/18 21:30:33 1.268
+++ loncom/interface/domainprefs.pm 2016/02/19 02:39:07 1.269
@@ -1,7 +1,7 @@
# The LearningOnline Network with CAPA
# Handler to set domain-wide configuration settings
#
-# $Id: domainprefs.pm,v 1.268 2016/02/18 21:30:33 raeburn Exp $
+# $Id: domainprefs.pm,v 1.269 2016/02/19 02:39:07 raeburn Exp $
#
# Copyright Michigan State University Board of Trustees
#
@@ -4955,7 +4955,8 @@ sub email_as_username {
sub captcha_choice {
my ($context,$settings,$itemcount) = @_;
- my ($keyentry,$currpub,$currpriv,%checked,$rowname,$pubtext,$privtext);
+ my ($keyentry,$currpub,$currpriv,%checked,$rowname,$pubtext,$privtext,
+ $vertext,$currver);
my %lt = &captcha_phrases();
$keyentry = 'hidden';
if ($context eq 'cancreate') {
@@ -4973,6 +4974,11 @@ sub captcha_choice {
$pubtext = $lt{'pub'};
$privtext = $lt{'priv'};
$keyentry = 'text';
+ $vertext = $lt{'ver'};
+ $currver = $settings->{'recaptchaversion'};
+ if ($currver ne '2') {
+ $currver = 1;
+ }
}
if (ref($settings->{'recaptchakeys'}) eq 'HASH') {
$currpub = $settings->{'recaptchakeys'}{'public'};
@@ -5006,7 +5012,11 @@ sub captcha_choice {
$currpub.'" size="40" />
'."\n".
''.$privtext.' '."\n".
''."\n".
+ $currpriv.'" size="40" />
'.
+ ''.$vertext.' '."\n".
+ '
'.
+ ''."\n".
'';
return $output;
}
@@ -6791,6 +6801,13 @@ sub modify_login {
$chgtxt .= '';
$resulttext .= '
'.$chgtxt.'';
}
+ } elsif ($item eq 'recaptchaversion') {
+ if (ref($loginhash{'login'}) eq 'HASH') {
+ if ($loginhash{'login'}{'captcha'} eq 'recaptcha') {
+ $resulttext .= ''.&mt('ReCAPTCHA set to version [_1]',$loginhash{'login'}{'recaptchaversion'}).
+ '';
+ }
+ }
} else {
$resulttext .= ''.&mt("$title{$item} set to $offon[$env{'form.'.$item}]").'';
}
@@ -9482,7 +9499,8 @@ sub modify_usercreation {
if (ref($domconfig{'usercreation'}{$key}) eq 'HASH') {
foreach my $item (keys(%{$domconfig{'usercreation'}{$key}})) {
if (($item eq 'selfcreate') || ($item eq 'statustocreate') ||
- ($item eq 'captcha') || ($item eq 'recaptchakeys')) {
+ ($item eq 'captcha') || ($item eq 'recaptchakeys') ||
+ ($item eq 'recaptchaversion')) {
$save_usercreate{$key}{$item} = $domconfig{'usercreation'}{$key}{$item};
} else {
$curr_usercreation{$key}{$item} = $domconfig{'usercreation'}{$key}{$item};
@@ -9706,6 +9724,7 @@ sub modify_selfcreation {
foreach my $item (keys(%{$domconfig{'usercreation'}{$key}})) {
if (($item eq 'selfcreate') || ($item eq 'statustocreate') ||
($item eq 'captcha') || ($item eq 'recaptchakeys') ||
+ ($item eq 'recaptchaversion') ||
($item eq 'emailusername') || ($item eq 'notify') ||
($item eq 'selfcreateprocessing') || ($item eq 'shibenv')) {
$curr_usercreation{$key}{$item} = $domconfig{'usercreation'}{$key}{$item};
@@ -10035,6 +10054,7 @@ sub modify_selfcreation {
#
$save_usercreate{'cancreate'}{'captcha'} = $savecaptcha{'captcha'};
$save_usercreate{'cancreate'}{'recaptchakeys'} = $savecaptcha{'recaptchakeys'};
+ $save_usercreate{'cancreate'}{'recaptchaversion'} = $savecaptcha{'recaptchaversion'};
$save_usercreate{'cancreate'}{'selfcreate'} = $cancreate{'selfcreate'};
if (ref($cancreate{'notify'}) eq 'HASH') {
$save_usercreate{'cancreate'}{'notify'} = $cancreate{'notify'};
@@ -10196,6 +10216,11 @@ sub modify_selfcreation {
$chgtext .= ''.&mt('Private key set to [_1]',$pubkey).'';
}
$chgtext .= '';
+ } elsif ($type eq 'recaptchaversion') {
+ if ($savecaptcha{'captcha'} eq 'recaptcha') {
+ $chgtext .= ''.&mt('ReCAPTCHA set to version [_1]',$savecaptcha{$type}).
+ '';
+ }
} elsif ($type eq 'emailusername') {
if (ref($cancreate{'emailusername'}) eq 'HASH') {
if (ref($types) eq 'ARRAY') {
@@ -10316,7 +10341,7 @@ sub process_captcha {
$changes->{'captcha'} = 1;
}
}
- my ($newpub,$newpriv,$currpub,$currpriv);
+ my ($newpub,$newpriv,$currpub,$currpriv,$newversion,$currversion);
if ($newsettings->{'captcha'} eq 'recaptcha') {
$newpub = $env{'form.'.$container.'_recaptchapub'};
$newpriv = $env{'form.'.$container.'_recaptchapriv'};
@@ -10326,6 +10351,12 @@ sub process_captcha {
public => $newpub,
private => $newpriv,
};
+ $newversion = $env{'form.'.$container.'_recaptchaversion'};
+ $newversion =~ s/\D//g;
+ if ($newversion ne '2') {
+ $newversion = 1;
+ }
+ $newsettings->{'recaptchaversion'} = $newversion;
}
if (ref($current->{'recaptchakeys'}) eq 'HASH') {
$currpub = $current->{'recaptchakeys'}{'public'};
@@ -10337,6 +10368,23 @@ sub process_captcha {
}
}
}
+ if ($current->{'captcha'} eq 'recaptcha') {
+ $currversion = $current->{'recaptchaversion'};
+ if ($currversion ne '2') {
+ $currversion = 1;
+ }
+ }
+ if ($currversion ne $newversion) {
+ if ($container eq 'cancreate') {
+ if (ref($changes->{'cancreate'}) eq 'ARRAY') {
+ push(@{$changes->{'cancreate'}},'recaptchaversion');
+ } elsif (!defined($changes->{'cancreate'})) {
+ $changes->{'cancreate'} = ['recaptchaversion'];
+ }
+ } else {
+ $changes->{'recaptchaversion'} = 1;
+ }
+ }
if (($newpub ne $currpub) || ($newpriv ne $currpriv)) {
if ($container eq 'cancreate') {
if (ref($changes->{'cancreate'}) eq 'ARRAY') {
@@ -13024,6 +13072,8 @@ function updateCaptcha(caller,context) {
var pubitem;
var privtext;
var pubtext;
+ var versionitem;
+ var versiontext;
if (document.getElementById(context+'_recaptchapub')) {
pubitem = document.getElementById(context+'_recaptchapub');
} else {
@@ -13044,6 +13094,16 @@ function updateCaptcha(caller,context) {
} else {
return;
}
+ if (document.getElementById(context+'_recaptchaversion')) {
+ versionitem = document.getElementById(context+'_recaptchaversion');
+ } else {
+ return;
+ }
+ if (document.getElementById(context+'_recaptchavertxt')) {
+ versiontext = document.getElementById(context+'_recaptchavertxt');
+ } else {
+ return;
+ }
if (caller.checked) {
if (caller.value == 'recaptcha') {
pubitem.type = 'text';
@@ -13052,11 +13112,16 @@ function updateCaptcha(caller,context) {
privitem.size = '40';
pubtext.innerHTML = "$lt{'pub'}";
privtext.innerHTML = "$lt{'priv'}";
+ versionitem.type = 'text';
+ versionitem.size = '3';
+ versiontext.innerHTML = "$lt{'ver'}";
} else {
pubitem.type = 'hidden';
privitem.type = 'hidden';
+ versionitem.type = 'hidden';
pubtext.innerHTML = '';
privtext.innerHTML = '';
+ versiontext.innerHTML = '';
}
}
return;
@@ -13122,6 +13187,7 @@ sub captcha_phrases {
original => 'original (CAPTCHA)',
recaptcha => 'successor (ReCAPTCHA)',
notused => 'unused',
+ ver => 'ReCAPTCHA version (1 or 2)',
);
}