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

raeburn raeburn at source.lon-capa.org
Wed Feb 19 12:20:32 EST 2014


raeburn		Wed Feb 19 17:20:32 2014 EDT

  Modified files:              
    /loncom/interface	createaccount.pm 
  Log:
  - Bug 6646
    - Self-creation of user accounts with e-mail address as username.
    - Now user information and password are requested from prospective user in 
      a single web page, need to support submission of either original CAPTCHA
      or newer reCAPTCHA input by copying from "client" to "server" forms.
  
  
-------------- next part --------------
Index: loncom/interface/createaccount.pm
diff -u loncom/interface/createaccount.pm:1.58 loncom/interface/createaccount.pm:1.59
--- loncom/interface/createaccount.pm:1.58	Wed Feb 12 20:47:40 2014
+++ loncom/interface/createaccount.pm	Wed Feb 19 17:20:32 2014
@@ -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.58 2014/02/12 20:47:40 raeburn Exp $
+# $Id: createaccount.pm,v 1.59 2014/02/19 17:20:32 raeburn Exp $
 #
 # Copyright Michigan State University Board of Trustees
 #
@@ -291,6 +291,7 @@
                   &Apache::lonhtmlcommon::echo_form_input(['backto','logtoken',
                       'token','serverid','uname','upass','phase','create_with_email',
                       'code','crypt','cfirstname','clastname',
+                      'recaptcha_challenge_field','recaptcha_response_field',
                       'cmiddlename','cgeneration','cpermanentemail','cid']).
                   '</form>');
     }
@@ -321,12 +322,19 @@
 }
 
 sub javascript_setforms {
-    my ($now,$emailusername) =  @_;
+    my ($now,$emailusername,$captcha) =  @_;
     my $setuserinfo; 
     if (ref($emailusername) eq 'HASH') {
         foreach my $key (sort(keys(%{$emailusername}))) {
             $setuserinfo .= '      server.elements.'.$key.'.value=client.elements.'.$key.'.value;'."\n";
         }
+        if ($captcha eq 'original') {
+            $setuserinfo .= '      server.elements.code.value=client.elements.code.value;'."\n".
+                            '      server.elements.crypt.value=client.elements.crypt.value;'."\n";
+        } elsif ($captcha eq 'recaptcha') {
+            $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";
+        }
     }
     my $js = <<ENDSCRIPT;
 <script type="text/javascript">
@@ -343,8 +351,6 @@
                 if (context == 'email') {
                     $setuserinfo
                 }
-                server.elements.code.value=client.elements.code.value;
-                server.elements.crypt.value=client.elements.crypt.value;
 
                 uextkey=client.elements.uextkey.value;
                 lextkey=client.elements.lextkey.value;
@@ -428,29 +434,35 @@
 
 sub print_username_form {
     my ($r,$domain,$domdesc,$cancreate,$now,$lonhost,$include,$courseid,$gotlondes,$emailusername) = @_;
-    my %lt = &Apache::lonlocal::texthash(
+    my %lt = &Apache::lonlocal::texthash (
                                          unam => 'username',
                                          udom => 'domain',
                                          uemail => 'E-mail address in LON-CAPA',
-                                         proc => 'Proceed');
+                                         proc => 'Proceed',
+                                         crac => 'Create account with a username provided by this institution',
+                                         clca => 'Create LON-CAPA account',
+                                         type => 'Type in your log-in ID and password to find out.',
+                                         plse => 'Please provide a password for your new account.',
+                                         info => 'Please provide user information and a password for your new account.',
+                                         yopw => 'Your password will be encrypted when sent (and stored).',
+                                         );
     my $output;
     if (ref($cancreate) eq 'ARRAY') {
         if (grep(/^login$/,@{$cancreate})) {
             my %domdefaults = &Apache::lonnet::get_domain_defaults($domain);
             if ((($domdefaults{'auth_def'} =~/^krb/) && ($domdefaults{'auth_arg_def'} ne '')) || ($domdefaults{'auth_def'} eq 'localauth')) {
-                $output = '<div class="LC_left_float"><h3>'.&mt('Create account with a username provided by this institution').'</h3>';
-                my $submit_text = &mt('Create LON-CAPA account');
-                $output .= &mt('If you already have a log-in ID at this institution,[_1] you may be able to use it for LON-CAPA.','<br />').
+                $output = '<div class="LC_left_float"><h3>'.$lt{'crac'}.'</h3>';
+                $output .= &mt('If you already have a log-in ID at this institution [_1]you may be able to use it for LON-CAPA.','<br />').
                            '<br /><br />'.
-                           &mt('Type in your log-in ID and password to find out.').
+                           $lt{'type'}.
                            '<br /><br />';
-                $output .= &login_box($now,$lonhost,$courseid,$submit_text,
+                $output .= &login_box($now,$lonhost,$courseid,$lt{'clca'},
                                       $domain,'createaccount').'</div>';
             }
         }
         if (grep(/^email(|approval)$/,@{$cancreate})) {
             $output .= '<div class="LC_left_float"><h3>'.&mt('Create account with an e-mail address as your username').'</h3>';
-            my ($captchaform,$error) = &Apache::loncommon::captcha_display('usercreation',$lonhost);
+            my ($captchaform,$error,$captcha) = &Apache::loncommon::captcha_display('usercreation',$lonhost);
             if ($error) {
                 my $helpdesk = '/adm/helpdesk?origurl=%2fadm%2fcreateaccount';
                 if ($courseid ne '') {
@@ -463,23 +475,24 @@
                                '<a href="'.$helpdesk.'">','</a>','<a href="javascript:window.location.reload()">');
             } else {
                 if (grep(/^login$/,@{$cancreate})) {
-                    $output .= &mt('Provide your e-mail address to request a LON-CAPA account,[_1] if you do not have a log-in ID at your institution.','<br />').'<br /><br />';
-                } else {
-                    $output .= '<br />';
-                }
-                $output .= &mt('Please provide user information and a password for your new account.').'<br />'.
-                           &mt('Your password, which must contain at least seven characters, will be sent to the LON-CAPA server in an encrypted form.').'<br />';
-                if (grep(/^login$/,@{$cancreate})) {
-                    $output .= &mt('Provide your e-mail address to request a LON-CAPA account,[_1] if you do not have a log-in ID at your institution.','<br />').'<br /><br />';
+                    $output .= &mt('If you do not have a log-in ID at your institution, [_1]provide your e-mail address to request a LON-CAPA account.','<br />').'<br /><br />'.
+                               $lt{'plse'}.'<br />'.
+                               $lt{'yopw'}.'<br />';
                 } else {
-                    $output .= '<br />';
-                }
-                $output .= &print_dataentry_form($r,$domain,$lonhost,$include,$now,$captchaform,$courseid,$gotlondes,$emailusername);
-                if (grep(/^login$/,@{$cancreate})) {
-                    $output .= &mt('Provide your e-mail address to request a LON-CAPA account,[_1] if you do not have a log-in ID at your institution.','<br />').'<br /><br />';
-                } else {
-                    $output .= '<br />';
+                    my $prompt = $lt{'plse'};
+                    if (ref($emailusername) eq 'HASH') {
+                        foreach my $key (keys(%{$emailusername})) {
+                            if ($emailusername->{$key}) {
+                                $prompt = $lt{'info'};
+                                last;
+                            }
+                        }
+                    }
+                    $output .= $prompt.'<br />'.
+                               $lt{'yopw'}.'<br />';
                 }
+                $output .= &print_dataentry_form($r,$domain,$lonhost,$include,$now,$captchaform,
+                                                 $courseid,$gotlondes,$emailusername,$captcha);
             }
             $output .= '</div>';
         }
@@ -504,8 +517,8 @@
     my $logtoken=Apache::lonnet::reply('tmpput:'.$ukey.$lkey.'&createaccount:createaccount',
                                        $lonhost);
     $output = &serverform($logtoken,$lonhost,undef,$courseid,$context);
-    my $unameform = '<input type="text" name="uname" size="20" value="" />';
-    my $upassform = '<input type="password" name="upass'.$now.'" size="20" />';
+    my $unameform = '<input type="text" name="uname" size="20" value="" autocomplete="off" />';
+    my $upassform = '<input type="password" name="upass'.$now.'" size="20" autocomplete="off" />';
     $output .= '<form name="client" method="post" action="" onsubmit="return(send('."'server','client'".'));">'."\n".
                &Apache::lonhtmlcommon::start_pick_box()."\n".
                &Apache::lonhtmlcommon::row_title($titles{$context},
@@ -776,7 +789,7 @@
 # Stores token to store DES-key and stage during creation session
 #
 sub print_dataentry_form {
-    my ($r,$domain,$lonhost,$include,$now,$captchaform,$courseid,$gotlondes,$emailusername) = @_;
+    my ($r,$domain,$lonhost,$include,$now,$captchaform,$courseid,$gotlondes,$emailusername,$captcha) = @_;
     my ($error,$output);
     unless ($gotlondes) {
         if (open(my $jsh,"<$include/londes.js")) {
@@ -784,7 +797,7 @@
                 $r->print($line);
             }
             close($jsh);
-            $output = &javascript_setforms($now,$emailusername)."\n";
+            $output = &javascript_setforms($now,$emailusername,$captcha)."\n";
             $gotlondes = 1;
         }
     }
@@ -804,14 +817,23 @@
                 $output .= '<input type="hidden" name="'.$field.'" value="" />'."\n";
             }
         }
+        if ($captcha eq 'original') {
+            $output .= '
+   <input type="hidden" name="crypt" value="" />
+   <input type="hidden" name="code" value="" />
+';
+        } elsif ($captcha eq 'recaptcha') {
+            $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" />
    <input type="hidden" name="serverid" value="$lonhost" />
    <input type="hidden" name="uname" value="" />
    <input type="hidden" name="upass" value="" />
    <input type="hidden" name="udom" value="" />
-   <input type="hidden" name="crypt" value="" />
-   <input type="hidden" name="code" value="" />
    <input type="hidden" name="phase" value="createaccount" />
    <input type="hidden" name="create_with_email" value="1" />
   </form>
@@ -879,6 +901,8 @@
             }
             if (ref($usercreation->{'cancreate'}{'emailusername'}) eq 'HASH') {
                 $emailusername = $usercreation->{'cancreate'}{'emailusername'};
+            } else {
+                $emailusername =  {'lastname' => '1', 'firstname' => 1, };
             }
         }
     }


More information about the LON-CAPA-cvs mailing list