--- loncom/auth/lonauth.pm 2009/07/03 10:22:00 1.99 +++ loncom/auth/lonauth.pm 2010/03/17 17:51:06 1.103 @@ -1,7 +1,7 @@ # The LearningOnline Network # User Authentication Module # -# $Id: lonauth.pm,v 1.99 2009/07/03 10:22:00 bisitz Exp $ +# $Id: lonauth.pm,v 1.103 2010/03/17 17:51:06 raeburn Exp $ # # Copyright Michigan State University Board of Trustees # @@ -40,6 +40,7 @@ use Apache::lonmenu(); use Apache::createaccount; use Fcntl qw(:flock); use Apache::lonlocal; +use HTML::Entities; # ------------------------------------------------------------ Successful login sub success { @@ -73,23 +74,54 @@ sub success { # ------------------------------------------------------------ Get cookie ready $cookie="lonID=$cookie; path=/"; # -------------------------------------------------------- Menu script and info - my $windowinfo=&Apache::lonmenu::open($env{'browser.os'}); - my $startupremote=&Apache::lonmenu::startupremote($lowerurl); - my $remoteinfo=&Apache::lonmenu::load_remote_msg($lowerurl); - my $setflags=&Apache::lonmenu::setflags(); - my $maincall=&Apache::lonmenu::maincall(); + my $destination = $lowerurl; + + if (defined($form->{role})) { + my $envkey = 'user.role.'.$form->{role}; + my $now=time; + my $then=$env{'user.login.time'}; + my $refresh=$env{'user.refresh.time'}; + if (exists($env{$envkey})) { + my ($role,$where,$trolecode,$tstart,$tend,$tremark,$tstatus); + &Apache::lonnet::role_status($envkey,$then,$refresh,$now,\$role,\$where, + \$trolecode,\$tstatus,\$tstart,\$tend); + if ($tstatus eq 'is') { + $destination .= ($destination =~ /\?/) ? '&' : '?'; + my $newrole = &HTML::Entities::encode($form->{role},'"<>&'); + $destination .= 'selectrole=1&'.$newrole.'=1'; + } + } + } + if (defined($form->{symb})) { + my $destsymb = $form->{symb}; + $destination .= ($destination =~ /\?/) ? '&' : '?'; + if ($destsymb =~ /___/) { + # FIXME Need to deal with encrypted symbs and urls as needed. + my ($map,$resid,$desturl)=split(/___/,$destsymb); + unless ($desturl=~/^(adm|uploaded|editupload|public)/) { + $desturl = &Apache::lonnet::clutter($desturl); + } + $desturl = &HTML::Entities::encode($desturl,'"<>&'); + $destsymb = &HTML::Entities::encode($destsymb,'"<>&'); + $destination .= '&destinationurl='.$desturl. + '&destsymb='.$destsymb; + } else { + $destsymb = &HTML::Entities::encode($destsymb,'"<>&'); + $destination .= '&destinationurl='.$destsymb; + } + } + + my $windowinfo = Apache::lonhtmlcommon::scripttag('self.name="loncapaclient";'); + my $header = ''; my $brcrum = [{'href' => '', 'text' => 'Successful Login'},]; my $start_page=&Apache::loncommon::start_page('Successful Login', - $startupremote, + $header, {'no_inline_link' => 1, 'bread_crumbs' => $brcrum,}); my $end_page =&Apache::loncommon::end_page(); - my $continuelink; - if ($env{'environment.remote'} eq 'off') { - $continuelink="".&mt('Continue').""; - } + my $continuelink=''.&mt('Continue').''; # ------------------------------------------------- Output for successful login &Apache::loncommon::content_type($r,'text/html'); @@ -104,13 +136,10 @@ sub success { ); $r->print(<$lt{'wel'} $lt{'mes'}

$lt{'pro'}

-$remoteinfo -$maincall $continuelink $end_page ENDSUCCESS @@ -122,6 +151,14 @@ sub failed { my ($r,$message,$form) = @_; my $start_page = &Apache::loncommon::start_page('Unsuccessful Login',undef, {'no_inline_link' => 1,}); + my $retry = '/adm/login?username='.$form->{'uname'}. + '&domain='.$form->{'udom'}; + if (exists($form->{role})) { + $retry .= '&role='.$form->{role}; + } + if (exists($form->{symb})) { + $retry .= '&symb='.$form->{symb}; + } my $end_page = &Apache::loncommon::end_page(); &Apache::loncommon::content_type($r,'text/html'); $r->send_http_header; @@ -129,8 +166,7 @@ sub failed { $start_page .'

'.&mt('Sorry ...').'

' .'

'.&mt($message).'

' - .'

'.&mt('Please [_1]log in again[_2].' - ,"{'uname'}&domain=$form->{'udom'}\">",'') + .'

'.&mt('Please [_1]log in again[_2].','','') .'

' .'

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

' .$end_page @@ -164,23 +200,29 @@ sub handler { # -------------------------------- Prevent users from attempting to login twice my $handle = &Apache::lonnet::check_for_valid_session($r); if ($handle ne '') { + my $lonidsdir=$r->dir_config('lonIDsDir'); + if ($handle=~/^publicuser\_/) { +# For "public user" - remove it, we apparently really want to login + unlink($r->dir_config('lonIDsDir')."/$handle.id"); + } else { # Indeed, a valid token is found - &Apache::loncommon::content_type($r,'text/html'); - $r->send_http_header; - my $start_page = - &Apache::loncommon::start_page('Already logged in'); - my $end_page = - &Apache::loncommon::end_page(); - $r->print( - $start_page - .'

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

' - .'

'.&mt('Please either [_1]continue the current session[_2] or [_3]log out[_4].' + &Apache::lonnet::transfer_profile_to_env($lonidsdir,$handle); + &Apache::loncommon::content_type($r,'text/html'); + $r->send_http_header; + my $start_page = + &Apache::loncommon::start_page('Already logged in'); + my $end_page = + &Apache::loncommon::end_page(); + $r->print( + $start_page + .'

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

' + .'

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

' - .'

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

' - .$end_page - ); - return OK; + .'

' + .$end_page + ); + return OK; + } } # ---------------------------------------------------- No valid token, continue @@ -233,11 +275,25 @@ sub handler { return OK; } } + if (!&Apache::lonnet::domain($form{'udom'})) { &failed($r,'The domain you provided is not a valid LON-CAPA domain.',\%form); return OK; } - my ($key,$firsturl)=split(/&/,$tmpinfo); + + my ($key,$firsturl,$rolestr,$symbstr)=split(/&/,$tmpinfo); + if ($rolestr) { + $rolestr = &unescape($rolestr); + } + if ($symbstr) { + $symbstr= &unescape($symbstr); + } + if ($rolestr =~ /^role=/) { + (undef,$form{'role'}) = split('=',$rolestr); + } + if ($symbstr =~ /^symb=/) { + (undef,$form{'symb'}) = split('=',$symbstr); + } my $keybin=pack("H16",$key);