[LON-CAPA-cvs] cvs: loncom /auth switchserver.pm

albertel lon-capa-cvs-allow@mail.lon-capa.org
Sat, 25 Aug 2007 00:52:47 -0000


albertel		Fri Aug 24 20:52:47 2007 EDT

  Modified files:              
    /loncom/auth	switchserver.pm 
  Log:
  - public users it switch ed just need redirecting, not full switchservering
  
  
Index: loncom/auth/switchserver.pm
diff -u loncom/auth/switchserver.pm:1.13 loncom/auth/switchserver.pm:1.14
--- loncom/auth/switchserver.pm:1.13	Fri Mar  2 18:17:48 2007
+++ loncom/auth/switchserver.pm	Fri Aug 24 20:52:47 2007
@@ -1,7 +1,7 @@
 # The LearningOnline Network
 # Switch Servers Handler
 #
-# $Id: switchserver.pm,v 1.13 2007/03/02 23:17:48 albertel Exp $
+# $Id: switchserver.pm,v 1.14 2007/08/25 00:52:47 albertel Exp $
 #
 # Copyright Michigan State University Board of Trustees
 #
@@ -59,6 +59,20 @@
     return $r->dir_config('lonIDsDir')."/$handle.id";
 }
 
+sub do_redirect {
+    my ($r,$url,$only_body,$extra_text) = @_;
+    $r->send_http_header;
+    my $switch='<meta HTTP-EQUIV="Refresh" CONTENT="0; url='.$url.'">';
+    my $start_page = 
+	&Apache::loncommon::start_page('Switching Server ...', $switch,
+				       {'no_inline_link' => 1,
+					'only_body'      => $only_body,});
+    my $end_page   = &Apache::loncommon::end_page();
+    $r->print($start_page.$extra_text.$end_page);
+    return OK;
+
+}
+
 sub handler {
     my ($r) = @_;
     
@@ -76,6 +90,12 @@
 
     if (!defined($switch_to)) { return FORBIDDEN; }
 
+    if ($env{'user.name'} eq 'public'
+	&& $env{'user.domain'} eq 'public') {
+	my $url = 'http://'.$switch_to.'/'.$r->uri;
+	return &do_redirect($r,$url,1)
+    }
+
     if ($env{'form.role'} && 
 	!exists($env{'user.role.'.$env{'form.role'}})) { return FORBIDDEN; }
 
@@ -99,8 +119,9 @@
     return OK if $r->header_only;
 # -------------------------------------------------------- Menu script and info
 	   
-    my $windowinfo=&Apache::lonmenu::close();
-    $windowinfo.=&Apache::lonnavmaps::close();
+    my $windowinfo=
+	&Apache::lonmenu::close().
+	&Apache::lonnavmaps::close();
 # ---------------------------------------------------------------- Get handover
 
     my %info=('ip'       => $ENV{'REMOTE_ADDR'},
@@ -115,16 +136,13 @@
         $info{'sso.reloginserver'} = $env{'request.sso.reloginserver'};
     }
     my $token = &Apache::lonnet::tmpput(\%info,$env{'form.otherserver'});
-    my $switch='<meta HTTP-EQUIV="Refresh" CONTENT="0.5; url=http://'.$switch_to.'/adm/login?domain='.$env{'user.domain'}.'&username='.$env{'user.name'}.'&token='.$token.'">';
-    my $start_page = &Apache::loncommon::start_page('Switching Server ...',
-						    $switch,
-						    {'no_inline_link' => 1,});
-    my $end_page   = &Apache::loncommon::end_page();
+    my $url ='http://'.$switch_to.'/adm/login?'.
+	'domain='.$env{'user.domain'}.
+	'&amp;username='.$env{'user.name'}.
+	'&amp;token='.$token;
 # --------------------------------------------------------------- Screen Output
-    $r->print($start_page.$windowinfo.$end_page);
-
     &Apache::lonnet::flushcourselogs();
-    return OK;
+    return &do_redirect($r,$url,0,$windowinfo);
 }
 
 1;