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

raeburn raeburn@source.lon-capa.org
Sat, 07 Feb 2009 00:59:17 -0000


This is a MIME encoded message

--raeburn1233968357
Content-Type: text/plain

raeburn		Sat Feb  7 00:59:17 2009 EDT

  Modified files:              
    /loncom/interface	createaccount.pm 
  Log:
  Bug 5877.
   - Occasionally Authen::Captcha fails to generate an image.
   - In &create_captcha() loop the Authen::Captcha->new() call until an image is generated, or 10 attempts have been made.
   - Display an error message if no success after 10 attempts.
  
  
--raeburn1233968357
Content-Type: text/plain
Content-Disposition: attachment; filename="raeburn-20090207005917.txt"

Index: loncom/interface/createaccount.pm
diff -u loncom/interface/createaccount.pm:1.27 loncom/interface/createaccount.pm:1.28
--- loncom/interface/createaccount.pm:1.27	Wed Jan 14 13:13:59 2009
+++ loncom/interface/createaccount.pm	Sat Feb  7 00:59:17 2009
@@ -3,7 +3,7 @@
 # institutional log-in ID (institutional authentication required - localauth
 #  or kerberos) or an e-mail address.
 #
-# $Id: createaccount.pm,v 1.27 2009/01/14 13:13:59 raeburn Exp $
+# $Id: createaccount.pm,v 1.28 2009/02/07 00:59:17 raeburn Exp $
 #
 # Copyright Michigan State University Board of Trustees
 #
@@ -404,34 +404,43 @@
         }
         if (grep(/^email$/,@{$cancreate})) {
             $output .= '<div class="LC_left_float"><h3>'.&mt('Create account with an e-mail address as your username').'</h3>';
-            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 $emailform = '<input type="text" name="useremail" size="25" value="" />';
             my $captchaform = &create_captcha();
-            my $submit_text = &mt('Request LON-CAPA account');
-            $output .=  '<form name="createaccount" method="post" onSubmit="return validate_email()" action="/adm/createaccount">'.
-                        &Apache::lonhtmlcommon::start_pick_box()."\n".
-                        &Apache::lonhtmlcommon::row_title(&mt('E-mail address'),
-                                                         'LC_pick_box_title')."\n".
-                        $emailform."\n".
-                        &Apache::lonhtmlcommon::row_closure(1).
-                        &Apache::lonhtmlcommon::row_title(&mt('Validation'),
-                                                         'LC_pick_box_title')."\n".
-                        $captchaform."\n".'<br /><br />';
-            if ($courseid ne '') {
-                $output .= '<input type="hidden" name="courseid" value="'.$courseid.'"/>'."\n"; 
-            }
-            $output .= '<input type="submit" name="create_with_email" value="'. 
-                        $submit_text.'" />'.
-                        &Apache::lonhtmlcommon::row_closure(1).
-                        &Apache::lonhtmlcommon::end_pick_box().'<br /><br />';
-            if ($courseid ne '') {
-                $output .= &Apache::lonhtmlcommon::echo_form_input(['courseid']);
+            if ($captchaform) {
+                my $submit_text = &mt('Request LON-CAPA account');
+                my $emailform = '<input type="text" name="useremail" size="25" value="" />';
+                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 .=  '<form name="createaccount" method="post" onSubmit="return validate_email()" action="/adm/createaccount">'.
+                            &Apache::lonhtmlcommon::start_pick_box()."\n".
+                            &Apache::lonhtmlcommon::row_title(&mt('E-mail address'),
+                                                             'LC_pick_box_title')."\n".
+                            $emailform."\n".
+                            &Apache::lonhtmlcommon::row_closure(1).
+                            &Apache::lonhtmlcommon::row_title(&mt('Validation'),
+                                                             'LC_pick_box_title')."\n".
+                            $captchaform."\n".'<br /><br />';
+                if ($courseid ne '') {
+                    $output .= '<input type="hidden" name="courseid" value="'.$courseid.'"/>'."\n"; 
+                }
+                $output .= '<input type="submit" name="create_with_email" value="'. 
+                            $submit_text.'" />'.
+                            &Apache::lonhtmlcommon::row_closure(1).
+                            &Apache::lonhtmlcommon::end_pick_box().'<br /><br />';
+                if ($courseid ne '') {
+                    $output .= &Apache::lonhtmlcommon::echo_form_input(['courseid']);
+                }
+                $output .= '</form>';
+            } else {
+                my $helpdesk = '/adm/helpdesk?origurl=%2fadm%2fcreateaccount';
+                if ($courseid ne '') {
+                    $helpdesk .= '&courseid='.$courseid;
+                }
+                $output .= '<span class="LC_error">'.&mt('An error occurred generating the validation code[_1] required for an e-mail address to be used as username.','<br />').'</span><br /><br />'.&mt('[_1]Contact the helpdesk[_2] or [_3]reload[_2] the page and try again.','<a href="'.$helpdesk.'">','</a>','<a href="javascript:window.location.reload()">');
             }
-            $output .= '</form></div>';
+            $output .= '</div>';
         }
     }
     if ($output eq '') {
@@ -583,10 +592,10 @@
     my $token = &Apache::lonnet::tmpput(\%info,$server);
     if ($token !~ /^error/ && $token ne 'no_such_host') {
         my $esc_token = &escape($token);
-        my $mailmsg = &mt('A request was submitted on [_1] for creation of a LON-CAPA account at the following institution: [_2].',localtime(time),$domdesc).' '.
-             &mt('To complete this process please open a web browser and enter the following'
-                .' URL in the address/location box: [_1]'
-                ,&Apache::lonnet::absolute_url().'/adm/createaccount?token='.$esc_token);
+        my $showtime = localtime(time);
+        my $mailmsg = &mt('A request was submitted on [_1] for creation of a LON-CAPA account at the following institution: [_2].',$showtime,$domdesc).' '.
+             &mt('To complete this process please open a web browser and enter the following URL in the address/location box: [_1]',
+                 &Apache::lonnet::absolute_url().'/adm/createaccount?token='.$esc_token);
         my $result = &Apache::resetpw::send_mail($domdesc,$email,$mailmsg,$contact_name,
                                                  $contact_email);
         if ($result eq 'ok') {
@@ -1122,15 +1131,23 @@
 sub create_captcha {
     my ($output_dir,$db_dir) = @_;
     my %captcha_params = &captcha_settings();
-    my $captcha = Authen::Captcha->new(
-                                       output_folder => $captcha_params{'output_dir'},
-                                       data_folder   => $captcha_params{'db_dir'},
-                                      );
-    my $md5sum = $captcha->generate_code($captcha_params{'numchars'});
-    my $output = '<input type="hidden" name="crypt" value="'.$md5sum.'" />'."\n".
-                 &mt('Type in the letters/numbers shown below').'&nbsp;'.
-                 '<input type="text" size="5" name="code" value="" /><br />'.
-                 '<img src="'.$captcha_params{'www_output_dir'}.'/'.$md5sum.'.png">';
+    my ($output,$maxtries,$tries) = ('',10,0);
+    while ($tries < $maxtries) {
+        $tries ++;
+        my $captcha = Authen::Captcha->new (
+                                           output_folder => $captcha_params{'output_dir'},
+                                           data_folder   => $captcha_params{'db_dir'},
+                                          );
+        my $md5sum = $captcha->generate_code($captcha_params{'numchars'});
+
+        if (-e $Apache::lonnet::perlvar{'lonCaptchaDir'}.'/'.$md5sum.'.png') {
+            $output = '<input type="hidden" name="crypt" value="'.$md5sum.'" />'."\n".
+                      &mt('Type in the letters/numbers shown below').'&nbsp;'.
+                     '<input type="text" size="5" name="code" value="" /><br />'.
+                     '<img src="'.$captcha_params{'www_output_dir'}.'/'.$md5sum.'.png">';
+            last;
+        }
+    }
     return $output;
 }
 

--raeburn1233968357--