--- loncom/interface/createaccount.pm 2010/12/06 02:39:59 1.37.2.7 +++ loncom/interface/createaccount.pm 2010/02/19 15:41:39 1.38 @@ -3,7 +3,7 @@ # institutional log-in ID (institutional authentication required - localauth # or kerberos) or an e-mail address. # -# $Id: createaccount.pm,v 1.37.2.7 2010/12/06 02:39:59 raeburn Exp $ +# $Id: createaccount.pm,v 1.38 2010/02/19 15:41:39 bisitz Exp $ # # Copyright Michigan State University Board of Trustees # @@ -39,7 +39,7 @@ use Apache::lonhtmlcommon; use Apache::lonlocal; use Apache::lonauth; use Apache::resetpw; -use Captcha::reCAPTCHA; +use Authen::Captcha; use DynaLoader; # for Crypt::DES version use Crypt::DES; use LONCAPA qw(:DEFAULT :match); @@ -140,7 +140,6 @@ sub handler { &Apache::loncommon::start_page($title,$js, {'no_inline_link' => 1,}); - my $inventory = uc($domain); my %domconfig = &Apache::lonnet::get_dom('configuration',['usercreation'],$domain); my ($cancreate,$statustocreate) = &get_creation_controls($domain,$domconfig{'usercreation'}); @@ -148,7 +147,7 @@ sub handler { &print_header($r,$start_page,$courseid); my $output = '

'.&mt('Account creation unavailable').'

'. ''. - &mt('Creation of a new user account using an e-mail address or an institutional log-in ID as username is not permitted for the [_1] WebCenter.',$inventory).'

'; + &mt('Creation of a new user account using an e-mail address or an institutional log-in ID as username is not permitted at this institution ([_1]).',$domdesc).'

'; $r->print($output); &print_footer($r); return OK; @@ -180,7 +179,7 @@ sub handler { if ($token) { ($output,$nostart,$noend) = &process_mailtoken($r,$token,$contact_name,$contact_email,$domain, - $domdesc,$lonhost,$include,$start_page,$inventory); + $domdesc,$lonhost,$include,$start_page); if ($nostart) { if ($noend) { return OK; @@ -227,7 +226,7 @@ sub handler { $output = &process_email_request($env{'form.useremail'},$domain,$domdesc, $contact_name,$contact_email,$cancreate, $lonhost,$domconfig{'usercreation'}, - $courseid,$inventory); + $courseid); } elsif (!$token) { &print_header($r,$start_page,$courseid); my $now=time; @@ -375,13 +374,6 @@ function validate_email() { if (validmail(field) == false) { alert("$lt{'email'}: "+field.value+" $lt{'notv'}."); return false; - } else { - var emailaddr = field.value; - var lcemail = emailaddr.toLowerCase(); - if (emailaddr != lcemail) { - field.value = lcemail; - alert("WebCenter usernames are all lower case.\\nAccordingly your username will be "+lcemail+" once activated."); - } } return true; } @@ -411,7 +403,7 @@ sub print_username_form { } if (grep(/^email$/,@{$cancreate})) { $output .= '

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

'; - my $captchaform = &create_recaptcha(); + my $captchaform = &create_captcha(); if ($captchaform) { my $submit_text = &mt('Request LON-CAPA account'); my $emailform = ''; @@ -428,8 +420,7 @@ sub print_username_form { &Apache::lonhtmlcommon::row_closure(1). &Apache::lonhtmlcommon::row_title(&mt('Validation'), 'LC_pick_box_title')."\n". - $captchaform."\n". - &mt('If either word is hard to read, [_1] will replace them.','reCAPTCHA refresh').'

'; + $captchaform."\n".'

'; if ($courseid ne '') { $output .= ''."\n"; } @@ -476,7 +467,6 @@ sub login_box { my $unameform = ''; my $upassform = ''; $output .= '
'."\n". - ''. &Apache::lonhtmlcommon::start_pick_box()."\n". &Apache::lonhtmlcommon::row_title($titles{$context}, 'LC_pick_box_title')."\n". @@ -485,6 +475,16 @@ sub login_box { &Apache::lonhtmlcommon::row_title(&mt('Password'), 'LC_pick_box_title')."\n". $upassform; + if ($context eq 'selfenroll') { + my $udomform = ''; + $output .= &Apache::lonhtmlcommon::row_closure(1)."\n". + &Apache::lonhtmlcommon::row_title(&mt('Domain'), + 'LC_pick_box_title')."\n". + $udomform."\n"; + } else { + $output .= ''; + } $output .= &Apache::lonhtmlcommon::row_closure(1). &Apache::lonhtmlcommon::row_title(). '
'; if ($error eq 'baduseremail') { - $msg .= &mt('The e-mail address you provided does not appear to be a valid address.'); + $msg = &mt('The e-mail address you provided does not appear to be a valid address.'); } elsif ($error eq 'existinguser') { - my $uname = &HTML::Entities::encode($useremail); - $msg .= &mt('The e-mail address you provided is already in use as a username in LON-CAPA at this institution.').'

'.&mt('You can either:').'
    '. - '
  • '.&mt('Return to the [_1]log-in page[_2] and enter your password.','','').'
  • '. - '
  • '.&mt('or, if you do not remember your password, visit the "[_1]Forgot your password?[_2]" page.','',''). - '
'; + $msg = &mt('The e-mail address you provided is already in use as a username in LON-CAPA at this institution.'); } elsif ($error eq 'userrules') { - $msg .= &mt('Username rules at this institution do not allow the e-mail address you provided to be used as a username.'); + $msg = &mt('Username rules at this institution do not allow the e-mail address you provided to be used as a username.'); } elsif ($error eq 'userformat') { - $msg .= &mt('The e-mail address you provided may not be used as a username at this LON-CAPA institution.'); + $msg = &mt('The e-mail address you provided may not be used as a username at this LON-CAPA institution.'); } elsif ($error eq 'captcha') { - $msg .= &mt('Validation of the code you entered failed.'); + $msg = &mt('Validation of the code your entered failed.'); } elsif ($error eq 'noemails') { - $msg .= &mt('Creation of a new user account using an e-mail address as username is not permitted at this LON-CAPA institution.'); + $msg = &mt('Creation of a new user account using an e-mail address as username is not permitted at this LON-CAPA institution.'); } $msg .= '
'; if ($msgtext) { $msg .= '
'.$msgtext; } - $msg .= &linkto_email_help($contact_email,$domdesc,$error); + $msg .= &linkto_email_help($contact_email,$domdesc); return $msg; } sub linkto_email_help { - my ($contact_email,$domdesc,$error) = @_; + my ($contact_email,$domdesc) = @_; my $msg; if ($contact_email ne '') { my $escuri = &HTML::Entities::encode('/adm/createaccount','&<>"'); - my $href = '/adm/helpdesk?origurl='.$escuri; - if ($error eq 'existinguser') { - my $escemail = &HTML::Entities::encode($env{'form.useremail'}); - $href .= '&useremail='.$escemail.'&useraccount='.$escemail; - } - $msg .= '
'.&mt('You may wish to contact the [_1]LON-CAPA helpdesk[_2] for [_3].','','',$domdesc).'
'; + $msg .= '
'.&mt('You may wish to contact the [_1]LON-CAPA helpdesk[_2] for [_3].','','',$domdesc).'
'; } else { $msg .= '
'.&mt('You may wish to send an e-mail to the server administrator: [_1] for [_2].',$Apache::lonnet::perlvar{'AdminEmail'},$domdesc).'
'; } return $msg; } -sub create_recaptcha { - my $captcha = Captcha::reCAPTCHA->new; - return $captcha->get_options_setter({theme => 'white'})."\n". - $captcha->get_html('PUBLICKEY'); # generate public key for IP - # from http://recaptcha.net/ +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 {