--- loncom/interface/createaccount.pm 2012/05/18 04:31:05 1.51 +++ loncom/interface/createaccount.pm 2012/08/25 04:34:44 1.52 @@ -3,7 +3,7 @@ # institutional log-in ID (institutional authentication required - localauth # or kerberos) or an e-mail address. # -# $Id: createaccount.pm,v 1.51 2012/05/18 04:31:05 raeburn Exp $ +# $Id: createaccount.pm,v 1.52 2012/08/25 04:34:44 raeburn Exp $ # # Copyright Michigan State University Board of Trustees # @@ -382,8 +382,14 @@ sub print_username_form { } if (grep(/^email$/,@{$cancreate})) { $output .= '

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

'; - my $captchaform = &create_captcha(); - if ($captchaform) { + my ($captchaform,$error) = &Apache::loncommon::captcha_display('usercreation',$lonhost); + if ($error) { + 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.','','',''); + } else { my $submit_text = &mt('Request LON-CAPA account'); my $emailform = ''; if (grep(/^login$/,@{$cancreate})) { @@ -394,12 +400,14 @@ sub print_username_form { $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".'

'; + 'LC_pick_box_title')."\n". + $emailform."\n"; + if ($captchaform) { + $output .= &Apache::lonhtmlcommon::row_closure(1). + &Apache::lonhtmlcommon::row_title(&mt('Validation'), + 'LC_pick_box_title')."\n". + $captchaform."\n".'

'; + } if ($courseid ne '') { $output .= ''."\n"; } @@ -413,12 +421,6 @@ sub print_username_form { $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 .= '
'; } @@ -503,23 +505,10 @@ sub process_email_request { $contact_name,$contact_email); return $output; } else { - my $code = $env{'form.code'}; - my $md5sum = $env{'form.crypt'}; - my %captcha_params = &captcha_settings(); - my $captcha = Authen::Captcha->new( - output_folder => $captcha_params{'output_dir'}, - data_folder => $captcha_params{'db_dir'}, - ); - my $captcha_chk = $captcha->check_code($code,$md5sum); - my %captcha_hash = ( - 0 => 'Code not checked (file error)', - -1 => 'Failed: code expired', - -2 => 'Failed: invalid code (not in database)', - -3 => 'Failed: invalid code (code does not match crypt)', - ); + my ($captcha_chk,$captcha_error) = &Apache::loncommon::captcha_response('usercreation',$server); if ($captcha_chk != 1) { $output = &invalid_state('captcha',$domdesc,$contact_name, - $contact_email,$captcha_hash{$captcha_chk}); + $contact_email,$captcha_error); return $output; } my $uhome=&Apache::lonnet::homeserver($useremail,$domain); @@ -1185,39 +1174,6 @@ sub linkto_email_help { return $msg; } -sub create_captcha { - my ($output_dir,$db_dir) = @_; - my %captcha_params = &captcha_settings(); - 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; -} - -sub captcha_settings { - my %captcha_params = ( - output_dir => $Apache::lonnet::perlvar{'lonCaptchaDir'}, - www_output_dir => "/captchaspool", - db_dir => $Apache::lonnet::perlvar{'lonCaptchaDb'}, - numchars => '5', - ); - return %captcha_params; -} - sub getkeys { my ($lkey,$ukey) = @_; my $lextkey=hex($lkey);