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

raeburn lon-capa-cvs@mail.lon-capa.org
Sat, 04 Feb 2006 01:24:33 -0000


This is a MIME encoded message

--raeburn1139016273
Content-Type: text/plain

raeburn		Fri Feb  3 20:24:33 2006 EDT

  Modified files:              
    /modules/raeburn/register	Login.pm 
  Log:
  Changes to make this work with Apache2.  Form parameter retrieval now uses routines in processform.pm. Also include expiration time in e-mail message. 
  
  
--raeburn1139016273
Content-Type: text/plain
Content-Disposition: attachment; filename="raeburn-20060203202433.txt"

Index: modules/raeburn/register/Login.pm
diff -u modules/raeburn/register/Login.pm:1.3 modules/raeburn/register/Login.pm:1.4
--- modules/raeburn/register/Login.pm:1.3	Wed Apr 27 12:59:54 2005
+++ modules/raeburn/register/Login.pm	Fri Feb  3 20:24:31 2006
@@ -1,15 +1,19 @@
 package Apache::LON::Login;
 
 use strict;
+use Apache::Const qw(:common :http REDIRECT);
+use Apache::RequestRec();
+use Apache::RequestIO();
 use Storable qw(store retrieve dclone);
-use Apache::Constants qw(:common :http REDIRECT);
 use MD5;
 use Crypt::PasswdMD5;
+use CGI::Apache qw(:standard);
 use CGI::Cookie();
 use HTTP::Request;
-use Apache::Constants qw(OK SERVER_ERROR);
+#use Apache::Constants qw(OK SERVER_ERROR);
 use DBI;
 use LWP;
+use Apache::LON::processform;
 
 sub handler {
     my $r = shift;
@@ -27,17 +31,27 @@
             }
         }
     }
+    $r->content_type('text/html');
+    $r->send_http_header;
 
-    my %params = ($r->args,$r->content);
+    my %params = ();
+    &Apache::LON::processform::postitems($r,\%params);
+    if ($r->args) {
+        &Apache::LON::processform::getitems($r->args,\%params);
+    }
+
+#    my %params = ($r->args,$r->content);
     foreach (keys %params) {
-        $params{$_} =~ s#`#'#g;
-        $params{$_} =~ s#\$#\(\$\)#g;
+        for (my $j=0; $j<@{$params{$_}}; $j++) {
+            $params{$_}[$j] =~ s#`#'#g;
+            $params{$_}[$j] =~ s#\$#\(\$\)#g;
+        }
     }
-    if ($params{'process'} eq 'signup') {
+    if ($params{'process'}[0] eq 'signup') {
         &signup($r,$caller,\%params);
-        return OK;
+        return Apache::OK;
     }
-    my $msgtoken = $params{"msgtoken"};
+    my $msgtoken = $params{"msgtoken"}[0];
     my $message = '';
     if ( ($msgtoken ne '')  && (-e "/tmp/session_tokens/$msgtoken") ) {
         my $msghash = &Storable::retrieve("/tmp/session_tokens/$msgtoken");
@@ -47,7 +61,7 @@
     $r->content_type('text/html');
     $r->send_http_header;
     $r->print(&display($r,$caller,$token,$message));
-    return OK;
+    return Apache::OK;
 }
 
 sub display {
@@ -184,7 +198,7 @@
           <font class="bodyblue"><b>Create a LON-CAPA guest ID</b> &#150; use your guest ID to register for conferences, workshops or training.  If you are already a LON-CAPA user, please log-in.</font><br />
 	  <table border="0" align="left" cellpadding="0" cellspacing="0" height="95">
 	    <tr>
-	      <td align="left"><form name="signup" method="post" action="/login"><input name="signup" type="button" value="Sign Up Now" class="buttonred" onClick="javascript:send('newaccount')"><input type="hidden" name="process" value="signup"></form></td>
+	      <td align="left"><form name="signup" method="post" action="/login"><input name="signup" type="button" value="New to LON-CAPA: Click here to sign up" class="buttonred" onClick="javascript:send('newaccount')"><input type="hidden" name="process" value="signup"></form></td>
 	    </tr>
           </table>
 	</td>
@@ -290,7 +304,7 @@
           <td width="10" nowrap>&nbsp;</td>
        <td><font face="Arial, Helvetica, sans-serif" size="-1">
      <b>Note</b>:<br>
-      If log-in fails, it may be because your browser is not accepting session cookies, or javascript is disabled. <a href="http://loncapa.msu.edu/student/cookies.html"><u>Learn more</u></a>
+      If log-in fails, it may be because your browser is not accepting session cookies, or javascript is disabled. <a href="http://loncapa.msu.edu/student/cookies.html"><u>Learn more</u></a>.  Also, it may be that you selected the wrong domain; if you select LONCAPA ID as the account type, the domain you should select is the domain which houses your user account, which for some users is different from the domain which houses the courses they teach. 
      </font>
          </td>
          <td width="10" nowrap>&nbsp;</td>
@@ -481,12 +495,12 @@
     my $contact_name = "LON-CAPA support team";
 
 # figure out what page we're on and where we're heading.
-    my $page = $$params{'page'};
-    my $command = $$params{'go'};
+    my $page = $$params{'page'}[0];
+    my $command = $$params{'go'}[0];
     my $msg = '';
     my $current_page = &calculate_page($page,$command);
     if ($current_page > 1) {
-        if ($$params{'emailaddr'} !~ /^[^\@]+\@[^\@]+$/) {
+        if ($$params{'emailaddr'}[0] !~ /^[^\@]+\@[^\@]+$/) {
             $msg = "The e-mail address you entered is not a valid address.  Please try again.<br /><br />";
             &signup_zero($r,1,$msg,1);
             return;
@@ -604,7 +618,7 @@
 
 sub signup_one {
     my ($r,$params,$info,$dbh,$page,$contact_email,$contact_name) = @_;
-    my $user = $$params{'emailaddr'};
+    my $user = $$params{'emailaddr'}[0];
     my $user_quoted = $dbh->quote( $user );
     my $output;
     my %curr=();
@@ -657,7 +671,7 @@
         &main_box(\$output,$loadmsg,$width);
         $output .= <<"END";
         <br /><br />
-        An account already exists in the LON-CAPA support/registration system for the e-mail address you entered - $user.<br />Please choose one of the folowing:
+        An account already exists in the LON-CAPA support/registration system for the e-mail address you entered - $user.<br />Please choose one of the following:
        <ul>
         <li>Forgotten password? Request a <a href="/reset"><u>password reset</u></a>.</li>
         <li>Log-in and <a href="/update"><u>update your information</u></a>.</li>
@@ -755,7 +769,7 @@
           <td>&nbsp;</td>
           <td align='left'>
            <font face='arial,helvetica,sans serif'>
-           Your e-mail address:&nbsp;<b>$$params{'emailaddr'}</b> will be used as your username.<br />
+           Your e-mail address:&nbsp;<b>$$params{'emailaddr'}[0]</b> will be used as your username.<br />
             Please provide some additional contact information. 
            <br /><br />
 
@@ -988,11 +1002,11 @@
     my $width = '698';
     my $newpass = '';
     my %userdata = ();
-    my $user = $$params{'emailaddr'};
+    my $user = $$params{'emailaddr'}[0];
     my $user_quoted = $dbh->quote( $user );
     my ($msg,$webmsg,$mailflag,$mailmsg);
     foreach (%{$params}) {
-        $quoted_params{$_} = $dbh->quote( $$params{$_} );
+        $quoted_params{$_} = $dbh->quote( $$params{$_}[0] );
     }
 
 # Is there a password for this user?
@@ -1025,8 +1039,12 @@
                   my $directlogin = $dbh->selectrow_array("SELECT directlogin FROM event_config WHERE event = $event_quoted AND year = $year_quoted");
                   if ($directlogin) {
                       my $logtoken;
+                      my $now = time;
+                      my $expiration = $now + 1800;
+                      $expiration = localtime($expiration);
+                      
                       if (&maketoken($user,$event,$year,$caller,\$logtoken) eq 'ok') {
-                          $maildirections = "Go to http://support.loncapa.org/directlogin?logintoken=$logtoken to log-in to the LON-CAPA registration form for the $event, $year. This URL will be valid for the next 30 minutes. After that time you will need to return to the events page listed below and use your username and initial password to log-in.\n\n";
+                          $maildirections = "Go to http://support.loncapa.org/directlogin?logintoken=$logtoken to log-in to the LON-CAPA registration form for the $event, $year. This URL will be valid until $expiration (US Eastern Time Zone). After that time you will need to return to the events page listed below and use your username and initial password to log-in.\n\n";
                           $webdirections = "This e-mail contains a link which you can use to directly access the registration form for the $event, $year. The token included in the link will be valid for the next 30 minutes.  After that time you will need to use the password and username credentials included in the e-mail to log-in to the form.";
                       }
                   }
@@ -1045,7 +1063,7 @@
     ($userdata{'created'},$userdata{'domain'},$userdata{'lastname'},$userdata{'firstname'},$userdata{'middlename'},$userdata{'generation'},$userdata{'title'},$userdata{'dept'},$userdata{'institution'},$userdata{'email'},$userdata{'streetaddress'},$userdata{'citystate'},$userdata{'zip'},$userdata{'phone'}) =  $dbh->selectrow_array("SELECT created,domain,lastname,firstname,middlename,generation,title,dept,institution,email,streetaddress,citystate,zip,phone FROM support_user WHERE user_id = $user_quoted");
     if ($userdata{'created'}) {
         foreach (@{$info}) {
-            if ($$params{$_} ne $userdata{$_}) {
+            if ($$params{$_}[0] ne $userdata{$_}) {
                 push @infochanges, $_;
             }
         }
@@ -1064,7 +1082,7 @@
     }
 
     if ($mailflag) {
-        my $requestmail = "To: $$params{'emailaddr'}\n";
+        my $requestmail = "To: $$params{'emailaddr'}[0]\n";
         $requestmail .=  "From: $contact_name <$contact_email>\n".
     "Subject: LON-CAPA guest ID\n".
     "Thank you for your interest in LON-CAPA.\n\n".
@@ -1095,7 +1113,7 @@
 <html><head><title>Create a LON-CAPA GuestID</title>
 <meta http-equiv="pragma" content="no-cache">
 <meta http-equiv="Content-Type" content="text/html; charset=iso-8859-1">
-<meta HTTP-EQUIV="Refresh" CONTENT="10; url=$caller" />
+<meta HTTP-EQUIV="Refresh" CONTENT="30; url=$caller" />
 
 END_A
     &main_box(\$output,'',$width);

--raeburn1139016273--