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

raeburn lon-capa-cvs-allow@mail.lon-capa.org
Wed, 14 May 2008 18:27:30 -0000


raeburn		Wed May 14 14:27:30 2008 EDT

  Modified files:              
    /loncom/auth	lonauth.pm lonacc.pm 
  Log:
  - If a user successfully authenticates via SSO, but a LON-CAPA account is lacking for the username used to authenticate, offer the possibility of creating an account, if selfcreation is allowed for the 'sso' auth type.
  - selfcreation auth types are now stored as an array, instead of a single-valued scalar.  
  
  
Index: loncom/auth/lonauth.pm
diff -u loncom/auth/lonauth.pm:1.90 loncom/auth/lonauth.pm:1.91
--- loncom/auth/lonauth.pm:1.90	Mon Mar 24 01:23:10 2008
+++ loncom/auth/lonauth.pm	Wed May 14 14:27:30 2008
@@ -1,7 +1,7 @@
 # The LearningOnline Network
 # User Authentication Module
 #
-# $Id: lonauth.pm,v 1.90 2008/03/24 05:23:10 raeburn Exp $
+# $Id: lonauth.pm,v 1.91 2008/05/14 18:27:30 raeburn Exp $
 #
 # Copyright Michigan State University Board of Trustees
 #
@@ -264,17 +264,20 @@
     }
 
 # ---------------------------------------------------------------- Authenticate
-    my $cancreate; 
+    my @cancreate;
     my %domconfig = &Apache::lonnet::get_dom('configuration',['usercreation'],$form{'udom'});
     if (ref($domconfig{'usercreation'}) eq 'HASH') {
         if (ref($domconfig{'usercreation'}{'cancreate'}) eq 'HASH') {
-            if ($domconfig{'usercreation'}{'cancreate'}{'selfcreate'} ne 'none') {
-                $cancreate = $domconfig{'usercreation'}{'cancreate'}{'selfcreate'};
+            if (ref($domconfig{'usercreation'}{'cancreate'}{'selfcreate'}) eq 'ARRAY') {
+                @cancreate = @{$domconfig{'usercreation'}{'cancreate'}{'selfcreate'}};
+            } elsif (($domconfig{'usercreation'}{'cancreate'}{'selfcreate'} ne 'none') && 
+                     ($domconfig{'usercreation'}{'cancreate'}{'selfcreate'} ne '')) {
+                @cancreate = ($domconfig{'usercreation'}{'cancreate'}{'selfcreate'});
             }
         }
     }
     my $defaultauth;
-    if ($cancreate eq 'any' || $cancreate eq 'login') {  
+    if (grep(/^login$/,@cancreate)) {
         $defaultauth = 1;
     }
     my $authhost=Apache::lonnet::authenticate($form{'uname'},$upass,
@@ -287,27 +290,25 @@
 		\%form);
         return OK;
     } elsif ($authhost eq 'no_account_on_host') {
-        my $cancreate;
         my %domconfig = 
             &Apache::lonnet::get_dom('configuration',['usercreation'],$form{'udom'});
-        if (ref($domconfig{'usercreation'}) eq 'HASH') {
-            if (ref($domconfig{'usercreation'}{'cancreate'}) eq 'HASH') {
-                if ($domconfig{'usercreation'}{'cancreate'}{'selfcreate'} ne 'none') {
-                    $cancreate = $domconfig{'usercreation'}{'cancreate'}{'selfcreate'};
-                }
-            }
-        }
-        if ($cancreate eq 'any' || $cancreate eq 'login') {
+        if (grep(/^login$/,@cancreate)) {
             my $start_page = 
                 &Apache::loncommon::start_page('Create a user account in LON-CAPA',
                                                '',{'no_inline_link'   => 1,});
             my $domdesc = &Apache::lonnet::domain($form{'udom'},'description');
-            my $output = &Apache::createaccount::username_check($form{'uname'},
-                                                                $form{'udom'},$domdesc);
+            my ($output,$checkfail) = &Apache::createaccount::username_check($form{'uname'},
+                                                                  $form{'udom'},$domdesc);
             &Apache::loncommon::content_type($r,'text/html');
             $r->send_http_header;
             &Apache::createaccount::print_header($r,$start_page);
-            $r->print($output);
+            my $msg = '<h4>'.&mt('Although your username and password were authenticated, you do not currently have a LON-CAPA account in this domain.').'<br />';
+            if ($checkfail) {
+                $msg .= &mt('A LON-CAPA account may not be created with the username you used.');
+            } 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('<h4>'.$msg.'</h4>'.$output);
             $r->print(&Apache::loncommon::end_page());
             return OK;
         } else {
Index: loncom/auth/lonacc.pm
diff -u loncom/auth/lonacc.pm:1.114 loncom/auth/lonacc.pm:1.115
--- loncom/auth/lonacc.pm:1.114	Fri Mar  7 21:45:14 2008
+++ loncom/auth/lonacc.pm	Wed May 14 14:27:30 2008
@@ -1,7 +1,7 @@
 # The LearningOnline Network
 # Cookie Based Access Handler
 #
-# $Id: lonacc.pm,v 1.114 2008/03/08 02:45:14 raeburn Exp $
+# $Id: lonacc.pm,v 1.115 2008/05/14 18:27:30 raeburn Exp $
 #
 # Copyright Michigan State University Board of Trustees
 #
@@ -203,7 +203,24 @@
 	&Apache::lonnet::logthis(" SSO authorized unknown user $user ");
         $r->subprocess_env->set('SSOUserUnknown' => $user);
         $r->subprocess_env->set('SSOUserDomain' => $domain);
-	$r->internal_redirect($r->dir_config('lonSSOUserUnknownRedirect'));
+        my @cancreate;
+        my %domconfig =
+            &Apache::lonnet::get_dom('configuration',['usercreation'],$domain);
+        if (ref($domconfig{'usercreation'}) eq 'HASH') {
+            if (ref($domconfig{'usercreation'}{'cancreate'}) eq 'HASH') {
+                if (ref($domconfig{'usercreation'}{'cancreate'}{'selfcreate'}) eq 'ARRAY') {
+                    @cancreate = @{$domconfig{'usercreation'}{'cancreate'}{'selfcreate'}};
+                } elsif (($domconfig{'usercreation'}{'cancreate'}{'selfcreate'} ne 'none') && 
+                         ($domconfig{'usercreation'}{'cancreate'}{'selfcreate'} ne '')) {
+                    @cancreate = ($domconfig{'usercreation'}{'cancreate'}{'selfcreate'});
+                }
+            }
+        }
+        if (grep(/^sso$/,@cancreate)) {
+            $r->internal_redirect('/adm/createaccount');
+        } else {
+	    $r->internal_redirect($r->dir_config('lonSSOUserUnknownRedirect'));
+        }
 	$r->set_handlers('PerlHandler'=> undef);
 	return OK;
     }