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

raeburn lon-capa-cvs-allow@mail.lon-capa.org
Sun, 13 Jul 2008 17:57:58 -0000


raeburn		Sun Jul 13 13:57:58 2008 EDT

  Modified files:              
    /loncom/interface	createaccount.pm 
  Log:
  Log-in screen for institutional IDs to create new accounts:
  - If user enters an existing username (for current domain):
    - password is correct: log the user in.
    - incorrect password: report invalid username or password.  
  
  
Index: loncom/interface/createaccount.pm
diff -u loncom/interface/createaccount.pm:1.18 loncom/interface/createaccount.pm:1.19
--- loncom/interface/createaccount.pm:1.18	Sat Jul 12 20:51:31 2008
+++ loncom/interface/createaccount.pm	Sun Jul 13 13:57:58 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.18 2008/07/13 00:51:31 raeburn Exp $
+# $Id: createaccount.pm,v 1.19 2008/07/13 17:57:58 raeburn Exp $
 #
 # Copyright Michigan State University Board of Trustees
 #
@@ -180,19 +180,26 @@
         $r->print($output);
         $r->print(&Apache::loncommon::end_page());
         return OK;
-    }
-
-    &print_header($r,$start_page);
-    if ($env{'form.create_with_email'}) {
+    } elsif ($env{'form.phase'} eq 'username_validation') { 
+        (my $result,$output) = 
+            &username_validation($r,$env{'form.uname'},$domain,$domdesc,
+                                 $contact_name,$contact_email,$courseid,
+                                 $lonhost);
+        if ($result eq 'existingaccount') {
+            $r->print($output);
+            $r->print(&Apache::loncommon::end_page());
+            return OK;
+        } else {
+            &print_header($r,$start_page);
+        }
+    } elsif ($env{'form.create_with_email'}) {
+        &print_header($r,$start_page);
         $output = &process_email_request($env{'form.useremail'},$domain,$domdesc,
                                          $contact_name,$contact_email,\@cancreate,
                                          $lonhost,$domconfig{'usercreation'},
                                          $courseid);
-    } elsif ($env{'form.phase'} eq 'username_validation') {
-        $output = &username_validation($env{'form.uname'},$domain,$domdesc,
-                                       $contact_name,$contact_email,$courseid,
-                                       $lonhost);
     } elsif (!$token) {
+        &print_header($r,$start_page);
         my $now=time;
         if (grep(/^login$/,@cancreate)) {
             my $jsh=Apache::File->new($include."/londes.js");
@@ -568,7 +575,9 @@
     if ($r->dir_config('lonBalancer') eq 'yes') {
         &Apache::lonauth::success($r,$form{'uname'},$form{'udom'},
                                   $lonhost,'noredirect',undef,\%form);
-        my $delete = &Apache::lonnet::tmpdel($token);
+        if ($token ne '') { 
+            my $delete = &Apache::lonnet::tmpdel($token);
+        }
         $r->internal_redirect('/adm/switchserver');
     } else {
         &Apache::lonauth::success($r,$form{'uname'},$form{'udom'},
@@ -707,21 +716,32 @@
 }
 
 sub username_validation {
-    my ($username,$domain,$domdesc,$contact_name,$contact_email,$courseid,$lonhost) = @_;
+    my ($r,$username,$domain,$domdesc,$contact_name,$contact_email,$courseid,
+        $lonhost) = @_;
     my ($retrieved,$output,$upass);
 
     $username= &LONCAPA::clean_username($username);
     $domain = &LONCAPA::clean_domain($domain);
     my $uhome = &Apache::lonnet::homeserver($username,$domain);
 
-    if ($uhome ne 'no_host') {
-        $output = &invalid_state('existinguser',$domdesc,
-                                 $contact_name,$contact_email);
-        return $output;
-    }
     ($retrieved,$output,$upass) = &process_credentials($env{'form.logtoken'},
                                                        $env{'form.serverid'});
-    if ($retrieved eq 'ok') {
+    if ($retrieved ne 'ok') {
+        return ('fail',$output);
+    }
+    if ($uhome ne 'no_host') {
+        my $result = &Apache::lonnet::authenticate($username,$upass,$domain);
+        if ($result ne 'no_host') { 
+            my %form = &start_session($r,$username,$domain,$lonhost,$courseid);
+            $output = '<br /><br />'.&mt('A LON-CAPA account already exists for username [_1] at this institution ([_2]).','<tt>'.$username.'</tt>',$domdesc).'<br />'.&mt('The password entered was also correct so you have been logged in.');
+            return ('existingaccount',$output);
+        } else {
+            $output = '<div class="LC_warning">'.
+                      &mt('Username and/or password could not be authenticated.').
+                      '</div>'.
+                      &mt('Please check the username and password.');
+        }
+    } else {
         my $primlibserv = &Apache::lonnet::domain($domain,'primary');
         my $authok;
         my %domdefaults = &Apache::lonnet::get_domain_defaults($domain);
@@ -736,13 +756,13 @@
             $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.')
-                     .'</div>'
-                     .&mt('Please check the username and password.'); 
+            $output = '<div class="LC_warning">'.
+                      &mt('Username and/or password could not be authenticated.').
+                      '</div>'.
+                      &mt('Please check the username and password.'); 
         }
     }
-    return $output;
+    return ('ok',$output);
 }
 
 sub username_check {