[LON-CAPA-cvs] cvs: loncom /enrollment Enrollment.pm
raeburn
lon-capa-cvs@mail.lon-capa.org
Fri, 05 Dec 2003 18:56:27 -0000
This is a MIME encoded message
--raeburn1070650587
Content-Type: text/plain
raeburn Fri Dec 5 13:56:27 2003 EDT
Modified files:
/loncom/enrollment Enrollment.pm
Log:
Fixed bugs caught by use strict. Modified authentication check. Replaced call to local version of modify_student_enrollment with call to lonnet::modify_student_enrollment.
--raeburn1070650587
Content-Type: text/plain
Content-Disposition: attachment; filename="raeburn-20031205135627.txt"
Index: loncom/enrollment/Enrollment.pm
diff -u loncom/enrollment/Enrollment.pm:1.2 loncom/enrollment/Enrollment.pm:1.3
--- loncom/enrollment/Enrollment.pm:1.2 Fri Dec 5 12:31:40 2003
+++ loncom/enrollment/Enrollment.pm Fri Dec 5 13:56:27 2003
@@ -123,6 +123,7 @@
}
# Get mapping of student IDs to usernames for users in institutional data for this class
my @allINids = ();
+ my %unameFromINid = ();
foreach my $uname (@okusers) {
$enrollinfo{$uname}[ $place{'studentID'} ] =~ tr/A-Z/a-z/;
my $stuID = $enrollinfo{$uname}[ $place{'studentID'} ];
@@ -148,8 +149,8 @@
# Check for section changes
unless ($$currlist{$uname}[$sec] eq $stuinfo[ $place{groupID} ]) {
$logmsg .= "Found a section difference for $uname - ".$$currlist{$uname}[$sec] ."versus ".$stuinfo[ $place{groupID} ]." in class $crs\n";
- if ($$currlist{$uname}[$type] eq "auto") {
- my $modify_section_result = &Apache::lonnet::modifystudent($dom,$uname,'','','',undef,undef,undef,undef,$$currlist{$uname}[$sec],$nowtime,undef,undef,undef,undef,'auto',$cid);
+ if ( ($$currlist{$uname}[$type] eq "auto") && ($adds == 1) ) {
+ my $modify_section_result = &Apache::lonnet::modifystudent($dom,$uname,'','','',undef,undef,undef,undef,$$currlist{$uname}[$sec],time,undef,undef,undef,undef,'auto',$cid);
if ($modify_section_result !~ /^ok/) {
$logmsg .= "An error occured during the attempt to expire the $uname from the old section $$currlist{$uname}[$sec] - $modify_section_result\n";
}
@@ -163,10 +164,10 @@
my $newend = $stuinfo[ $place{enddate} ];
my $newstart = $stuinfo[ $place{startdate} ];
if ($newend eq '') {
- $end = $enddate;
+ $newend = $enddate;
}
if ($newstart eq '') {
- $start = $startdate;
+ $newstart = $startdate;
}
&Apache::lonnet::assignrole($dom,$uname,$uurl,"st",$newend,$newstart);
}
@@ -209,6 +210,9 @@
if ($authparam eq '') {
$authparam = $autharg;
}
+ if ($auth =~ m/^krb/) {
+ $auth .= ":".$authparam;
+ }
if ($end eq '') {
$end = $enddate;
}
@@ -223,37 +227,49 @@
# Check for existing account in this LON-CAPA domain for this username
my $uhome=&Apache::lonnet::homeserver($uname,$dom);
if ($uhome eq 'no_host') { # User does not exist
- $create_passwd = 0;
- if ($passwd eq '') {
+ my $create_passwd = 0;
+ my $authchk = '';
+ unless ($authparam eq '') { $authchk = 'ok'; };
# If no account exists and passwords should be generated
- if (($authtype eq "int") || ($authtype eq "loc")) {
- ($passwd,$create_passwd) = &create_password($authtype); }
- } elsif ($authtype =~ m/^krb/) {
- $passwd = $autharg;
- } else {
- $logmsg .= "Invalid authentication type for $uname in $crs\n";
- }
- }
-# Now create user.
- my $reply=&Apache::lonnet::modifystudent($dom,$uname,$pid,$auth,$authparam,$first,$middle,$last,$gene,$usec,$end,$start,'',undef,$emailaddr,'auto',$cid);
- if ($reply eq 'ok') {
- $enrollcount ++;
- $addresult .= "$first $last ($pid) - $uname enrolled in section/group $usec.".$linefeed;
- $logmsg .= "New user $uname added successfully. ";
- unless ($emailenc eq '') {
- my %emailHash;
- $emailHash{'critnotification'} = $emailenc;
- $emailHash{'notification'} = $emailenc;
- my $putresult = &Apache::lonnet::put('environment',\%emailHash,$dom,$uname);
+ if ($authtype eq "int") {
+ if ($authparam eq '') {
+ ($authparam,$create_passwd,$authchk) = &create_password();
+ }
+ } elsif ($authtype eq "local") {
+ if ($authparam eq '') {
+ ($authparam,$create_passwd,$authchk) = &create_password();
+ }
+ } elsif ($authtype =~ m/^krb/) {
+ if ($authparam eq '') {
+ $logmsg .= "No Kerberos domain available for the new user - $uname in course $crs - no enrollment occurred.\n";
+ $authchk = 'invalid';
}
- if ($create_passwd) {
+ } else {
+ $authchk = 'invalid';
+ $logmsg .= "Invalid authentication type for new user - $uname in course $crs - no enrollment occurred.\n";
+ }
+ unless ($authchk eq 'ok') {
+# Now create user.
+ my $reply=&Apache::lonnet::modifystudent($dom,$uname,$pid,$auth,$authparam,$first,$middle,$last,$gene,$usec,$end,$start,'',undef,$emailaddr,'auto',$cid);
+ if ($reply eq 'ok') {
+ $enrollcount ++;
+ $addresult .= "$first $last ($pid) - $uname enrolled in section/group $usec.".$linefeed;
+ $logmsg .= "New user $uname added successfully. ";
+ unless ($emailenc eq '') {
+ my %emailHash;
+ $emailHash{'critnotification'} = $emailenc;
+ $emailHash{'notification'} = $emailenc;
+ my $putresult = &Apache::lonnet::put('environment',\%emailHash,$dom,$uname);
+ }
+ if ($create_passwd) {
# Send e-mail with inital password to new user at $emailaddr
- $logmsg .= "Initial password - - sent to $emailaddr\n";
+ $logmsg .= "Initial password - - sent to $emailaddr\n";
+ } else {
+ $logmsg .= "\n";
+ }
} else {
- $logmsg .= "\n";
+ $logmsg .= "An error occurred adding new user $uname - $reply\n";
}
- } else {
- $logmsg .= "An error occurred adding new user $uname - $reply\n";
}
} else {
# Get the user's information and authentication
@@ -265,7 +281,8 @@
# Get the user's e-mail address
if ($userenv{critnotification} =~ m/%40/) {
unless ($emailenc eq $userenv{critnotification}) {
- $logmsg .= "Current critical notification e-mail - ".$userenv{critnotification}." for $uname is different to e-mail address in Institutional classlist - $emailenc\n";
+ $logmsg .= "Current critical notification e-mail - ".$userenv{critnotification}." for $uname is different to e-mail address in Institutional classlist - $emailenc\n";
+ }
}
if ($userenv{notification} =~ m/%40/) {
unless ($emailenc eq $userenv{critnotification}) {
@@ -305,28 +322,22 @@
$changeHash{'id'} = $pid;
my $putresult = &Apache::lonnet::put('environment',\%changeHash,$dom,$uname);
if ($putresult eq 'ok') {
- $logmsg .= "User: $uname enrolled in $crs\n";
-# Assign the role of student
- $classlist_reply = &modify_student_enrollment($$configvars{'lonHostID'},$dom,$cid,$crs,$uname,$pid,$first,$middle,$last,$gene,$usec,$end,$start,'auto');
- if ($classlist_reply eq 'ok') {
- my $uurl='/'.$cid;
- $uurl=~s/\_/\//g;
- if ($usec) {
- $uurl.='/'.$usec;
- }
- &Apache::lonnet::assignrole($dom,$uname,$uurl,"st",$enddate,$startdate);
- $addresult .= "$first $last ($pid) - $uname enrolled in section/group $usec.".$linefeed;
- $enrollcount ++;
- $addresult .= "$first $last ($pid) - $uname enrolled in section/group $usec.".$linefeed;
- $logmsg .= "Existing user $uname enrolled successfully in $crs\n";
-
- } else {
- $logmsg .= "There was a problem updating the classlist db file for user $uname to show the new enrollment, so no enrollment occurred in $crs\n";
- }
+ $logmsg .= "User information updated for user: $uname prior to enrollment in $crs\n";
} else {
- $logmsg .= "There was a problem modifying user data for existing user - $uname, so no enrollment occurred in $crs.\n";
+ $logmsg .= "There was a problem modifying user data for existing user - $uname, enrollment will still be attempted for user in $crs.\n";
}
}
+
+# Assign the role of student in the course.
+ my $classlist_reply = &Apache::lonnet::modify_student_enrollment($dom,$uname,$pid,$first,$middle,$last,$gene,$usec,$end,$start,'auto',$cid);
+ if ($classlist_reply eq 'ok') {
+ $enrollcount ++;
+ $addresult .= "$first $last ($pid) - $uname enrolled in section/group $usec.".$linefeed;
+ $logmsg .= "Existing user $uname enrolled successfully in $crs\n";
+
+ } else {
+ $logmsg .= "There was a problem updating the classlist db file for user $uname to show the new enrollment, so no enrollment occurred for this user in $crs\n";
+ }
}
}
}
@@ -392,34 +403,34 @@
}
sub parse_classlist {
- my ($tmpdir,$dom,$crs,$class,$placeref,$groupID,$studentsref) = @_;
- my $configvars = &LONCAPA::Configuration::read_conf();
- my $xmlfile = $tmpdir."/tmp/".$dom."_".$crs."_classlist.xml";
- my $enrolled = XMLin( $xmlfile, KeyAttr => ['username'] );
- foreach my $uname ( sort keys %{$$enrolled{'student'}} ) {
- @{ $$studentsref{$uname} } = ();
- foreach my $key (sort keys %{$$enrolled{'student'}{$uname}} ) {
- my $value = $$enrolled{'student'}{$uname}{$key};
- if (ref($value)) {
- $$studentsref{$uname}[ $$placeref{$key} ] = '';
- } else {
- if ($key eq 'groupID') {
- $$studentsref{$uname}[ $$placeref{$key} ] = $groupID;
- } else {
- $$studentsref{$uname}[ $$placeref{$key} ] = $value;
- }
- }
- }
- }
-# if (-e "$xmlfile") {
-# unlink $xmlfile;
-# }
- return;
+ my ($tmpdir,$dom,$crs,$class,$placeref,$groupID,$studentsref) = @_;
+ my $configvars = &LONCAPA::Configuration::read_conf();
+ my $xmlfile = $tmpdir."/tmp/".$dom."_".$crs."_classlist.xml";
+ my $enrolled = XMLin( $xmlfile, KeyAttr => ['username'] );
+ foreach my $uname ( sort keys %{$$enrolled{'student'}} ) {
+ @{ $$studentsref{$uname} } = ();
+ foreach my $key (sort keys %{$$enrolled{'student'}{$uname}} ) {
+ my $value = $$enrolled{'student'}{$uname}{$key};
+ if (ref($value)) {
+ $$studentsref{$uname}[ $$placeref{$key} ] = '';
+ } else {
+ if ($key eq 'groupID') {
+ $$studentsref{$uname}[ $$placeref{$key} ] = $groupID;
+ } else {
+ $$studentsref{$uname}[ $$placeref{$key} ] = $value;
+ }
+ }
+ }
+ }
+# if (-e "$xmlfile") {
+# unlink $xmlfile;
+# }
+ return;
}
sub create_password {
-
-
+ my ($authparam,$create_passwd,$authreply);
+ return ($authparam,$create_passwd,$authreply);
}
sub CL_autharg { return 0; }
--raeburn1070650587--