--- loncom/interface/createaccount.pm 2008/08/22 10:52:56 1.25 +++ loncom/interface/createaccount.pm 2009/04/04 21:47:40 1.34 @@ -3,7 +3,7 @@ # institutional log-in ID (institutional authentication required - localauth # or kerberos) or an e-mail address. # -# $Id: createaccount.pm,v 1.25 2008/08/22 10:52:56 bisitz Exp $ +# $Id: createaccount.pm,v 1.34 2009/04/04 21:47:40 bisitz Exp $ # # Copyright Michigan State University Board of Trustees # @@ -58,10 +58,21 @@ sub handler { my $sso_username = $r->subprocess_env->get('REDIRECT_SSOUserUnknown'); my $sso_domain = $r->subprocess_env->get('REDIRECT_SSOUserDomain'); + &Apache::loncommon::get_unprocessed_cgi($ENV{'QUERY_STRING'},['token','courseid']); + &Apache::lonacc::get_posted_cgi($r); + &Apache::lonlocal::get_language_handle($r); + if ($sso_username ne '' && $sso_domain ne '') { $domain = $sso_domain; - } else { + } else { $domain = &Apache::lonnet::default_login_domain(); + if (defined($env{'form.courseid'})) { + if (&validate_course($env{'form.courseid'})) { + if ($env{'form.courseid'} =~ /^($match_domain)_($match_courseid)$/) { + $domain = $1; + } + } + } } my $domdesc = &Apache::lonnet::domain($domain,'description'); my $contact_name = &mt('LON-CAPA helpdesk'); @@ -74,18 +85,14 @@ sub handler { my $include = $r->dir_config('lonIncludes'); my $start_page; - &Apache::loncommon::get_unprocessed_cgi($ENV{'QUERY_STRING'},['token','courseid']); - &Apache::lonacc::get_posted_cgi($r); - &Apache::lonlocal::get_language_handle($r); - my $handle = &Apache::lonnet::check_for_valid_session($r); - if ($handle ne '') { + if (($handle ne '') && ($handle !~ /^publicuser_\d+$/)) { $start_page = &Apache::loncommon::start_page('Already logged in'); my $end_page = &Apache::loncommon::end_page(); $r->print($start_page."\n".'

'.&mt('You are already logged in').'

'. - '

'.&mt('Please either [_1]continue the current session[_2] or [_3]logout[_4].','','','',''). + '

'.&mt('Please either [_1]continue the current session[_2] or [_3]log out[_4].','','','',''). '

'.&mt('Login problems?').'

'.$end_page); return OK; } @@ -306,9 +313,10 @@ sub validate_course { sub javascript_setforms { my ($now) = @_; my $js = < + ENDSCRIPT @@ -381,7 +389,7 @@ sub print_username_form { my %lt = &Apache::lonlocal::texthash( unam => 'username', udom => 'domain', - uemail => 'Email address in LON-CAPA', + uemail => 'E-mail address in LON-CAPA', proc => 'Proceed'); my $output; if (ref($cancreate) eq 'ARRAY') { @@ -397,34 +405,45 @@ 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::row_title().'
'. + ''. + &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 '') { @@ -447,32 +466,41 @@ sub login_box { my $logtoken=Apache::lonnet::reply('tmpput:'.$ukey.$lkey.'&createaccount', $lonhost); $output = &serverform($logtoken,$lonhost,undef,$courseid,$context); - my $unameform = ''; - my $upassform = ''; - $output .= '
'."\n". - &Apache::lonhtmlcommon::start_pick_box()."\n"; - if ($context eq 'selfenroll') { - my $udomform = ''; - $output .= &Apache::lonhtmlcommon::row_title(&mt('Domain'), - 'LC_pick_box_title')."\n". - $udomform."\n". - &Apache::lonhtmlcommon::row_closure(1)."\n"; - } - - $output .= &Apache::lonhtmlcommon::row_title($titles{$context}, + my $unameform = ''; + my $upassform = ''; + $output .= ''."\n". + &Apache::lonhtmlcommon::start_pick_box()."\n". + &Apache::lonhtmlcommon::row_title($titles{$context}, 'LC_pick_box_title')."\n". $unameform."\n". &Apache::lonhtmlcommon::row_closure(1)."\n". &Apache::lonhtmlcommon::row_title(&mt('Password'), 'LC_pick_box_title')."\n". - $upassform."\n".'

'."\n". - ''."\n". - &Apache::lonhtmlcommon::row_closure(1)."\n". - &Apache::lonhtmlcommon::end_pick_box().'

'."\n". - ''."\n". - ''."\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(). + '
'."\n"; + if ($context eq 'selfenroll') { + $output .= '

'. + ''. + ''.&mt('Forgot password?').''. + '
'."\n"; + } + $output .= &Apache::lonhtmlcommon::row_closure(1)."\n". + &Apache::lonhtmlcommon::end_pick_box().'
'."\n"; + $output .= ''."\n". + ''."\n". '
'; return $output; } @@ -576,10 +604,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') { @@ -699,79 +727,65 @@ sub print_dataentry_form { my ($lextkey,$uextkey) = &getkeys($lkey,$ukey); my $logtoken=Apache::lonnet::reply('tmpput:'.$ukey.$lkey.'&createaccount', $lonhost); - my @userinfo = ('firstname','middlename','lastname','generation','id', - 'permanentemail'); - my %lt=&Apache::lonlocal::texthash( - 'pd' => "Personal Data", - 'firstname' => "First Name", - 'middlename' => "Middle Name", - 'lastname' => "Last Name", - 'generation' => "Generation", - 'permanentemail' => "Permanent e-mail address", - 'id' => "Student/Employee ID", - 'lg' => "Login Data" - ); - my %textboxsize = ( - firstname => '15', - middlename => '15', - lastname => '15', - generation => '5', - id => '15', - ); - my $genhelp=&Apache::loncommon::help_open_topic('Generation'); - $output .= '

'.$lt{'pd'}.'

'. - '
'. - &Apache::lonhtmlcommon::start_pick_box(); - foreach my $item (@userinfo) { - my $rowtitle = $lt{$item}; - if ($item eq 'generation') { - $rowtitle = $genhelp.$rowtitle; - } - $output .= &Apache::lonhtmlcommon::row_title($rowtitle,undef,'LC_oddrow_value')."\n"; - if ($item eq 'permanentemail') { - $output .= $username; - } else { - $output .= ''; - } - $output .= &Apache::lonhtmlcommon::row_closure(1); + my $formtag = ''; + my ($datatable,$rowcount) = + &Apache::loncreateuser::personal_data_display($username,$domain, + 'email','selfcreate'); + if ($rowcount) { + $output .= '
'.$formtag.$datatable; + } else { + $output .= $formtag; } - $output .= &Apache::lonhtmlcommon::end_pick_box(); $output .= <<"ENDSERVERFORM"; + -
+ ENDSERVERFORM + if ($rowcount) { + $output .= '
'. + '
'; + } my $upassone = ''; my $upasstwo = ''; my $submit_text = &mt('Create LON-CAPA account'); - $output .= '

'.$lt{'lg'}.'

'."\n". - '
'."\n". + $output .= '

'.&mt('Login Data').'

'."\n". + ''."\n". &Apache::lonhtmlcommon::start_pick_box()."\n". &Apache::lonhtmlcommon::row_title(&mt('Username'), - 'LC_pick_box_title')."\n". + 'LC_pick_box_title', + 'LC_oddrow_value')."\n". $username."\n". &Apache::lonhtmlcommon::row_closure(1)."\n". &Apache::lonhtmlcommon::row_title(&mt('Password'), - 'LC_pick_box_title')."\n". + 'LC_pick_box_title', + 'LC_oddrow_value')."\n". $upassone."\n". &Apache::lonhtmlcommon::row_closure(1)."\n". &Apache::lonhtmlcommon::row_title(&mt('Confirm password'), - 'LC_pick_box_title')."\n". - $upasstwo."\n". + 'LC_pick_box_title', + 'LC_oddrow_value')."\n". + $upasstwo. + &Apache::lonhtmlcommon::row_closure(1)."\n". + &Apache::lonhtmlcommon::row_title()."\n". + '
'. &Apache::lonhtmlcommon::row_closure(1)."\n". &Apache::lonhtmlcommon::end_pick_box()."\n". - ''."\n". - ''."\n". - ''."\n". - '
'."\n". - ''; + ''."\n". + ''."\n". + ''."\n". + ''."\n". + ''; + if ($rowcount) { + $output .= '
'."\n". + ''."\n"; + } } else { $output = &mt('Could not load javascript file [_1]','londes.js'); } @@ -1115,15 +1129,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; } @@ -1164,6 +1186,7 @@ sub serverform { + $catalog_elements