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

raeburn raeburn at source.lon-capa.org
Thu Dec 9 23:14:52 EST 2021


raeburn		Fri Dec 10 04:14:52 2021 EDT

  Modified files:              
    /loncom/interface	createaccount.pm loncreateuser.pm 
  Log:
  - g-recaptcha (ReCaptcha v2) needs to be in "server" form not "client" form.
    - Reverse part of change in createaccount.pm 1.83
    - Validation box with "Create account" button now below Personal Data table
      to reduce likelihood that repeated of reCaptcha will be needed.
  
  
-------------- next part --------------
Index: loncom/interface/createaccount.pm
diff -u loncom/interface/createaccount.pm:1.84 loncom/interface/createaccount.pm:1.85
--- loncom/interface/createaccount.pm:1.84	Sun Sep 26 20:11:14 2021
+++ loncom/interface/createaccount.pm	Fri Dec 10 04:14:52 2021
@@ -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.84 2021/09/26 20:11:14 raeburn Exp $
+# $Id: createaccount.pm,v 1.85 2021/12/10 04:14:52 raeburn Exp $
 #
 # Copyright Michigan State University Board of Trustees
 #
@@ -438,7 +438,9 @@
                 }
                 $setuserinfo .= '                    server.elements.'.$key.'.value=client.elements.'.$key.'.value;'."\n";
             }
-            $setuserinfo .= '                    server.elements.type.value=client.elements.type.value;'."\n"; 
+            if ($usertype ne '') {
+                $setuserinfo .= '                    server.elements.type.value=client.elements.type.value;'."\n";
+            }
         }
         if ($captcha eq 'original') {
             $setuserinfo .= '                    server.elements.code.value=client.elements.code.value;'."\n".
@@ -1181,42 +1183,54 @@
         my ($lextkey,$uextkey) = &getkeys($lkey,$ukey);
         my $logtoken=Apache::lonnet::reply('tmpput:'.$ukey.$lkey.'&createaccount:createaccount',
                                            $lonhost);
-        $output .=
+        my $showsubmit = 1;
+        my $serverform =
             '<form name="createaccount" method="post" target="_top" action="/adm/createaccount">';
         if ($courseid ne '') {
-            $output .= '<input type="hidden" name="courseid" value="'.$courseid.'"/>'."\n";
+            $serverform .= '<input type="hidden" name="courseid" value="'.$courseid.'"/>'."\n";
         }
         if (ref($emailusername) eq 'HASH') {
             if (ref($emailusername->{$usertype}) eq 'HASH') {
                 foreach my $field (sort(keys(%{$emailusername->{$usertype}}))) {
-                    $output .= '<input type="hidden" name="'.$field.'" value="" />'."\n";
+                    $serverform .= '<input type="hidden" name="'.$field.'" value="" />'."\n";
                 }
             }
         }
         if ($captcha eq 'original') {
-            $output .= '
+            $serverform .= '
    <input type="hidden" name="crypt" value="" />
    <input type="hidden" name="code" value="" />
 ';
-            $captchaform .= '<br /><br />';
-            
         } elsif ($captcha eq 'recaptcha') {
-            unless ($recaptchaversion eq '2') {
-                $output .= '
+            if ($recaptchaversion eq '2') {
+                $serverform .= &Apache::lonhtmlcommon::start_pick_box().
+                               &Apache::lonhtmlcommon::row_title(&mt('Validation').'<b>*</b>',
+                                                                 'LC_pick_box_title',
+                                                                 'LC_oddrow_value')."\n".
+                                                                 $captchaform.
+                               &Apache::lonhtmlcommon::row_closure(1)."\n".
+                               &Apache::lonhtmlcommon::row_title()."\n".
+                               '<br /><input type="button" name="createaccount" value="'.
+                               &mt('Create account').'" onclick="checkpass('."'createaccount','newemail'".')" />'.
+                               &Apache::lonhtmlcommon::row_closure(1)."\n".
+                               &Apache::lonhtmlcommon::end_pick_box();
+                undef($captchaform);
+                undef($showsubmit);
+            } else {
+                $serverform .= '
    <input type="hidden" name="recaptcha_challenge_field" value="" />
    <input type="hidden" name="recaptcha_response_field" value="" />
 ';
-                $captchaform .= '<br /><br />';
             }
         }
         if ($usertype ne '') {
-            $output .= '<input type="hidden" name="type" value="'.
-                       &HTML::Entities::encode($usertype,'\'<>"&').'" />'."\n";
+            $serverform .= '<input type="hidden" name="type" value="'.
+                           &HTML::Entities::encode($usertype,'\'<>"&').'" />'."\n";
         }
         if ($usernameset eq 'free') {
-            $output .= '<input type="hidden" name="username" value="" />'."\n"; 
+            $serverform .= '<input type="hidden" name="username" value="" />'."\n"; 
         }
-        $output .= <<"ENDSERVERFORM";
+        $serverform .= <<"ENDSERVERFORM";
    <input type="hidden" name="logtoken" value="$logtoken" />
    <input type="hidden" name="serverid" value="$lonhost" />
    <input type="hidden" name="uname" value="" />
@@ -1228,25 +1242,33 @@
 ENDSERVERFORM
         my $beginclientform = '<form name="newemail" method="post" action="" '.
                               'onsubmit="return checkpass('."'createaccount','newemail'".');">'."\n";
-        my $endclientform = '<input type="hidden" name="udom" value="'.$domain.'" />'."\n".
-                            '<input type="hidden" name="lextkey" value="'.$lextkey.'" />'."\n".
-                            '<input type="hidden" name="uextkey" value="'.$uextkey.'" />'."\n".
-                            '</form>'."\n".
-                            '<p class="LC_info">'.&mt('Fields marked [_1]*[_2] are required.','<b>','</b>').'</p>';
+        my $endclientform;
+        unless ($showsubmit) {
+            if ($usertype ne '') {
+                $endclientform = '<input type="hidden" name="type" value="'.
+                                 &HTML::Entities::encode($usertype,'\'<>"&').'" />'."\n";
+            }
+        }
+        $endclientform .= '<input type="hidden" name="udom" value="'.$domain.'" />'."\n".
+                          '<input type="hidden" name="lextkey" value="'.$lextkey.'" />'."\n".
+                          '<input type="hidden" name="uextkey" value="'.$uextkey.'" />'."\n".
+                          '</form>'."\n";
         my ($datatable,$rowcount) =
             &Apache::loncreateuser::personal_data_display('',$domain,'email','selfcreate',
                                                           '','',$now,$captchaform,
                                                           $emailusername,$usertype,
-                                                          $usernameset,$condition,$excluded);
+                                                          $usernameset,$condition,$excluded,
+                                                          $showsubmit);
         if ($rowcount) {
-            $output .= '<div class="LC_left_float">'.$beginclientform.$datatable.$endclientform;
+            $output .= '<div class="LC_left_float">'.$beginclientform.$datatable.$endclientform.'</div>'."\n".
+                       '<div class="LC_clear_float_footer"></div>'."\n";
         } else {
             $output .= $beginclientform.$endclientform;
         }
-        if ($rowcount) {
-            $output .= '</div>'."\n".
-                       '<div class="LC_clear_float_footer"></div>'."\n";
-        }
+        $output .= $serverform.
+                   '<p class="LC_info">'.
+                   &mt('Fields marked [_1]*[_2] are required.','<b>','</b>').
+                   '</p>';
     } else {
         $output = &mt('Could not load javascript file [_1]','<tt>londes.js</tt>');
     }
Index: loncom/interface/loncreateuser.pm
diff -u loncom/interface/loncreateuser.pm:1.455 loncom/interface/loncreateuser.pm:1.456
--- loncom/interface/loncreateuser.pm:1.455	Sat Sep 25 20:35:26 2021
+++ loncom/interface/loncreateuser.pm	Fri Dec 10 04:14:52 2021
@@ -1,7 +1,7 @@
 # The LearningOnline Network with CAPA
 # Create a user
 #
-# $Id: loncreateuser.pm,v 1.455 2021/09/25 20:35:26 raeburn Exp $
+# $Id: loncreateuser.pm,v 1.456 2021/12/10 04:14:52 raeburn Exp $
 #
 # Copyright Michigan State University Board of Trustees
 #
@@ -71,6 +71,7 @@
 use Apache::lonuserutils;
 use Apache::loncoursequeueadmin;
 use LONCAPA qw(:DEFAULT :match);
+use HTML::Entities;
 
 my $loginscript; # piece of javascript used in two separate instances
 my $authformnop;
@@ -2441,8 +2442,8 @@
 }
 
 sub personal_data_display {
-    my ($ccuname,$ccdomain,$newuser,$context,$inst_results,$rolesarray,
-        $now,$captchaform,$emailusername,$usertype,$usernameset,$condition,$excluded) = @_;
+    my ($ccuname,$ccdomain,$newuser,$context,$inst_results,$rolesarray,$now,
+        $captchaform,$emailusername,$usertype,$usernameset,$condition,$excluded,$showsubmit) = @_;
     my ($output,%userenv,%canmodify,%canmodify_status);
     my @userinfo = ('firstname','middlename','lastname','generation',
                     'permanentemail','id');
@@ -2675,16 +2676,21 @@
         if ($captchaform) {
             $output .= &Apache::lonhtmlcommon::row_title($lt{'valid'}.'*',
                                                          'LC_pick_box_title')."\n".
-                       $captchaform."\n".
+                       $captchaform."\n".'<br /><br />'.
                        &Apache::lonhtmlcommon::row_closure(1); 
             $rowcount ++;
         }
-        my $submit_text = &mt('Create account');
-        $output .= &Apache::lonhtmlcommon::row_title()."\n".
-                   '<br /><input type="submit" name="createaccount" value="'.
-                   $submit_text.'" />'.
-                   '<input type="hidden" name="type" value="'.$usertype.'" />'.
-                   &Apache::lonhtmlcommon::row_closure(1);
+        if ($showsubmit) {
+            my $submit_text = &mt('Create account');
+            $output .= &Apache::lonhtmlcommon::row_title()."\n".
+                       '<br /><input type="submit" name="createaccount" value="'.
+                       $submit_text.'" />';
+            if ($usertype ne '') {
+                $output .= '<input type="hidden" name="type" value="'.
+                           &HTML::Entities::encode($usertype,'\'<>"&').'" />';
+            }
+            $output .= &Apache::lonhtmlcommon::row_closure(1);
+        }
     }
     $output .= &Apache::lonhtmlcommon::end_pick_box();
     if (wantarray) {


More information about the LON-CAPA-cvs mailing list