--- loncom/interface/loncreateuser.pm 2002/03/22 22:23:23 1.28 +++ loncom/interface/loncreateuser.pm 2002/04/04 21:46:44 1.29 @@ -1,7 +1,7 @@ # The LearningOnline Network with CAPA # Create a user # -# $Id: loncreateuser.pm,v 1.28 2002/03/22 22:23:23 matthew Exp $ +# $Id: loncreateuser.pm,v 1.29 2002/04/04 21:46:44 matthew Exp $ # # Copyright Michigan State University Board of Trustees # @@ -47,7 +47,7 @@ # 11/12,11/13,11/15 Scott Harrison # 02/11/02 Matthew Hall # -# $Id: loncreateuser.pm,v 1.28 2002/03/22 22:23:23 matthew Exp $ +# $Id: loncreateuser.pm,v 1.29 2002/04/04 21:46:44 matthew Exp $ ### package Apache::loncreateuser; @@ -260,12 +260,11 @@ ENDDOCHEAD - - ENDFORMINFO my $uhome=&Apache::lonnet::homeserver($ccuname,$ccdomain); my %incdomains; my %inccourses; + my %home_servers = &get_home_servers($ccdomain); foreach (%Apache::lonnet::hostdom) { $incdomains{$_}=1; } @@ -275,6 +274,13 @@ ENDFORMINFO } } if ($uhome eq 'no_host') { + my $home_server_list= + ''."\n"; + foreach (sort keys(%home_servers)) { + $home_server_list.= + '\n"; + } $r->print(<Create New User @@ -295,6 +301,7 @@ $loginscript ID/Student Number

+Home Server:

Login Data

$generalrule @@ -570,6 +577,8 @@ ENDDROW # ================================================================= Phase Three sub phase_three { my $r=shift; + my $uhome=&Apache::lonnet::homeserver($ENV{'form.ccuname'}, + $ENV{'form.ccdomain'}); # Error messages my $error = 'Error:'; my $end = ''; @@ -583,26 +592,35 @@ sub phase_three { ENDTHREEHEAD # Check Inputs - if (! $ENV{'form.cuname'} ) { + if (! $ENV{'form.ccuname'} ) { $r->print($error.'No login name specified.'.$end); return; } - if ( $ENV{'form.cuname'} =~/\W/) { + if ( $ENV{'form.ccuname'} =~/\W/) { $r->print($error.'Invalid login name. '. 'Only letters, numbers, and underscores are valid.'. $end); return; } - if (! $ENV{'form.cdomain'} ) { + if (! $ENV{'form.ccdomain'} ) { $r->print($error.'No domain specified.'.$end); return; } - if ( $ENV{'form.cdomain'} =~/\W/) { + if ( $ENV{'form.ccdomain'} =~/\W/) { $r->print($error.'Invalid domain name. '. 'Only letters, numbers, and underscores are valid.'. $end); return; } + if (! exists($ENV{'form.makeuser'})) { + # Modifying an existing user, so check the validity of the name + if ($uhome eq 'no_host') { + $r->print($error.'Unable to determine home server for '. + $ENV{'form.ccuname'}.' in domain '. + $ENV{'form.ccdomain'}.'.'); + return; + } + } # Determine authentication method and password for the user being modified my $amode=''; my $genpwd=''; @@ -624,28 +642,41 @@ ENDTHREEHEAD # Create a new user $r->print(<Create User -

Creating user "$ENV{'form.cuname'}" in domain "$ENV{'form.cdomain'}"

+

Creating user "$ENV{'form.ccuname'}" in domain "$ENV{'form.ccdomain'}"

ENDNEWUSERHEAD # Check for the authentication mode and password if (! $amode || ! $genpwd) { $r->print($error.'Invalid login mode or password'.$end); return; } + # Determine desired host + my $desiredhost = $ENV{'form.hserver'}; + if (lc($desiredhost) eq 'default') { + $desiredhost = undef; + } else { + my %home_servers = &get_home_servers($ENV{'form.ccdomain'}); + if (! exists($home_servers{$desiredhost})) { + $r->print($error.'Invalid home server specified'); + return; + } + } # Call modifyuser my $result = &Apache::lonnet::modifyuser - ($ENV{'form.cdomain'},$ENV{'form.cuname'}, - $ENV{'form.cstid'},$amode,$genpwd, - $ENV{'form.cfirst'},$ENV{'form.cmiddle'}, - $ENV{'form.clast'},$ENV{'form.cgen'} + ($ENV{'form.ccdomain'},$ENV{'form.ccuname'},$ENV{'form.cstid'}, + $amode,$genpwd,$ENV{'form.cfirst'}, + $ENV{'form.cmiddle'},$ENV{'form.clast'},$ENV{'form.cgen'}, + undef,$desiredhost ); $r->print('Generating user: '.$result); - $r->print('
Home server: '.&Apache::lonnet::homeserver - ($ENV{'form.cuname'},$ENV{'form.cdomain'})); + my $home = &Apache::lonnet::homeserver($ENV{'form.ccuname'}, + $ENV{'form.ccdomain'}); + $r->print('
Home server: '.$home.' '. + $Apache::lonnet::libserv{$home}); } elsif ($ENV{'form.login'} ne '') { # Modify user privileges $r->print(<Change User Privileges -

User "$ENV{'form.cuname'}" in domain "$ENV{'form.cdomain'}"

+

User "$ENV{'form.ccuname'}" in domain "$ENV{'form.ccdomain'}"

ENDMODIFYUSERHEAD if (! $amode || ! $genpwd) { $r->print($error.'Invalid login mode or password'.$end); @@ -655,10 +686,10 @@ ENDMODIFYUSERHEAD if (&Apache::lonnet::allowed('mau',$ENV{'user.domain'})) { $r->print('Modifying authentication: '. &Apache::lonnet::modifyuserauth( - $ENV{'form.cdomain'},$ENV{'form.cuname'}, + $ENV{'form.ccdomain'},$ENV{'form.ccuname'}, $amode,$genpwd)); $r->print('
Home server: '.&Apache::lonnet::homeserver - ($ENV{'form.cuname'},$ENV{'form.cdomain'})); + ($ENV{'form.ccuname'},$ENV{'form.ccdomain'})); } else { # Okay, this is a non-fatal error. $r->print($error.'You do not have the authority to modify '. @@ -670,7 +701,7 @@ ENDMODIFYUSERHEAD # Check for need to change my %userenv = &Apache::lonnet::get ('environment',['firstname','middlename','lastname','generation'], - $ENV{'form.cdomain'},$ENV{'form.cuname'}); + $ENV{'form.ccdomain'},$ENV{'form.ccuname'}); my ($tmp) = keys(%userenv); if ($tmp =~ /^(con_lost|error)/i) { %userenv = (); @@ -680,7 +711,7 @@ ENDMODIFYUSERHEAD # Strip leading and trailing whitespace $ENV{'form.c'.$_} =~ s/(\s+$|^\s+)//g; } - if (&Apache::lonnet::allowed('mau',$ENV{'form.cdomain'}) && + if (&Apache::lonnet::allowed('mau',$ENV{'form.ccdomain'}) && ($ENV{'form.cfirstname'} ne $userenv{'firstname'} || $ENV{'form.cmiddlename'} ne $userenv{'middlename'} || $ENV{'form.clastname'} ne $userenv{'lastname'} || @@ -693,7 +724,7 @@ ENDMODIFYUSERHEAD $changeHash{'generation'} = $ENV{'form.cgeneration'}; my $putresult = &Apache::lonnet::put ('environment',\%changeHash, - $ENV{'form.cdomain'},$ENV{'form.cuname'}); + $ENV{'form.ccdomain'},$ENV{'form.ccuname'}); if ($putresult eq 'ok') { # Tell the user we changed the name $r->print(<<"END"); @@ -718,14 +749,14 @@ ENDMODIFYUSERHEAD END } else { # error occurred $r->print("

Unable to successfully change environment for ". - $ENV{'form.cuname'}." in domain ". - $ENV{'form.cdomain'}."

"); + $ENV{'form.ccuname'}." in domain ". + $ENV{'form.ccdomain'}.""); } } else { # End of if ($ENV ... ) logic # They did not want to change the users name but we can # still tell them what the name is $r->print(<<"END"); -

User "$ENV{'form.cuname'}" in domain "$ENV{'form.cdomain'}"

+

User "$ENV{'form.ccuname'}" in domain "$ENV{'form.ccdomain'}"

$userenv{'firstname'} $userenv{'middlename'} $userenv{'lastname'}

Generation: $userenv{'generation'}

END @@ -740,8 +771,8 @@ END if ($_=~/^form\.rev/) { if ($_=~/^form\.rev\:([^\_]+)\_([^\_]+)$/) { $r->print('Revoking '.$2.' in '.$1.': '. - &Apache::lonnet::assignrole($ENV{'form.cdomain'}, - $ENV{'form.cuname'},$1,$2,$now).'
'); + &Apache::lonnet::assignrole($ENV{'form.ccdomain'}, + $ENV{'form.ccuname'},$1,$2,$now).'
'); if ($2 eq 'st') { $1=~/^\/(\w+)\/(\w+)/; my $cid=$1.'_'.$2; @@ -749,8 +780,8 @@ END &Apache::lonnet::critical('put:'. $ENV{'course.'.$cid.'.domain'}.':'. $ENV{'course.'.$cid.'.num'}.':classlist:'. - &Apache::lonnet::escape($ENV{'form.cuname'}.':'. - $ENV{'form.cdomain'}).'='. + &Apache::lonnet::escape($ENV{'form.ccuname'}.':'. + $ENV{'form.ccdomain'}).'='. &Apache::lonnet::escape($now.':'), $ENV{'course.'.$cid.'.home'}).'
'); } @@ -772,7 +803,7 @@ END # Assign the role and report it $r->print('Assigning: '.$3.' in '.$url.': '. &Apache::lonnet::assignrole( - $ENV{'form.cdomain'},$ENV{'form.cuname'}, + $ENV{'form.ccdomain'},$ENV{'form.ccuname'}, $url,$3,$end,$start). '
'); # Handle students differently @@ -784,8 +815,8 @@ END 'put:'.$ENV{'course.'.$cid.'.domain'}.':'. $ENV{'course.'.$cid.'.num'}.':classlist:'. &Apache::lonnet::escape( - $ENV{'form.cuname'}.':'. - $ENV{'form.cdomain'} ).'='. + $ENV{'form.ccuname'}.':'. + $ENV{'form.ccdomain'} ).'='. &Apache::lonnet::escape($end.':'.$start), $ENV{'course.'.$cid.'.home'}) .'
'); @@ -803,7 +834,7 @@ END # Assign the role and report it. $r->print('Assigning: '.$2.' in '.$url.': '. &Apache::lonnet::assignrole( - $ENV{'form.cdomain'},$ENV{'form.cuname'}, + $ENV{'form.ccdomain'},$ENV{'form.ccuname'}, $url,$2,$end,$start) .'
'); } @@ -902,6 +933,20 @@ ENDTABLE } #---------------------------------------------- end functions for &phase_two +#--------------------------------- functions for &phase_two and &phase_three +sub get_home_servers { + my $domain = shift; + my %home_servers; + foreach (keys(%Apache::lonnet::libserv)) { + if ($Apache::lonnet::hostdom{$_} eq $domain) { + $home_servers{$_} = $Apache::lonnet::hostname{$_}; + } + } + return %home_servers; +} + +#--------------------------end of functions for &phase_two and &phase_three + 1; __END__