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

raeburn lon-capa-cvs-allow@mail.lon-capa.org
Sun, 13 Jul 2008 00:51:34 -0000


This is a MIME encoded message

--raeburn1215910294
Content-Type: text/plain

raeburn		Sat Jul 12 20:51:34 2008 EDT

  Modified files:              
    /loncom/interface	createaccount.pm 
    /loncom/auth	lonauth.pm 
  Log:
  Move duplicate code in lonauth.pm and createaccount.pm which handles result from createaccount::username_check() into username_check() for both log-in ID and SSO cases.
  - additional args ($contact_name $sso_logout) passed to &username_check for SSO case.
  - Page for user information data table customized based on availability of data fields, and whther data can be entered (according to $rowcount and $editable args returned from &loncreateuser::personal_data_display().
   - If no values are available or editable don't display table.
   - If only non-editable values are available - display table with appropriate message.
   - If one or more editable values - display table with appropriate message.
  If username check reports errors (e.g., 'username' not in institutional database, or 'authtoken' - authtoken could not be set) - display appropriate error reports.
  
  
--raeburn1215910294
Content-Type: text/plain
Content-Disposition: attachment; filename="raeburn-20080712205134.txt"

Index: loncom/interface/createaccount.pm
diff -u loncom/interface/createaccount.pm:1.17 loncom/interface/createaccount.pm:1.18
--- loncom/interface/createaccount.pm:1.17	Sat Jul 12 10:08:58 2008
+++ loncom/interface/createaccount.pm	Sat Jul 12 20:51:31 2008
@@ -3,7 +3,7 @@
 # institutional log-in ID (institutional authentication required - localauth
 #  or kerberos) or an e-mail address.
 #
-# $Id: createaccount.pm,v 1.17 2008/07/12 14:08:58 raeburn Exp $
+# $Id: createaccount.pm,v 1.18 2008/07/13 00:51:31 raeburn Exp $
 #
 # Copyright Michigan State University Board of Trustees
 #
@@ -127,34 +127,18 @@
 
     if ($sso_username ne '') {
         &print_header($r,$start_page);
-        my $msg;
+        my ($msg,$sso_logout);
+        $sso_logout = &sso_logout_frag($r,$domain);
         if (grep(/^sso$/,@cancreate)) {
             $msg = '<h3>'.&mt('Account creation').'</h3>'.
                    &mt("Although your username and password were authenticated by your institution's Single Sign On system, you do not currently have a LON-CAPA account at this institution.").'<br />';
-            my ($output,$checkfail) = &username_check($sso_username,$domain,
-                                                      $domdesc,$courseid,
-                                                      $lonhost,$contact_email);
-            if ($checkfail) {
-                $msg .= '<h4>'.&mt('Account creation unavailable').'</h4>';
-                if ($checkfail eq 'username') {
-                    $msg .= '<span class="LC_warning">'.
-                            &mt('A LON-CAPA account may not be created with the username you use.').
-                            '</span><br /><br />'.$output;
-                } elsif ($checkfail eq 'authtoken') {
-                    $msg .= '<span class="LC_error">'.&mt('Error creating token.').'</span>'.
-                            '<br />'.$output;
-                }
-                $msg .= &mt('Please contact the [_1] ([_2]) for assistance.',
-                            $contact_name,$contact_email).'<br /><hr />'.
-                        &sso_logout_frag($r,$domain);    
 
-            } else {
-                $msg .= '<br />'.&mt('To create one, use the table below to provide information about yourself (if appropriate), then click the "Create LON-CAPA account" button.').'<br />'.$output;
-            }
+            $msg .= &username_check($sso_username,$domain,$domdesc,$courseid, 
+                                    $lonhost,$contact_email,$contact_name,$sso_logout);
         } else {
             $msg = '<h3>'.&mt('Account creation unavailable').'</h3>'.
                    '<span class="LC_warning">'.&mt("Although your username and password were authenticated by your institution's Single Sign On system, you do not currently have a LON-CAPA account at this institution, and you are not permitted to create one.").'</span><br /><br />'.&mt('Please contact the [_1] ([_2]) for assistance.',$contact_name,$contact_email).'<hr />'.
-                   &sso_logout_frag($r,$domain);
+                   $sso_logout;
         }
         $r->print($msg);
         $r->print(&Apache::loncommon::end_page());
@@ -749,8 +733,8 @@
             $authok = 'non_authorized';
         }
         if ($authok eq 'authorized') {
-            ($output,undef) = &username_check($username,$domain,$domdesc,
-                                              $courseid,$lonhost,$contact_email); 
+            $output = &username_check($username,$domain,$domdesc,$courseid,$lonhost,
+                                      $contact_email,$contact_name);
         } else {
             $output = '<div class="LC_warning">'
                      .&mt('Username and/or password could not be authenticated.')
@@ -762,8 +746,10 @@
 }
 
 sub username_check {
-    my ($username,$domain,$domdesc,$courseid,$lonhost,$contact_email) = @_;
-    my (%rulematch,%inst_results,$newuser,%alerts,%curr_rules,%got_rules);
+    my ($username,$domain,$domdesc,$courseid,$lonhost,$contact_email,$contact_name,
+        $sso_logout) = @_;
+    my (%rulematch,%inst_results,$newuser,$checkfail,$rowcount,$editable,$output,$msg,
+        %alerts,%curr_rules,%got_rules);
     $newuser = 1;
     my $checkhash;
     my $checks = { 'username' => 1 };
@@ -773,48 +759,75 @@
     if (ref($alerts{'username'}) eq 'HASH') {
         if (ref($alerts{'username'}{$domain}) eq 'HASH') {
             if ($alerts{'username'}{$domain}{$username}) {
-                my ($userchkmsg,$checkfail);
                 if (ref($curr_rules{$domain}) eq 'HASH') {
-                    $userchkmsg =
+                    $output =
                         &Apache::loncommon::instrule_disallow_msg('username',$domdesc,1,
                                                                   'selfcreate').
                         &Apache::loncommon::user_rule_formats($domain,$domdesc,
                                 $curr_rules{$domain}{'username'},'username');
-                    if ($userchkmsg) {
-                        $checkfail = 'username';
-                    }
                 }
-                return ($userchkmsg,$checkfail);
+                $checkfail = 'username';
             }
         }
     }
-    my $submit_text = &mt('Create LON-CAPA account');
-    my $output = '<form method="post" action="/adm/createaccount">'.
-                 &Apache::loncreateuser::personal_data_display($username,$domain,1,
-                                    undef,$inst_results{$username.':'.$domain}).
-                '<br /><br /><input type="hidden" name="uname" value="'.$username.'" />'."\n".
-                '<input type="hidden" name="udom" value="'.$domain.'" />'."\n".
-                '<input type="hidden" name="phase" value="username_activation" />';
-    my $now = time;
-    my %info = ('ip'         => $ENV{'REMOTE_ADDR'},
-                'time'       => $now,
-                'domain'     => $domain,
-                'username'   => $username);
-    my $authtoken = &Apache::lonnet::tmpput(\%info,$lonhost);
-    if ($authtoken !~ /^error/ && $authtoken ne 'no_such_host') {
-        $output .= '<input type="hidden" name="authtoken" value="'.&HTML::Entities::encode($authtoken,'&<>"').'" />';
+    if (!$checkfail) {
+        $output = '<form method="post" action="/adm/createaccount">';
+        (my $datatable,$rowcount,$editable) = 
+            &Apache::loncreateuser::personal_data_display($username,$domain,1,'selfcreate',
+                                                         $inst_results{$username.':'.$domain});
+        if ($rowcount > 0) {
+            $output .= $datatable;
+        }
+        $output .=  '<br /><br /><input type="hidden" name="uname" value="'.$username.'" />'."\n".
+                    '<input type="hidden" name="udom" value="'.$domain.'" />'."\n".
+                    '<input type="hidden" name="phase" value="username_activation" />';
+        my $now = time;
+        my %info = ('ip'         => $ENV{'REMOTE_ADDR'},
+                    'time'       => $now,
+                    'domain'     => $domain,
+                    'username'   => $username);
+        my $authtoken = &Apache::lonnet::tmpput(\%info,$lonhost);
+        if ($authtoken !~ /^error/ && $authtoken ne 'no_such_host') {
+            $output .= '<input type="hidden" name="authtoken" value="'.&HTML::Entities::encode($authtoken,'&<>"').'" />';
+        } else {
+            $output = &mt('An error occurred when storing a token').'<br />'.
+                      &mt('You will not be able to proceed to the next stage of account creation').
+                      &linkto_email_help($contact_email,$domdesc);
+            $checkfail = 'authtoken';
+        }
+    }
+    if ($checkfail) { 
+        $msg = '<h4>'.&mt('Account creation unavailable').'</h4>';
+        if ($checkfail eq 'username') {
+            $msg .= '<span class="LC_warning">'.
+                     &mt('A LON-CAPA account may not be created with the username you use.').
+                     '</span><br /><br />'.$output;
+        } elsif ($checkfail eq 'authtoken') {
+            $msg .= '<span class="LC_error">'.&mt('Error creating token.').'</span>'.
+                    '<br />'.$output;
+        }
+        $msg .= &mt('Please contact the [_1] ([_2]) for assistance.',
+                $contact_name,$contact_email).'<br /><hr />'.
+                $sso_logout;
+        &Apache::lonnet::logthis("ERROR: failure type of '$checkfail' when performing username check to create account for authenticated user: $username, in domain $domain");
     } else {
-        $output = &mt('An error occurred when storing a token').'<br />'.
-                  &mt('You will not be able to proceed to the next stage of account creation').
-                  &linkto_email_help($contact_email,$domdesc);
-        return($output,'authtoken');
-    }
-    if ($courseid ne '') {
-        $output .= '<input type="hidden" name="courseid" value="'.$courseid.'" />';
-    }
-    $output .= '<input type="submit" name="newaccount" value="'.
-               $submit_text.'" /></form>';
-    return ($output,'');
+        if ($courseid ne '') {
+            $output .= '<input type="hidden" name="courseid" value="'.$courseid.'" />';
+        }
+        $output .= '<input type="submit" name="newaccount" value="'.
+                   &mt('Create LON-CAPA account').'" /></form>';
+        if ($rowcount) {
+            if ($editable) {
+                $msg = &mt('To create one, use the table below to provide information about yourself, then click the [_1]Create LON-CAPA account[_2] button.','<span class="LC_cusr_emph">','</span>').'<br />';
+            } else {
+                 $msg = &mt('A user account will be created with information displayed in the table below, when you click the [_1]Create LON-CAPA account[_2] button.','<span class="LC_cusr_emph">','</span>').'<br />';
+            }
+        } else {
+            $msg = '<br />'.&mt('Confirm that you wish to create an account.');
+        }
+        $msg .= $output;
+    }
+    return $msg;
 }
 
 sub username_activation {
Index: loncom/auth/lonauth.pm
diff -u loncom/auth/lonauth.pm:1.93 loncom/auth/lonauth.pm:1.94
--- loncom/auth/lonauth.pm:1.93	Wed Jul  9 20:26:40 2008
+++ loncom/auth/lonauth.pm	Sat Jul 12 20:51:31 2008
@@ -1,7 +1,7 @@
 # The LearningOnline Network
 # User Authentication Module
 #
-# $Id: lonauth.pm,v 1.93 2008/07/10 00:26:40 raeburn Exp $
+# $Id: lonauth.pm,v 1.94 2008/07/13 00:51:31 raeburn Exp $
 #
 # Copyright Michigan State University Board of Trustees
 #
@@ -298,32 +298,15 @@
                 &Apache::loncommon::build_recipient_list(undef,'helpdeskmail',
                                                         $form{'udom'},$origmail);
             my ($contact_email) = split(',',$contacts); 
-            my ($output,$checkfail) = 
-                &Apache::createaccount::username_check($form{'uname'},$form{'udom'},
-                                                      $domdesc,undef,$lonhost,
-                                                      $contact_email);
+            my $output = &Apache::createaccount::username_check($form{'uname'}, 
+                                                                $form{'udom'},$domdesc,'',
+                                                                $lonhost,$contact_email,$contact_name);
             &Apache::loncommon::content_type($r,'text/html');
             $r->send_http_header;
             &Apache::createaccount::print_header($r,$start_page);
-            my $msg = '<h3>'.&mt('Account creation').'</h3>'.
-                      '<span class="LC_cusr_emph">'.&mt('Although your username and password were authenticated, you do not currently have a LON-CAPA account in this domain.').'</span><br />';
-            if ($checkfail) {
-                $msg .= '<h4>'.&mt('Account creation unavailable').'</h4>';
-                if ($checkfail eq 'username') {
-                    $msg .= '<span class="LC_warning">'.
-                            &mt('A LON-CAPA account may not be created with the username you use.').'</span>';
-                } elsif ($checkfail eq 'authtoken') {
-                    $msg .= '<span class="LC_error">'.&mt('Error creating token.').'</span>';
-                }
-                &Apache::lonnet::logthis("ERROR: failure type of '$checkfail' when performing username check to create account for authenticated user: $form{'uname'}, in domain $form{'udom'}");
-                $msg .= '<br /><br />'.
-                         &mt('Please contact the [_1] ([_2]) for assistance.',
-                             $contact_name,$contact_email);
-            } else {
-                $msg .= &mt('To create one, use the table below to provide information about yourself (if appropriate), then click the "Create LON-CAPA account" button.');
-            }
-            $r->print($msg.$output);
-            $r->print(&Apache::loncommon::end_page());
+            $r->print('<h3>'.&mt('Account creation').'</h3>'.
+                      &mt('Although your username and password were authenticated, you do not currently have a LON-CAPA account at this institution.').'<br />'.
+                      $output.&Apache::loncommon::end_page());
             return OK;
         } else {
             &failed($r,'Although your username and password were authenticated, you do not currently have a LON-CAPA account in this domain, and you are not permitted to create one.',\%form);

--raeburn1215910294--