[LON-CAPA-cvs] cvs: loncom /auth lonlogin.pm /lonnet/perl lonnet.pm

raeburn raeburn at source.lon-capa.org
Sun Sep 24 20:36:36 EDT 2017


raeburn		Mon Sep 25 00:36:36 2017 EDT

  Modified files:              
    /loncom/auth	lonlogin.pm 
    /loncom/lonnet/perl	lonnet.pm 
  Log:
  - When browser sends a LON-CAPA cookie for an expired session, redirect user
    to portal URL for user's domain for re-authentication. 
  
  
Index: loncom/auth/lonlogin.pm
diff -u loncom/auth/lonlogin.pm:1.170 loncom/auth/lonlogin.pm:1.171
--- loncom/auth/lonlogin.pm:1.170	Sat Feb 25 19:56:09 2017
+++ loncom/auth/lonlogin.pm	Mon Sep 25 00:36:30 2017
@@ -1,7 +1,7 @@
 # The LearningOnline Network
 # Login Screen
 #
-# $Id: lonlogin.pm,v 1.170 2017/02/25 19:56:09 raeburn Exp $
+# $Id: lonlogin.pm,v 1.171 2017/09/25 00:36:30 raeburn Exp $
 #
 # Copyright Michigan State University Board of Trustees
 #
@@ -58,15 +58,16 @@
     }
 
 # For "public user" - remove any exising "public" cookie, as user really wants to log-in
-    my ($handle,$lonidsdir,$expire);
+    my ($handle,$lonidsdir,$expirepub,$userdom);
     unless ($r->header_only) {
-        $handle = &Apache::lonnet::check_for_valid_session($r);
+        $handle = &Apache::lonnet::check_for_valid_session($r,'lonID',undef,\$userdom);
         if ($handle ne '') {
             $lonidsdir=$r->dir_config('lonIDsDir');
             if ($handle=~/^publicuser\_/) {
                 unlink($r->dir_config('lonIDsDir')."/$handle.id");
                 undef($handle);
-                $expire = 1;
+                undef($userdom);
+                $expirepub = 1;
             }
         }
     }
@@ -74,11 +75,16 @@
     &Apache::loncommon::no_cache($r);
     &Apache::lonlocal::get_language_handle($r);
     &Apache::loncommon::content_type($r,'text/html');
-    if ($expire) {
+    if ($expirepub) {
         my $c = new CGI::Cookie(-name    => 'lonPubID',
                                 -value   => '',
                                 -expires => '-10y',);
         $r->header_out('Set-cookie' => $c);
+    } elsif (($handle eq '') && ($userdom ne '')) {
+        my $c = new CGI::Cookie(-name    => 'lonID',
+                                -value   => '',
+                                -expires => '-10y',);
+        $r->headers_out->add('Set-cookie' => $c);
     }
     $r->send_http_header;
     return OK if $r->header_only;
@@ -91,6 +97,23 @@
 	return OK;
     }
 
+#
+# If browser sent an old cookie for which the session file had been removed
+# check if configuration for user's domain has a portal URL set.  If so
+# switch user's log-in to the portal.
+#
+
+    if (($handle eq '') && ($userdom ne '')) {
+        my %domdefaults = &Apache::lonnet::get_domain_defaults($userdom);
+        if ($domdefaults{'portal_def'} =~ /^https?\:/) {
+            my $start_page = &Apache::loncommon::start_page('Switching Server ...',undef,
+                                          {'redirect' => [0,$domdefaults{'portal_def'}],});
+            my $end_page   = &Apache::loncommon::end_page();
+            $r->print($start_page.$end_page);
+            return OK;
+        }
+    }
+
     $env{'form.firsturl'} =~ s/(`)/'/g;
 
 # -------------------------------- Prevent users from attempting to login twice
Index: loncom/lonnet/perl/lonnet.pm
diff -u loncom/lonnet/perl/lonnet.pm:1.1354 loncom/lonnet/perl/lonnet.pm:1.1355
--- loncom/lonnet/perl/lonnet.pm:1.1354	Sun Aug 27 17:49:49 2017
+++ loncom/lonnet/perl/lonnet.pm	Mon Sep 25 00:36:35 2017
@@ -1,7 +1,7 @@
 # The LearningOnline Network
 # TCP networking package
 #
-# $Id: lonnet.pm,v 1.1354 2017/08/27 17:49:49 raeburn Exp $
+# $Id: lonnet.pm,v 1.1355 2017/09/25 00:36:35 raeburn Exp $
 #
 # Copyright Michigan State University Board of Trustees
 #
@@ -650,7 +650,7 @@
 
 # ---------------------------------------------------- Check for valid session 
 sub check_for_valid_session {
-    my ($r,$name,$userhashref) = @_;
+    my ($r,$name,$userhashref,$domref) = @_;
     my %cookies=CGI::Cookie->parse($r->header_in('Cookie'));
     my ($linkname,$pubname);
     if ($name eq '') {
@@ -678,7 +678,16 @@
     } else {
         $lonidsdir=$r->dir_config('lonIDsDir');
     }
-    return undef if (!-e "$lonidsdir/$handle.id");
+    if (!-e "$lonidsdir/$handle.id") {
+        if ((ref($domref)) && ($name eq 'lonID') && 
+            ($handle =~ /^($match_username)\_\d+\_($match_domain)\_(.+)$/)) {
+            my ($possuname,$possudom,$possuhome) = ($1,$2,$3);
+            if ((&domain($possudom) ne '') && (&homeserver($possuname,$possudom) eq $possuhome)) {
+                $$domref = $possudom;
+            }
+        }
+        return undef;
+    }
 
     my $opened = open(my $idf,'+<',"$lonidsdir/$handle.id");
     return undef if (!$opened);




More information about the LON-CAPA-cvs mailing list