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

raeburn raeburn@source.lon-capa.org
Wed, 22 Jul 2009 20:24:07 -0000


raeburn		Wed Jul 22 20:24:07 2009 EDT

  Modified files:              
    /loncom/auth	lonlogin.pm lonauth.pm 
  Log:
  - Bug 3987. Deep linking.
  - Include role and symb in query string when calling log-in page.
  - Role is automatically selected and resource is displayed (assuming user actually has the role, and its active, and symb is valid).
  
  
Index: loncom/auth/lonlogin.pm
diff -u loncom/auth/lonlogin.pm:1.122 loncom/auth/lonlogin.pm:1.123
--- loncom/auth/lonlogin.pm:1.122	Fri May 22 17:01:28 2009
+++ loncom/auth/lonlogin.pm	Wed Jul 22 20:24:07 2009
@@ -1,7 +1,7 @@
 # The LearningOnline Network
 # Login Screen
 #
-# $Id: lonlogin.pm,v 1.122 2009/05/22 17:01:28 bisitz Exp $
+# $Id: lonlogin.pm,v 1.123 2009/07/22 20:24:07 raeburn Exp $
 #
 # Copyright Michigan State University Board of Trustees
 #
@@ -46,7 +46,7 @@
 	(join('&',$ENV{'QUERY_STRING'},$env{'request.querystring'},
 	      $ENV{'REDIRECT_QUERY_STRING'}),
 	 ['interface','username','domain','firsturl','localpath','localres',
-	  'token']);
+	  'token','role','symb']);
     if (!defined($env{'form.firsturl'})) {
         &Apache::lonacc::get_posted_cgi($r,['firsturl']);
     }
@@ -170,8 +170,15 @@
     if ($uextkey>2147483647) { $uextkey-=4294967296; }
 
 # -------------------------------------------------------- Store away log token
+    my $tokenextras;
+    if ($env{'form.role'}) {
+        $tokenextras = '&role='.&escape($env{'form.role'});
+    }
+    if ($env{'form.symb'}) {
+        $tokenextras .= '&symb='.&escape($env{'form.symb'});
+    }
     my $logtoken=Apache::lonnet::reply(
-       'tmpput:'.$ukey.$lkey.'&'.$firsturl,
+       'tmpput:'.$ukey.$lkey.'&'.$firsturl.$tokenextras,
        $lonhost);
 
 # ------------------- If we cannot talk to ourselves, we are in serious trouble
Index: loncom/auth/lonauth.pm
diff -u loncom/auth/lonauth.pm:1.99 loncom/auth/lonauth.pm:1.100
--- loncom/auth/lonauth.pm:1.99	Fri Jul  3 10:22:00 2009
+++ loncom/auth/lonauth.pm	Wed Jul 22 20:24:07 2009
@@ -1,7 +1,7 @@
 # The LearningOnline Network
 # User Authentication Module
 #
-# $Id: lonauth.pm,v 1.99 2009/07/03 10:22:00 bisitz Exp $
+# $Id: lonauth.pm,v 1.100 2009/07/22 20:24:07 raeburn Exp $
 #
 # Copyright Michigan State University Board of Trustees
 #
@@ -73,8 +73,44 @@
 # ------------------------------------------------------------ Get cookie ready
     $cookie="lonID=$cookie; path=/";
 # -------------------------------------------------------- Menu script and info
+    my $destination = $lowerurl;
+
+    if (defined($form->{role})) {
+        my $envkey = 'user.role.'.$form->{role};
+        my $now=time;
+        my $then=$env{'user.login.time'};
+        my $refresh=$env{'user.refresh.time'};
+        if (exists($env{$envkey})) {
+            my ($role,$where,$trolecode,$tstart,$tend,$tremark,$tstatus);
+            &Apache::lonnet::role_status($envkey,$then,$refresh,$now,\$role,\$where,
+                                         \$trolecode,\$tstatus,\$tstart,\$tend);
+            if ($tstatus eq 'is') {
+                if ($destination =~ /\?/) {
+                    $destination .= '&';
+                } else {
+                    $destination .= '?';
+                }
+                $destination .= 'selectrole=1&'.$form->{role}.'=1';
+                if (defined($form->{symb})) {
+                    my $destsymb = $form->{symb};
+                    if ($destsymb =~ /___/) {
+                        # FIXME Need to deal with encrypted symbs and urls as needed.
+                        my ($map,$resid,$desturl)=split(/___/,$destsymb);
+                        unless ($desturl=~/^(adm|uploaded|editupload|public)/) {
+                            $desturl = &Apache::lonnet::clutter($desturl);
+                        }
+                        $destination .= '&destinationurl='.$desturl.
+                                        '&destsymb='.$destsymb;
+                    } else {
+                        $destination .= '&destinationurl='.$destsymb;
+                    }
+                }
+            }
+        }
+    }
+
     my $windowinfo=&Apache::lonmenu::open($env{'browser.os'});
-    my $startupremote=&Apache::lonmenu::startupremote($lowerurl);
+    my $startupremote=&Apache::lonmenu::startupremote($destination);
     my $remoteinfo=&Apache::lonmenu::load_remote_msg($lowerurl);
     my $setflags=&Apache::lonmenu::setflags();
     my $maincall=&Apache::lonmenu::maincall();
@@ -88,7 +124,7 @@
 
     my $continuelink;
     if ($env{'environment.remote'} eq 'off') {
-	$continuelink="<a href=\"$lowerurl\">".&mt('Continue')."</a>";
+	$continuelink='<a href="'.$destination.'">'.&mt('Continue').'</a>';
     }
 # ------------------------------------------------- Output for successful login
 
@@ -122,6 +158,14 @@
     my ($r,$message,$form) = @_;
     my $start_page = &Apache::loncommon::start_page('Unsuccessful Login',undef,
 						    {'no_inline_link' => 1,});
+    my $retry = '/adm/login?username='.$form->{'uname'}.
+                '&domain='.$form->{'udom'};
+    if (exists($form->{role})) {
+        $retry .= '&role='.$form->{role};
+    }
+    if (exists($form->{symb})) {
+        $retry .= '&symb='.$form->{symb};
+    }
     my $end_page   = &Apache::loncommon::end_page();
     &Apache::loncommon::content_type($r,'text/html');
     $r->send_http_header;
@@ -129,8 +173,7 @@
        $start_page
       .'<h1>'.&mt('Sorry ...').'</h1>'
       .'<p class="LC_warning">'.&mt($message).'</p>'
-      .'<p>'.&mt('Please [_1]log in again[_2].'
-                ,"<a href=\"/adm/login?username=$form->{'uname'}&domain=$form->{'udom'}\">",'</a>')
+      .'<p>'.&mt('Please [_1]log in again[_2].','<a href="'.$retry.'">','</a>')
       .'</p>'
       .'<p><a href="/adm/loginproblems.html">'.&mt('Login problems?').'</a></p>'
       .$end_page
@@ -233,11 +276,25 @@
 	    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 ($key,$firsturl,$rolestr,$symbstr)=split(/&/,$tmpinfo);
+    if ($rolestr) {
+        $rolestr = &unescape($rolestr);
+    }
+    if ($symbstr) {
+        $symbstr= &unescape($symbstr);
+    }
+    if ($rolestr =~ /^role=/) {
+        (undef,$form{'role'}) = split('=',$rolestr);
+    }
+    if ($symbstr =~ /^symb=/) { 
+        (undef,$form{'symb'}) = split('=',$symbstr);
+    }
 
     my $keybin=pack("H16",$key);