[LON-CAPA-cvs] cvs: loncom /interface createaccount.pm domainprefs.pm loncreateuser.pm

raeburn raeburn at source.lon-capa.org
Fri Feb 19 15:28:47 EST 2016


raeburn		Fri Feb 19 20:28:47 2016 EDT

  Modified files:              
    /loncom/interface	createaccount.pm domainprefs.pm loncreateuser.pm 
  Log:
  - Support version 2 of Google reCAPTCHA.
  
  
-------------- next part --------------
Index: loncom/interface/createaccount.pm
diff -u loncom/interface/createaccount.pm:1.71 loncom/interface/createaccount.pm:1.72
--- loncom/interface/createaccount.pm:1.71	Wed Feb 17 19:15:48 2016
+++ loncom/interface/createaccount.pm	Fri Feb 19 20:28:46 2016
@@ -4,7 +4,7 @@
 # kerberos, or SSO) or an e-mail address. Requests to use an e-mail address as
 # username may be processed automatically, or may be queued for approval.
 #
-# $Id: createaccount.pm,v 1.71 2016/02/17 19:15:48 raeburn Exp $
+# $Id: createaccount.pm,v 1.72 2016/02/19 20:28:46 raeburn Exp $
 #
 # Copyright Michigan State University Board of Trustees
 #
@@ -319,7 +319,7 @@
         $r->print('<form name="backupcrumbs" method="post" action="">'.
                   &Apache::lonhtmlcommon::echo_form_input(['backto','logtoken',
                       'token','serverid','uname','upass','phase','create_with_email',
-                      'code','crypt','cfirstname','clastname',
+                      'code','crypt','cfirstname','clastname','g-recaptcha-response',
                       'recaptcha_challenge_field','recaptcha_response_field',
                       'cmiddlename','cgeneration','cpermanentemail','cid']).
                   '</form>');
@@ -366,7 +366,7 @@
 }
 
 sub javascript_setforms {
-    my ($now,$emailusername,$captcha,$usertype) =  @_;
+    my ($now,$emailusername,$captcha,$usertype,$recaptchaversion) =  @_;
     my ($setuserinfo, at required,$requiredchk);
     if (ref($emailusername) eq 'HASH') {
         if (ref($emailusername->{$usertype}) eq 'HASH') {  
@@ -382,9 +382,11 @@
             $setuserinfo .= '                    server.elements.code.value=client.elements.code.value;'."\n".
                             '                    server.elements.crypt.value=client.elements.crypt.value;'."\n";
         } elsif ($captcha eq 'recaptcha') {
-            $setuserinfo .= 
+            if ($recaptchaversion ne '2') {
+                $setuserinfo .=
                 '                    server.elements.recaptcha_challenge_field.value=client.elements.recaptcha_challenge_field.value;'."\n".
                 '                    server.elements.recaptcha_response_field.value=client.elements.recaptcha_response_field.value;'."\n";
+            }
         }
     }
     if (@required) {
@@ -448,6 +450,9 @@
 // ]]>
 </script>
 ENDSCRIPT
+    if (($captcha eq 'recaptcha') && ($recaptchaversion eq '2')) {
+        $js .= "\n".'<script src="https://www.google.com/recaptcha/api.js"></script>'."\n";
+    }
     return $js;
 }
 
@@ -544,7 +549,8 @@
         }
         if (grep(/^email$/,@{$cancreate})) {
             $output .= '<div class="LC_left_float"><h3>'.&mt('Create account with an e-mail address as your username').'</h3>';
-            my ($captchaform,$error,$captcha) = &Apache::loncommon::captcha_display('usercreation',$lonhost);
+            my ($captchaform,$error,$captcha,$recaptchaversion) = 
+                &Apache::loncommon::captcha_display('usercreation',$lonhost);
             if ($error) {
                 my $helpdesk = '/adm/helpdesk?origurl=%2fadm%2fcreateaccount';
                 if ($courseid ne '') {
@@ -573,7 +579,8 @@
                                $lt{'yopw'}.'<br />';
                 }
                 $output .= &print_dataentry_form($r,$domain,$lonhost,$include,$now,$captchaform,
-                                                 $courseid,$emailusername,$captcha,$usertype);
+                                                 $courseid,$emailusername,$captcha,$usertype,
+                                                 $recaptchaversion);
             }
             $output .= '</div>';
         }
@@ -886,15 +893,15 @@
 #
 sub print_dataentry_form {
     my ($r,$domain,$lonhost,$include,$now,$captchaform,$courseid,$emailusername,$captcha,
-        $usertype) = @_;
+        $usertype,$recaptchaversion) = @_;
     my ($error,$output);
     if (open(my $jsh,"<$include/londes.js")) {
         while(my $line = <$jsh>) {
             $r->print($line);
         }
         close($jsh);
-        $output = &javascript_setforms($now,$emailusername,$captcha,$usertype)."\n".
-                  &javascript_checkpass($now,'email');
+        $output = &javascript_setforms($now,$emailusername,$captcha,$usertype,$recaptchaversion).
+                  "\n".&javascript_checkpass($now,'email');
         my ($lkey,$ukey) = &Apache::loncommon::des_keys();
         my ($lextkey,$uextkey) = &getkeys($lkey,$ukey);
         my $logtoken=Apache::lonnet::reply('tmpput:'.$ukey.$lkey.'&createaccount:createaccount',
@@ -918,10 +925,15 @@
    <input type="hidden" name="code" value="" />
 ';
         } elsif ($captcha eq 'recaptcha') {
-            $output .= '
+            if ($recaptchaversion eq '2') {
+                $output .= "$captchaform\n";
+                undef($captchaform);
+            } else {
+                $output .= '
    <input type="hidden" name="recaptcha_challenge_field" value="" />
    <input type="hidden" name="recaptcha_response_field" value="" />
 ';
+            }
         }
         $output .= <<"ENDSERVERFORM";
    <input type="hidden" name="logtoken" value="$logtoken" />
Index: loncom/interface/domainprefs.pm
diff -u loncom/interface/domainprefs.pm:1.269 loncom/interface/domainprefs.pm:1.270
--- loncom/interface/domainprefs.pm:1.269	Fri Feb 19 02:39:07 2016
+++ loncom/interface/domainprefs.pm	Fri Feb 19 20:28:46 2016
@@ -1,7 +1,7 @@
 # The LearningOnline Network with CAPA
 # Handler to set domain-wide configuration settings
 #
-# $Id: domainprefs.pm,v 1.269 2016/02/19 02:39:07 raeburn Exp $
+# $Id: domainprefs.pm,v 1.270 2016/02/19 20:28:46 raeburn Exp $
 #
 # Copyright Michigan State University Board of Trustees
 #
@@ -6804,7 +6804,7 @@
                 } elsif ($item eq 'recaptchaversion') {
                     if (ref($loginhash{'login'}) eq 'HASH') {
                         if ($loginhash{'login'}{'captcha'} eq 'recaptcha') {
-                            $resulttext .= '<li>'.&mt('ReCAPTCHA set to version [_1]',$loginhash{'login'}{'recaptchaversion'}).
+                            $resulttext .= '<li>'.&mt('ReCAPTCHA for helpdesk form set to version [_1]',$loginhash{'login'}{'recaptchaversion'}).
                                            '</li>';
                         }
                     }
@@ -10218,8 +10218,7 @@
                         $chgtext .= '</ul>';
                     } elsif ($type eq 'recaptchaversion') {
                         if ($savecaptcha{'captcha'} eq 'recaptcha') {
-                            $chgtext .= '<li>'.&mt('ReCAPTCHA set to version [_1]',$savecaptcha{$type}).
-                                        '</li>';
+                            $chgtext .= &mt('ReCAPTCHA set to version [_1]',$savecaptcha{$type});
                         }
                     } elsif ($type eq 'emailusername') {
                         if (ref($cancreate{'emailusername'}) eq 'HASH') {
Index: loncom/interface/loncreateuser.pm
diff -u loncom/interface/loncreateuser.pm:1.409 loncom/interface/loncreateuser.pm:1.410
--- loncom/interface/loncreateuser.pm:1.409	Fri Feb 19 02:39:07 2016
+++ loncom/interface/loncreateuser.pm	Fri Feb 19 20:28:46 2016
@@ -1,7 +1,7 @@
 # The LearningOnline Network with CAPA
 # Create a user
 #
-# $Id: loncreateuser.pm,v 1.409 2016/02/19 02:39:07 raeburn Exp $
+# $Id: loncreateuser.pm,v 1.410 2016/02/19 20:28:46 raeburn Exp $
 #
 # Copyright Michigan State University Board of Trustees
 #
@@ -2164,7 +2164,7 @@
 
 sub personal_data_display {
     my ($ccuname,$ccdomain,$newuser,$context,$inst_results,$rolesarray,
-        $now,$captchaform,$emailusername,$usertype,$recaptchaversion) = @_;
+        $now,$captchaform,$emailusername,$usertype) = @_;
     my ($output,%userenv,%canmodify,%canmodify_status);
     my @userinfo = ('firstname','middlename','lastname','generation',
                     'permanentemail','id');
@@ -2351,12 +2351,9 @@
     }
     if (($context eq 'selfcreate') && ($newuser eq 'email')) {
         if ($captchaform) {
-            $output .= &Apache::lonhtmlcommon::row_title($lt{'valid'},
-                                                         'LC_pick_box_title')."\n";
-            if ($recaptchaversion >=2) {
-                $output .= '<script src="https://www.google.com/recaptcha/api.js"></script>'."\n";
-            }
-            $output .= $captchaform."\n".'<br /><br />'.
+            $output .= &Apache::lonhtmlcommon::row_title($lt{'valid'}.'*',
+                                                         'LC_pick_box_title')."\n".
+                       $captchaform."\n".'<br /><br />'.
                        &Apache::lonhtmlcommon::row_closure(1); 
             $rowcount ++;
         }


More information about the LON-CAPA-cvs mailing list