[LON-CAPA-cvs] cvs: modules /raeburn/register Session.pm

raeburn lon-capa-cvs@mail.lon-capa.org
Wed, 21 Mar 2007 22:35:52 -0000


raeburn		Wed Mar 21 18:35:52 2007 EDT

  Modified files:              
    /modules/raeburn/register	Session.pm 
  Log:
  url stored in cookie will be overwritten if user wants to register for a different event or, as an administrator, wants to view registration data.
  Use registration.css    
  
  
Index: modules/raeburn/register/Session.pm
diff -u modules/raeburn/register/Session.pm:1.5 modules/raeburn/register/Session.pm:1.6
--- modules/raeburn/register/Session.pm:1.5	Fri Feb  3 21:43:45 2006
+++ modules/raeburn/register/Session.pm	Wed Mar 21 18:35:50 2007
@@ -40,6 +40,7 @@
 
     my $cookie;                       # cookie to send to client
     my $dbpwd;                        # get db credentials
+    my $failflag;
     my $authkeydir = "/home/helpdesk/admindata";
     my $authkeyfile = $authkeydir.'/mysql.dat';
     if (open (my $fh, "<$authkeyfile") ) {
@@ -65,7 +66,6 @@
   # Try to get the authentication cookie.
     my %headers = $r->headers_in;
     my %cookiejar = CGI::Cookie->parse($r->header_in('Cookie'));
-
     unless($cookiejar{$auth_name}) {
         &note_cookie_auth_failure($r);
         $dbh->disconnect;
@@ -74,8 +74,27 @@
   
     my %auth_cookie = $cookiejar{$auth_name}->value;
     my $sess_id = $auth_cookie{session};
-    $r->notes->set('_COOKIESTUFF' => $auth_name);
+    my $newuri;
+    if ($inbound =~ /^\/(register|registrations)/) {
+        my %query_str;
+        my ($newuri,$caller);
+        &Apache::LON::processform::getitems($r->args,\%query_str);
+        my @params = sort (keys(%query_str));
+        if (@params) {
+            for (my $i=0; $i<@params; $i++) {
+                if ($i==0) {
+                    $caller .= '?';
+                } else {
+                    $caller .=  '&';
+                }
+                $caller .= $params[$i]."=".$query_str{$params[$i]}[0];
+            }
+        }
+        $newuri = $inbound.$caller;
+        $auth_cookie{uri} = $newuri;
+    }
     $r->notes->set('_ORIGURL' => $auth_cookie{uri});
+    $r->notes->set('_COOKIESTUFF' => $auth_name);
     $r->notes->set('_CURRURL' => $inbound);
     $r->notes->set('_SESSTOKEN' => $auth_cookie{token});
     $r->notes->set('_AUTHFAIL' => 1);
@@ -101,10 +120,12 @@
                     }
                 }
             } else {
+                $failflag = 1;
                 &note_cookie_auth_failure($r);
             }
         } else {
             $r->notes->set('_RejectAuth' => "Your session has expired. Please re-authenticate");
+            $failflag = 1;
             &note_cookie_auth_failure($r);
         }
     } else {
@@ -118,6 +139,17 @@
             }
         }
     }
+    if (!$failflag) {
+        if (keys(%auth_cookie) > 0) {
+            my $new_auth_cookie = new CGI::Cookie (
+                                      -name => $r->auth_name,
+                                      -value => \%auth_cookie,
+                                      -path => '/',
+                                     );
+            $r->headers_out->{'Set-cookie'} = $new_auth_cookie;
+            $r->err_headers_out->{'Set-cookie'} = $new_auth_cookie;
+        }
+    }
     $dbh->disconnect;
     return OK;
 }
@@ -221,7 +253,6 @@
                                       -path => '/'
                                      );
     $r->err_headers_out->{'Set-cookie'} = $auth_cookie;
-    my %err_headers_out = $r->err_headers_out;
 }
   
 sub opensession () {