--- loncom/auth/lonauth.pm 2008/03/24 05:23:10 1.90 +++ loncom/auth/lonauth.pm 2009/07/22 20:24:07 1.100 @@ -1,7 +1,7 @@ # The LearningOnline Network # User Authentication Module # -# $Id: lonauth.pm,v 1.90 2008/03/24 05:23:10 raeburn Exp $ +# $Id: lonauth.pm,v 1.100 2009/07/22 20:24:07 raeburn Exp $ # # Copyright Michigan State University Board of Trustees # @@ -73,20 +73,58 @@ sub success { # ------------------------------------------------------------ Get cookie ready $cookie="lonID=$cookie; path=/"; # -------------------------------------------------------- Menu script and info + 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') { + if ($destination =~ /\?/) { + $destination .= '&'; + } else { + $destination .= '?'; + } + $destination .= 'selectrole=1&'.$form->{role}.'=1'; + if (defined($form->{symb})) { + my $destsymb = $form->{symb}; + 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); + } + $destination .= '&destinationurl='.$desturl. + '&destsymb='.$destsymb; + } else { + $destination .= '&destinationurl='.$destsymb; + } + } + } + } + } + my $windowinfo=&Apache::lonmenu::open($env{'browser.os'}); - my $startupremote=&Apache::lonmenu::startupremote($lowerurl); + my $startupremote=&Apache::lonmenu::startupremote($destination); my $remoteinfo=&Apache::lonmenu::load_remote_msg($lowerurl); my $setflags=&Apache::lonmenu::setflags(); my $maincall=&Apache::lonmenu::maincall(); + my $brcrum = [{'href' => '', + 'text' => 'Successful Login'},]; my $start_page=&Apache::loncommon::start_page('Successful Login', - $startupremote, - {'no_inline_link' => 1,}); + $startupremote, + {'no_inline_link' => 1, + 'bread_crumbs' => $brcrum,}); my $end_page =&Apache::loncommon::end_page(); my $continuelink; - if (($env{'browser.interface'} eq 'textual') || - ($env{'environment.remote'} eq 'off')) { - $continuelink="".&mt('Continue').""; + if ($env{'environment.remote'} eq 'off') { + $continuelink=''.&mt('Continue').''; } # ------------------------------------------------- Output for successful login @@ -96,8 +134,8 @@ sub success { my %lt=&Apache::lonlocal::texthash( 'wel' => 'Welcome', - 'mes' => 'Welcome to the LearningOnline Network with CAPA. Please wait while your session is being set up', - 'pro' => 'Problems', + 'mes' => 'Welcome to the LearningOnline Network with CAPA. Please wait while your session is being set up.', + 'pro' => 'Login problems?', 'log' => 'loginproblems.html', ); $r->print(<$lt{'wel'} -$lt{'mes'}.

-$lt{'pro'}?

+$lt{'mes'}

+$lt{'pro'}

$remoteinfo $maincall $continuelink @@ -120,30 +158,27 @@ 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(); - - $message = &mt($message); - my %lt=('sorry' => &mt('Sorry ...'), - 'please' => - &mt('Please [_1]log in again[_2].', - "{'uname'}&domain=$form->{'udom'}\">", - ''), - 'problemspage' => &mt('loginproblems.html'), - 'problems' => 'Problems', - ); &Apache::loncommon::content_type($r,'text/html'); $r->send_http_header; - - $r->print(<$lt{'sorry'} -

$message

-

$lt{'please'}

-

-$lt{'problems'}

-$end_page -ENDFAILED -} + $r->print( + $start_page + .'

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

' + .'

'.&mt($message).'

' + .'

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

' + .'

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

' + .$end_page + ); + } # ------------------------------------------------------------------ Rerouting! @@ -151,8 +186,8 @@ sub reroute { my ($r) = @_; &Apache::loncommon::content_type($r,'text/html'); $r->send_http_header; - my $msg='

Sorry ...

- Please log in again.'; + my $msg='

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

' + .&mt('Please [_1]log in again[_2].'); &Apache::loncommon::simple_error_page($r,'Rerouting',$msg); } @@ -179,16 +214,16 @@ sub handler { &Apache::loncommon::start_page('Already logged in'); my $end_page = &Apache::loncommon::end_page(); - $r->print(<You are already logged in -

Please either continue the current session or -logout.

-

-Problems?

-$end_page -ENDFAILED - return OK; + $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; } # ---------------------------------------------------- No valid token, continue @@ -222,6 +257,7 @@ ENDFAILED my $role = $r->dir_config('lonRole'); my $domain = $r->dir_config('lonDefDomain'); my $prodir = $r->dir_config('lonUsersDir'); + my $contact_name = &mt('LON-CAPA helpdesk'); # ---------------------------------------- Get the information from login token @@ -240,7 +276,25 @@ ENDFAILED return OK; } } - my ($key,$firsturl)=split(/&/,$tmpinfo); + + 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,$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); @@ -264,17 +318,20 @@ ENDFAILED } # ---------------------------------------------------------------- Authenticate - my $cancreate; + my @cancreate; my %domconfig = &Apache::lonnet::get_dom('configuration',['usercreation'],$form{'udom'}); if (ref($domconfig{'usercreation'}) eq 'HASH') { if (ref($domconfig{'usercreation'}{'cancreate'}) eq 'HASH') { - if ($domconfig{'usercreation'}{'cancreate'}{'selfcreate'} ne 'none') { - $cancreate = $domconfig{'usercreation'}{'cancreate'}{'selfcreate'}; + 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'}); } } } my $defaultauth; - if ($cancreate eq 'any' || $cancreate eq 'login') { + if (grep(/^login$/,@cancreate)) { $defaultauth = 1; } my $authhost=Apache::lonnet::authenticate($form{'uname'},$upass, @@ -287,28 +344,28 @@ ENDFAILED \%form); return OK; } elsif ($authhost eq 'no_account_on_host') { - my $cancreate; my %domconfig = &Apache::lonnet::get_dom('configuration',['usercreation'],$form{'udom'}); - if (ref($domconfig{'usercreation'}) eq 'HASH') { - if (ref($domconfig{'usercreation'}{'cancreate'}) eq 'HASH') { - if ($domconfig{'usercreation'}{'cancreate'}{'selfcreate'} ne 'none') { - $cancreate = $domconfig{'usercreation'}{'cancreate'}{'selfcreate'}; - } - } - } - if ($cancreate eq 'any' || $cancreate eq 'login') { + if (grep(/^login$/,@cancreate)) { my $start_page = &Apache::loncommon::start_page('Create a user account in LON-CAPA', '',{'no_inline_link' => 1,}); my $domdesc = &Apache::lonnet::domain($form{'udom'},'description'); - my $output = &Apache::createaccount::username_check($form{'uname'}, - $form{'udom'},$domdesc); + my $lonhost = $r->dir_config('lonHostID'); + my $origmail = $Apache::lonnet::perlvar{'lonSupportEMail'}; + my $contacts = + &Apache::loncommon::build_recipient_list(undef,'helpdeskmail', + $form{'udom'},$origmail); + my ($contact_email) = split(',',$contacts); + my $output = &Apache::createaccount::username_check($form{'uname'}, + $form{'udom'},$domdesc,'', + $lonhost,$contact_email,$contact_name); &Apache::loncommon::content_type($r,'text/html'); $r->send_http_header; &Apache::createaccount::print_header($r,$start_page); - $r->print($output); - $r->print(&Apache::loncommon::end_page()); + $r->print('

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

'. + &mt('Although your username and password were authenticated, you do not currently have a LON-CAPA account at this institution.').'
'. + $output.&Apache::loncommon::end_page()); return OK; } else { &failed($r,'Although your username and password were authenticated, you do not currently have a LON-CAPA account in this domain, and you are not permitted to create one.',\%form);