[LON-CAPA-cvs] cvs: loncom(loncapaMITrelate_1) /interface lonuserutils.pm

raeburn raeburn at source.lon-capa.org
Wed Feb 8 14:35:21 EST 2012


raeburn		Wed Feb  8 19:35:21 2012 EDT

  Modified files:              (Branch: loncapaMITrelate_1)
    /loncom/interface	lonuserutils.pm 
  Log:
  - Customization for MITrelate.
    - Eliminate case sensitivity - new users all lower case.
    - Enforce requirement that all usernames are e-mail addresses when 
      creating new users.
  
  
Index: loncom/interface/lonuserutils.pm
diff -u loncom/interface/lonuserutils.pm:1.136.6.1 loncom/interface/lonuserutils.pm:1.136.6.2
--- loncom/interface/lonuserutils.pm:1.136.6.1	Wed Feb  8 16:27:28 2012
+++ loncom/interface/lonuserutils.pm	Wed Feb  8 19:35:20 2012
@@ -1,7 +1,7 @@
 # The LearningOnline Network with CAPA
 # Utility functions for managing LON-CAPA user accounts
 #
-# $Id: lonuserutils.pm,v 1.136.6.1 2012/02/08 16:27:28 raeburn Exp $
+# $Id: lonuserutils.pm,v 1.136.6.2 2012/02/08 19:35:20 raeburn Exp $
 #
 # Copyright Michigan State University Board of Trustees
 #
@@ -342,7 +342,8 @@
              ."</p>\n");
     $r->print('<div class="LC_left_float"><h3>'.
               &mt('Identify fields in uploaded list')."</h3>\n");
-    $r->print(&mt('Enter as many fields as you can.<br /> The system will inform you and bring you back to this page, <br /> if the data selected are insufficient to add users.')."<br />\n");
+    $r->print(&mt('Enter as many fields as you can.').'<br />'.
+             &mt('The system will inform you and bring you back to this page, [_1]if the data selected are insufficient to add users.','<br />')."<br />\n");
     $r->print(&hidden_input('action','upload').
               &hidden_input('state','got_file').
               &hidden_input('associate','').
@@ -4180,10 +4181,32 @@
                         }
                         $checkid = 1;
                         $newuser = 1;
-                        my $user = $username.':'.$newuserdom;
+                        if ($username =~/^[^\@]+\@[^\@]+$/) {
+                            if ($email eq '') {
+                                $email = $username;
+                            }
+                            my $lc_email;
+                            if ($username eq $email) {
+                                $lc_email = lc($email);
+                            }
+                            my $lc_username = lc($username);
+                            if ($lc_username ne $username) {
+                                if ($username eq $email) {
+                                    $email = $lc_username;
+                                }
+                                $username = $lc_username;
+                                $uhome=&Apache::lonnet::homeserver($username,$userdomain);
+                                if ($uhome ne 'no_host') {
+                                    $newuser = 0;
+                                }
+                            }
+                        }
+                    }
+                    my $user = $username.':'.$newuserdom;
+                    if ($newuser) {
                         my $checkhash;
                         my $checks = { 'username' => 1 };
-                        $checkhash->{$username.':'.$newuserdom} = { 'newuser' => 1, };
+                        $checkhash->{$user} = { 'newuser' => 1, };
                         &Apache::loncommon::user_rule_check($checkhash,$checks,
                             \%alerts,\%rulematch,\%inst_results,\%curr_rules,
                             \%got_rules);
@@ -4205,8 +4228,13 @@
                         }
                         unless ($cancreate{$usertype}) {
                             my $showtype = $longtypes{$usertype};
-                            $r->print('<br />'.
-                                      &mt('[_1]: The user does not exist, and you are not permitted to create users of type: [_2].','<b>'.$username.'</b>',$showtype));
+                            if ($usertype eq 'unofficial') {
+                                $r->print('<br />'.
+                                          &mt("[_1]: The user does not exist, and the new user's username must be an e-mail address.",'<b>'.$username.'</b>'));
+                            } else {
+                                $r->print('<br />'.
+                                          &mt("[_1]: The user does not exist, and you are not permitted to create users of type: [_2].",'<b>'.$username.'</b>',$showtype));
+                            }
                             next;
                         }
                     } else {




More information about the LON-CAPA-cvs mailing list