--- loncom/auth/lonauth.pm 2011/06/11 17:50:35 1.114 +++ loncom/auth/lonauth.pm 2011/06/12 14:18:09 1.115 @@ -1,7 +1,7 @@ # The LearningOnline Network # User Authentication Module # -# $Id: lonauth.pm,v 1.114 2011/06/11 17:50:35 raeburn Exp $ +# $Id: lonauth.pm,v 1.115 2011/06/12 14:18:09 raeburn Exp $ # # Copyright Michigan State University Board of Trustees # @@ -415,17 +415,32 @@ sub handler { } } - unless (&check_can_host($r,\%form,$authhost)) { - return OK; - } - if ($r->dir_config("lonBalancer") eq 'yes') { - &success($r,$form{'uname'},$form{'udom'},$authhost,'noredirect',undef, - \%form); my $otherserver = &Apache::lonnet::spareserver(30000,undef,1,$form{'udom'}); - $r->internal_redirect('/adm/switchserver?otherserver='.$otherserver.'&origurl='.$firsturl); + if (!$otherserver) { + $otherserver = &Apache::lonnet::choose_server($form{'udom'}); + } + if ($otherserver) { + &success($r,$form{'uname'},$form{'udom'},$authhost,'noredirect',undef, + \%form); + $r->internal_redirect('/adm/switchserver?otherserver='.$otherserver.'&origurl='.$firsturl); + } else { + $r->print(&noswitch()); + } return OK; } else { + if (!&check_can_host($r,\%form,$authhost)) { + my $otherserver = &Apache::lonnet::choose_server($form{'udom'}); + if ($otherserver) { + &success($r,$form{'uname'},$form{'udom'},$authhost,'noredirect',undef, + \%form); + $r->internal_redirect('/adm/switchserver?otherserver='.$otherserver.'&origurl='.$firsturl); + } else { + $r->print(&noswitch()); + } + return OK; + } + # ------------------------------------------------------- Do the load balancing # ---------------------------------------------------------- Determine own load @@ -442,6 +457,9 @@ sub handler { # ---------------------------------------------------------- Are we overloaded? if ((($userloadpercent>100.0)||($loadpercent>100.0))) { my $unloaded=Apache::lonnet::spareserver($loadpercent,$userloadpercent,1,$form{'udom'}); + if (!$unloaded) { + $unloaded = &Apache::lonnet::choose_server($form{'udom'}); + } if ($unloaded) { &success($r,$form{'uname'},$form{'udom'},$authhost,'noredirect', undef,\%form); @@ -487,7 +505,9 @@ sub check_can_host { } unless ($canhost) { if ($authhost eq 'no_account_on_host') { - my ($login_host,$hostname) = &Apache::lonnet::choose_server($udom); + my $checkloginvia = 1; + my ($login_host,$hostname) = + &Apache::lonnet::choose_server($udom,$checkloginvia); &Apache::loncommon::content_type($r,'text/html'); $r->send_http_header; if ($login_host ne '') { @@ -517,6 +537,15 @@ sub check_can_host { return $canhost; } +sub noswitch { + my $result = &Apache::loncommon::start_page('Access to LON-CAPA unavailable'). + '
'.&mt('Currently no other LON-CAPA server is available to host your session either.').'
'. + &Apache::loncommon::end_page(); + return $result; +} + 1; __END__