--- loncom/auth/lonauth.pm 2007/07/25 22:35:47 1.88 +++ loncom/auth/lonauth.pm 2009/07/03 10:22:00 1.99 @@ -1,7 +1,7 @@ # The LearningOnline Network # User Authentication Module # -# $Id: lonauth.pm,v 1.88 2007/07/25 22:35:47 albertel Exp $ +# $Id: lonauth.pm,v 1.99 2009/07/03 10:22:00 bisitz Exp $ # # Copyright Michigan State University Board of Trustees # @@ -32,12 +32,12 @@ use strict; use LONCAPA; use Apache::Constants qw(:common); use CGI qw(:standard); -use CGI::Cookie(); use DynaLoader; # for Crypt::DES version use Crypt::DES; use Apache::loncommon(); use Apache::lonnet; use Apache::lonmenu(); +use Apache::createaccount; use Fcntl qw(:flock); use Apache::lonlocal; @@ -78,14 +78,16 @@ sub success { 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')) { + if ($env{'environment.remote'} eq 'off') { $continuelink="".&mt('Continue').""; } # ------------------------------------------------- Output for successful login @@ -96,8 +98,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 @@ -121,29 +123,19 @@ sub failed { my $start_page = &Apache::loncommon::start_page('Unsuccessful Login',undef, {'no_inline_link' => 1,}); 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].' + ,"{'uname'}&domain=$form->{'udom'}\">",'') + .'

' + .'

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

' + .$end_page + ); + } # ------------------------------------------------------------------ Rerouting! @@ -151,8 +143,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); } @@ -170,31 +162,25 @@ sub handler { &Apache::lonlocal::get_language_handle($r); # -------------------------------- Prevent users from attempting to login twice - my %cookies=CGI::Cookie->parse($r->header_in('Cookie')); - my $lonid=$cookies{'lonID'}; - my $cookie; - if ($lonid) { - my $handle=&LONCAPA::clean_handle($lonid->value); - my $lonidsdir=$r->dir_config('lonIDsDir'); - if ((-e "$lonidsdir/$handle.id") && ($handle ne '')) { + my $handle = &Apache::lonnet::check_for_valid_session($r); + if ($handle ne '') { # 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(<You are already logged in -

Please either continue the current session or -logout.

-

-Problems?

-$end_page -ENDFAILED - return OK; - } + &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; } # ---------------------------------------------------- No valid token, continue @@ -228,6 +214,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 @@ -246,6 +233,10 @@ ENDFAILED 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 $keybin=pack("H16",$key); @@ -270,9 +261,24 @@ ENDFAILED } # ---------------------------------------------------------------- Authenticate - my $authhost=Apache::lonnet::authenticate($form{'uname'}, - $upass, - $form{'udom'}); + 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 (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 (grep(/^login$/,@cancreate)) { + $defaultauth = 1; + } + my $authhost=Apache::lonnet::authenticate($form{'uname'},$upass, + $form{'udom'},$defaultauth); # --------------------------------------------------------------------- Failed? @@ -280,6 +286,34 @@ ENDFAILED &failed($r,'Username and/or password could not be authenticated.', \%form); return OK; + } elsif ($authhost eq 'no_account_on_host') { + my %domconfig = + &Apache::lonnet::get_dom('configuration',['usercreation'],$form{'udom'}); + 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 $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('

'.&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); + return OK; + } } if (($firsturl eq '') ||