--- loncom/auth/lonacc.pm 2005/07/07 21:38:35 1.68 +++ loncom/auth/lonacc.pm 2005/12/14 16:50:59 1.71 @@ -1,7 +1,7 @@ # The LearningOnline Network # Cookie Based Access Handler # -# $Id: lonacc.pm,v 1.68 2005/07/07 21:38:35 albertel Exp $ +# $Id: lonacc.pm,v 1.71 2005/12/14 16:50:59 www Exp $ # # Copyright Michigan State University Board of Trustees # @@ -44,10 +44,31 @@ sub handler { my %cookies=CGI::Cookie->parse($r->header_in('Cookie')); my $lonid=$cookies{'lonID'}; my $cookie; + my $lonidsdir=$r->dir_config('lonIDsDir'); + + my $handle; if ($lonid) { - my $handle=$lonid->value; + $handle=$lonid->value; $handle=~s/\W//g; - my $lonidsdir=$r->dir_config('lonIDsDir'); + } + + if ($r->user + && (!$lonid || !-e "$lonidsdir/$handle.id" || $handle eq '') ) { + my $domain = $r->dir_config('lonDefDomain'); + my $home=&Apache::lonnet::homeserver($r->user,$domain); + if ($home !~ /(con_lost|no_such_host)/) { + $handle=&Apache::lonauth::success($r,$r->user,$domain, + $home,'noredirect'); + $r->header_out('Set-cookie',"lonID=$handle; path=/"); + } + } + + if ($r->dir_config("lonBalancer") eq 'yes') { + $r->set_handlers('PerlResponseHandler'=> + [\&Apache::switchserver::handler]); + } + + if ($handle ne '') { if ((-e "$lonidsdir/$handle.id") && ($handle ne '')) { # ------------------------------------------------------ Initialize Environment @@ -95,7 +116,7 @@ sub handler { if ($env{'user.name'} eq 'public' && $env{'user.domain'} eq 'public' && $requrl !~ m{^/+(res|public)/} && - $requrl !~ m{^/+adm/(help|roles|logout|randomlabel\.png)}) { + $requrl !~ m{^/+adm/(help|logout|randomlabel\.png)}) { $env{'request.querystring'}=$r->args; $env{'request.firsturl'}=$requrl; return FORBIDDEN; @@ -167,6 +188,7 @@ sub handler { if ($requrl=~m|^/public/| || (&Apache::lonnet::metadata($requrl,'copyright') eq 'public')) { &Apache::lonnet::logthis('Granting public access: '.$requrl); + &Apache::lonlocal::get_language_handle($r); my $cookie= &Apache::lonauth::success($r,'public','public','public'); my $lonidsdir=$r->dir_config('lonIDsDir');