--- loncom/interface/createaccount.pm 2009/03/12 14:13:34 1.31 +++ loncom/interface/createaccount.pm 2010/08/20 04:01:47 1.37.6.1 @@ -3,7 +3,7 @@ # institutional log-in ID (institutional authentication required - localauth # or kerberos) or an e-mail address. # -# $Id: createaccount.pm,v 1.31 2009/03/12 14:13:34 bisitz Exp $ +# $Id: createaccount.pm,v 1.37.6.1 2010/08/20 04:01:47 raeburn Exp $ # # Copyright Michigan State University Board of Trustees # @@ -92,7 +92,7 @@ sub handler { 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; } @@ -112,10 +112,16 @@ sub handler { if ($env{'form.udom'} ne '') { $domain = $env{'form.udom'}; } + + my %domconfig = + &Apache::lonnet::get_dom('configuration',['usercreation'],$domain); + my ($cancreate,$statustocreate) = + &get_creation_controls($domain,$domconfig{'usercreation'}); + my ($result,$output) = &username_validation($r,$env{'form.uname'},$domain,$domdesc, $contact_name,$contact_email,$courseid, - $lonhost); + $lonhost,$statustocreate); if ($result eq 'existingaccount') { $r->print($output); &print_footer($r); @@ -133,20 +139,11 @@ sub handler { $start_page = &Apache::loncommon::start_page($title,$js, {'no_inline_link' => 1,}); - my @cancreate; - my %domconfig = &Apache::lonnet::get_dom('configuration',['usercreation'],$domain); - if (ref($domconfig{'usercreation'}) eq 'HASH') { - if (ref($domconfig{'usercreation'}{'cancreate'}) eq 'HASH') { - if (ref($domconfig{'usercreation'}{'cancreate'}{'selfcreate'}) eq 'ARRAY') { - @cancreate = @{$domconfig{'usercreation'}{'cancreate'}{'selfcreate'}}; - } elsif (($domconfig{'usercreation'}{'cancreate'}{'selfcreate'} ne 'none') && - ($domconfig{'usercreation'}{'cancreate'}{'selfcreate'} ne '')) { - @cancreate = ($domconfig{'usercreation'}{'cancreate'}{'selfcreate'}); - } - } - } - if (@cancreate == 0) { + my %domconfig = + &Apache::lonnet::get_dom('configuration',['usercreation'],$domain); + my ($cancreate,$statustocreate) = &get_creation_controls($domain,$domconfig{'usercreation'}); + if (@{$cancreate} == 0) { &print_header($r,$start_page,$courseid); my $output = '

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

'. ''. @@ -160,12 +157,13 @@ sub handler { &print_header($r,$start_page,$courseid); my ($msg,$sso_logout); $sso_logout = &sso_logout_frag($r,$domain); - if (grep(/^sso$/,@cancreate)) { + if (grep(/^sso$/,@{$cancreate})) { $msg = '

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

'. &mt("Although your username and password were authenticated by your institution's Single Sign On system, you do not currently have a LON-CAPA account at this institution.").'
'; $msg .= &username_check($sso_username,$domain,$domdesc,$courseid, - $lonhost,$contact_email,$contact_name,$sso_logout); + $lonhost,$contact_email,$contact_name, + $sso_logout,$statustocreate); } else { $msg = '

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

'. ''.&mt("Although your username and password were authenticated by your institution's Single Sign On system, you do not currently have a LON-CAPA account at this institution, and you are not permitted to create one.").'

'.&mt('Please contact the [_1] ([_2]) for assistance.',$contact_name,$contact_email).'
'. @@ -215,7 +213,7 @@ sub handler { (my $result,$output) = &username_validation($r,$env{'form.uname'},$domain,$domdesc, $contact_name,$contact_email,$courseid, - $lonhost); + $lonhost,$statustocreate); if ($result eq 'existingaccount') { $r->print($output); &print_footer($r); @@ -226,21 +224,21 @@ sub handler { } elsif ($env{'form.create_with_email'}) { &print_header($r,$start_page,$courseid); $output = &process_email_request($env{'form.useremail'},$domain,$domdesc, - $contact_name,$contact_email,\@cancreate, + $contact_name,$contact_email,$cancreate, $lonhost,$domconfig{'usercreation'}, $courseid); } elsif (!$token) { &print_header($r,$start_page,$courseid); my $now=time; - if (grep(/^login$/,@cancreate)) { + if (grep(/^login$/,@{$cancreate})) { my $jsh=Apache::File->new($include."/londes.js"); $r->print(<$jsh>); $r->print(&javascript_setforms($now)); } - if (grep(/^email$/,@cancreate)) { + if (grep(/^email$/,@{$cancreate})) { $r->print(&javascript_validmail()); } - $output = &print_username_form($domain,$domdesc,\@cancreate,$now,$lonhost, + $output = &print_username_form($domain,$domdesc,$cancreate,$now,$lonhost, $courseid); } $r->print($output); @@ -280,7 +278,7 @@ sub selfenroll_crumbs { my ($r,$courseid,$desc) = @_; &Apache::lonhtmlcommon::add_breadcrumb ({href=>"javascript:ToCatalog('backupcrumbs','')", - text=>"Course Catalog"}); + text=>"Course/Community Catalog"}); if ($env{'form.coursenum'} ne '') { &Apache::lonhtmlcommon::add_breadcrumb ({href=>"javascript:ToCatalog('backupcrumbs','details')", @@ -313,9 +311,10 @@ sub validate_course { sub javascript_setforms { my ($now) = @_; my $js = < + ENDSCRIPT @@ -425,7 +424,9 @@ sub print_username_form { if ($courseid ne '') { $output .= ''."\n"; } - $output .= ''. &Apache::lonhtmlcommon::row_closure(1). &Apache::lonhtmlcommon::end_pick_box().'

'; @@ -463,11 +464,11 @@ 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"; - $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". @@ -475,25 +476,29 @@ sub login_box { '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(0). + $output .= &Apache::lonhtmlcommon::row_closure(1). &Apache::lonhtmlcommon::row_title(). - ''."\n". - &Apache::lonhtmlcommon::row_closure(1)."\n". - &Apache::lonhtmlcommon::end_pick_box(); - $output .= '

'. - ''.&mt('Forgot password?').''. - '

'."\n"; - $output .= ''."\n". - ''."\n". + '
'."\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; } @@ -542,7 +547,7 @@ sub process_email_request { if ($uhome eq 'no_host') { my (%rulematch,%inst_results,%curr_rules,%got_rules,%alerts); &call_rulecheck($useremail,$domain,\%alerts,\%rulematch, - \%inst_results,\%curr_rules,%got_rules,'username'); + \%inst_results,\%curr_rules,\%got_rules,'username'); if (ref($alerts{'username'}) eq 'HASH') { if (ref($alerts{'username'}{$domain}) eq 'HASH') { if ($alerts{'username'}{$domain}{$useremail}) { @@ -720,85 +725,97 @@ 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'); } return $output; } +sub get_creation_controls { + my ($domain,$usercreation) = @_; + my (@cancreate,@statustocreate); + if (ref($usercreation) eq 'HASH') { + if (ref($usercreation->{'cancreate'}) eq 'HASH') { + if (ref($usercreation->{'cancreate'}{'statustocreate'}) eq 'ARRAY') { + @statustocreate = @{$usercreation->{'cancreate'}{'statustocreate'}}; + } else { + @statustocreate = ('default'); + my ($othertitle,$usertypes,$types) = + &Apache::loncommon::sorted_inst_types($domain); + if (ref($types) eq 'ARRAY') { + push(@statustocreate,@{$types}); + } + } + if (ref($usercreation->{'cancreate'}{'selfcreate'}) eq 'ARRAY') { + @cancreate = @{$usercreation->{'cancreate'}{'selfcreate'}}; + } elsif (($usercreation->{'cancreate'}{'selfcreate'} ne 'none') && + ($usercreation->{'cancreate'}{'selfcreate'} ne '')) { + @cancreate = ($usercreation->{'cancreate'}{'selfcreate'}); + } + } + } + return (\@cancreate,\@statustocreate); +} + sub create_account { my ($r,$domain,$lonhost,$username,$domdesc) = @_; my ($retrieved,$output,$upass) = &process_credentials($env{'form.logtoken'}, @@ -836,7 +853,7 @@ sub create_account { sub username_validation { my ($r,$username,$domain,$domdesc,$contact_name,$contact_email,$courseid, - $lonhost) = @_; + $lonhost,$statustocreate) = @_; my ($retrieved,$output,$upass); $username= &LONCAPA::clean_username($username); @@ -870,7 +887,8 @@ sub username_validation { } if ($authok eq 'authorized') { $output = &username_check($username,$domain,$domdesc,$courseid,$lonhost, - $contact_email,$contact_name); + $contact_email,$contact_name,undef, + $statustocreate); } else { $output = &login_failure_msg($courseid); } @@ -895,12 +913,12 @@ sub login_failure_msg { } sub username_check { - my ($username,$domain,$domdesc,$courseid,$lonhost,$contact_email,$contact_name, - $sso_logout) = @_; + my ($username,$domain,$domdesc,$courseid,$lonhost,$contact_email, + $contact_name,$sso_logout,$statustocreate) = @_; my (%rulematch,%inst_results,$checkfail,$rowcount,$editable,$output,$msg, %alerts,%curr_rules,%got_rules); &call_rulecheck($username,$domain,\%alerts,\%rulematch, - \%inst_results,\%curr_rules,%got_rules,'username'); + \%inst_results,\%curr_rules,\%got_rules,'username'); if (ref($alerts{'username'}) eq 'HASH') { if (ref($alerts{'username'}{$domain}) eq 'HASH') { if ($alerts{'username'}{$domain}{$username}) { @@ -916,6 +934,21 @@ sub username_check { } } if (!$checkfail) { + if (ref($statustocreate) eq 'ARRAY') { + $checkfail = 'inststatus'; + if (ref($inst_results{$username.':'.$domain}{inststatus}) eq 'ARRAY') { + foreach my $inststatus (@{$inst_results{$username.':'.$domain}{inststatus}}) { + if (grep(/^\Q$inststatus\E$/,@{$statustocreate})) { + undef($checkfail); + last; + } + } + } elsif (grep(/^default$/,@{$statustocreate})) { + undef($checkfail); + } + } + } + if (!$checkfail) { $output = '
'; (my $datatable,$rowcount,$editable) = &Apache::loncreateuser::personal_data_display($username,$domain,1,'selfcreate', @@ -950,6 +983,10 @@ sub username_check { } elsif ($checkfail eq 'authtoken') { $msg .= ''.&mt('Error creating token.').''. '
'.$output; + } elsif ($checkfail eq 'inststatus') { + $msg .= ''. + &mt('You are not permitted to create a LON-CAPA account.'). + '

'.$output; } $msg .= &mt('Please contact the [_1] ([_2]) for assistance.', $contact_name,$contact_email).'

'. @@ -1028,7 +1065,7 @@ sub username_activation { # Call modifyuser my (%rulematch,%inst_results,%curr_rules,%got_rules,%alerts,%info); &call_rulecheck($username,$domain,\%alerts,\%rulematch, - \%inst_results,\%curr_rules,%got_rules); + \%inst_results,\%curr_rules,\%got_rules); my @userinfo = ('firstname','middlename','lastname','generation', 'permanentemail','id'); my %canmodify = @@ -1149,7 +1186,7 @@ sub create_captcha { $output = ''."\n". &mt('Type in the letters/numbers shown below').' '. '
'. - ''; + ''; last; } } @@ -1193,6 +1230,7 @@ sub serverform { + $catalog_elements