--- loncom/auth/lonauth.pm 2007/07/25 22:35:47 1.88 +++ loncom/auth/lonauth.pm 2008/05/14 18:27:30 1.91 @@ -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.91 2008/05/14 18:27:30 raeburn 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; @@ -170,21 +170,16 @@ 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(<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 @@ -193,8 +188,7 @@ $start_page Problems?

$end_page ENDFAILED - return OK; - } + return OK; } # ---------------------------------------------------- No valid token, continue @@ -270,9 +264,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 +289,32 @@ 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 ($output,$checkfail) = &Apache::createaccount::username_check($form{'uname'}, + $form{'udom'},$domdesc); + &Apache::loncommon::content_type($r,'text/html'); + $r->send_http_header; + &Apache::createaccount::print_header($r,$start_page); + my $msg = '

'.&mt('Although your username and password were authenticated, you do not currently have a LON-CAPA account in this domain.').'
'; + if ($checkfail) { + $msg .= &mt('A LON-CAPA account may not be created with the username you used.'); + } else { + $msg .= &mt('To create one, use the table below to provide information about yourself (if appropriate), then click the "Create LON-CAPA account" button.'); + } + $r->print('

'.$msg.'

'.$output); + $r->print(&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 '') ||