--- loncom/interface/createaccount.pm 2009/01/14 13:13:59 1.27 +++ loncom/interface/createaccount.pm 2009/02/07 00:59:17 1.28 @@ -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 @@ sub print_username_form { } if (grep(/^email$/,@{$cancreate})) { $output .= '

'.&mt('Create account with an e-mail address as your username').'

'; - 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.','
').'

'; - } else { - $output .= '
'; - } - my $emailform = ''; my $captchaform = &create_captcha(); - my $submit_text = &mt('Request LON-CAPA account'); - $output .= '
'. - &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".'

'; - if ($courseid ne '') { - $output .= ''."\n"; - } - $output .= ''. - &Apache::lonhtmlcommon::row_closure(1). - &Apache::lonhtmlcommon::end_pick_box().'

'; - if ($courseid ne '') { - $output .= &Apache::lonhtmlcommon::echo_form_input(['courseid']); + if ($captchaform) { + my $submit_text = &mt('Request LON-CAPA account'); + my $emailform = ''; + 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.','
').'

'; + } else { + $output .= '
'; + } + $output .= ''. + &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".'

'; + if ($courseid ne '') { + $output .= ''."\n"; + } + $output .= ''. + &Apache::lonhtmlcommon::row_closure(1). + &Apache::lonhtmlcommon::end_pick_box().'

'; + if ($courseid ne '') { + $output .= &Apache::lonhtmlcommon::echo_form_input(['courseid']); + } + $output .= '
'; + } else { + my $helpdesk = '/adm/helpdesk?origurl=%2fadm%2fcreateaccount'; + if ($courseid ne '') { + $helpdesk .= '&courseid='.$courseid; + } + $output .= ''.&mt('An error occurred generating the validation code[_1] required for an e-mail address to be used as username.','
').'


'.&mt('[_1]Contact the helpdesk[_2] or [_3]reload[_2] the page and try again.','','',''); } - $output .= '
'; + $output .= ''; } } if ($output eq '') { @@ -583,10 +592,10 @@ sub send_token { 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 linkto_email_help { 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 = ''."\n". - &mt('Type in the letters/numbers shown below').' '. - '
'. - ''; + 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 = ''."\n". + &mt('Type in the letters/numbers shown below').' '. + '
'. + ''; + last; + } + } return $output; }