[LON-CAPA-cvs] cvs: loncom /interface lonrequestcourse.pm
raeburn
raeburn@source.lon-capa.org
Wed, 05 Jan 2011 18:47:46 -0000
This is a MIME encoded message
--raeburn1294253266
Content-Type: text/plain
raeburn Wed Jan 5 18:47:46 2011 EDT
Modified files:
/loncom/interface lonrequestcourse.pm
Log:
- Authentication type and authentication arg (optional) need to be stored
in course request for any users without existing accounts.
Will use domain defaults if no usertype determined (i.e., no username
format rules active).
Otherwise will use values defined in localenroll::username_rules() for "official"
users and internal auth with randomly generated password (e-mailed to new user)
for "unofficial" users.
--raeburn1294253266
Content-Type: text/plain
Content-Disposition: attachment; filename="raeburn-20110105184746.txt"
Index: loncom/interface/lonrequestcourse.pm
diff -u loncom/interface/lonrequestcourse.pm:1.59 loncom/interface/lonrequestcourse.pm:1.60
--- loncom/interface/lonrequestcourse.pm:1.59 Fri Nov 19 00:01:25 2010
+++ loncom/interface/lonrequestcourse.pm Wed Jan 5 18:47:46 2011
@@ -1,7 +1,7 @@
# The LearningOnline Network
# Request a course
#
-# $Id: lonrequestcourse.pm,v 1.59 2010/11/19 00:01:25 raeburn Exp $
+# $Id: lonrequestcourse.pm,v 1.60 2011/01/05 18:47:46 raeburn Exp $
#
# Copyright Michigan State University Board of Trustees
#
@@ -1322,16 +1322,38 @@
}
if ($skipuser) {
push(@disallowed,$i);
- $disallowmsg{$i} = &mt('[_1] was excluded because new users need be from the course domain','<tt>'.$personname.':'.$persondom.'</tt>');
+ $disallowmsg{$i} = &mt('[_1] was excluded because new users need to be from the course domain','<tt>'.$personname.':'.$persondom.'</tt>');
next;
}
}
- if (&get_cancreate_status($persondom,$personname,$dom)) {
- my ($allowed,$msg) =
+ my $usertype = &get_usertype($persondom,$personname,\%curr_rules,\%got_rules);
+ if (&Apache::lonuserutils::can_create_user($dom,'requestcrs',$usertype)) {
+ my ($allowed,$msg,$authtype,$authparam) =
&check_newuser_rules($persondom,$personname,
\%alerts,\%rulematch,\%inst_results,
\%curr_rules,\%got_rules);
if ($allowed) {
+ my %domdefaults = &Apache::lonnet::get_domain_defaults($persondom);
+ if ($usertype eq 'official') {
+ if ($authtype eq '') {
+ $authtype = $domdefaults{'auth_def'};
+ $authparam = $domdefaults{'auth_arg_def'};
+ }
+ } elsif ($usertype eq 'unofficial') {
+ if ($authtype eq '') {
+ $authtype = 'internal';
+ $authparam = '';
+ }
+ } else {
+ $authtype = $domdefaults{'auth_def'};
+ $authparam = $domdefaults{'auth_arg_def'};
+ }
+ if (($authtype eq '') ||
+ (($authtype =~/^krb/) && ($authparam eq ''))) {
+ push(@disallowed,$i);
+ $disallowmsg{$i} = &mt('[_1] was excluded because institutional information is incomplete for this new user.','<tt>'.$personname.':'.$persondom.'</tt>');
+ next;
+ }
if (ref($inst_results{$personname.':'.$persondom}) eq 'HASH') {
if ($inst_results{$personname.':'.$persondom}{'lastname'} ne '') {
$env{'form.person_'.$i.'_lastname'} = $inst_results{$personname.':'.$persondom}{'lastname'};
@@ -1454,13 +1476,13 @@
return;
}
-sub get_cancreate_status {
- my ($persondom,$personname,$dom) = @_;
+sub get_usertype {
+ my ($persondom,$personname,$curr_rules,$got_rules) = @_;
my ($rules,$ruleorder) =
&Apache::lonnet::inst_userrules($persondom,'username');
my $usertype = &Apache::lonuserutils::check_usertype($persondom,$personname,
- $rules);
- return &Apache::lonuserutils::can_create_user($dom,'requestcrs',$usertype);
+ $rules,$curr_rules,$got_rules);
+ return $usertype;
}
sub check_newuser_rules {
@@ -1468,7 +1490,7 @@
$got_rules) = @_;
my $allowed = 1;
my $newuser = 1;
- my ($checkhash,$userchkmsg);
+ my ($checkhash,$userchkmsg,$authtype,$authparam);
my $checks = { 'username' => 1 };
$checkhash->{$personname.':'.$persondom} = { 'newuser' => $newuser };
&Apache::loncommon::user_rule_check($checkhash,$checks,$alerts,$rulematch,
@@ -1490,7 +1512,22 @@
}
}
}
- return ($allowed,$userchkmsg);
+ if ($allowed) {
+ if (ref($rulematch) eq 'HASH') {
+ if (ref($rulematch->{$personname.':'.$persondom}) eq 'HASH') {
+ my $matchedrule = $rulematch->{$personname.':'.$persondom}{'username'};
+ my ($rules,$ruleorder) =
+ &Apache::lonnet::inst_userrules($persondom,'username');
+ if (ref($rules) eq 'HASH') {
+ if (ref($rules->{$matchedrule}) eq 'HASH') {
+ $authtype = $rules->{$matchedrule}{'authtype'};
+ $authparam = $rules->{$matchedrule}{'authparm'};
+ }
+ }
+ }
+ }
+ }
+ return ($allowed,$userchkmsg,$authtype,$authparam);
}
sub get_excluded_elements {
@@ -3065,6 +3102,7 @@
$enrollstart = '';
$enrollend = '';
}
+ my (%alerts,%rulematch,%inst_results,%curr_rules,%got_rules,%disallowmsg);
for (my $i=0; $i<$env{'form.persontotal'}; $i++) {
my $uname = $env{'form.person_'.$i.'_uname'};
my $udom = $env{'form.person_'.$i.'_dom'};
@@ -3076,6 +3114,51 @@
lastname => $env{'form.person_'.$i.'_lastname'},
emailaddr => $env{'form.person_'.$i.'_emailaddr'},
};
+ my $usertype = &get_usertype($udom,$uname,\%curr_rules,\%got_rules);
+ if (&Apache::lonuserutils::can_create_user($udom,'requestcrs',$usertype)) {
+ my ($allowed,$msg,$authtype,$authparam) =
+ &check_newuser_rules($udom,$uname,\%alerts,\%rulematch,
+ \%inst_results,\%curr_rules,\%got_rules);
+ if ($allowed) {
+ my %domdefaults = &Apache::lonnet::get_domain_defaults($udom);
+ if ($usertype eq 'official') {
+ if ($authtype eq '') {
+ $authtype = $domdefaults{'auth_def'};
+ $authparam = $domdefaults{'auth_arg_def'};
+ } else {
+ if ($authtype eq 'loc') {
+ $authtype = 'localauth';
+ } elsif ($authtype eq 'int') {
+ $authtype = 'internal';
+ }
+ if ($authtype !~ /^(krb4|krb5|internal|localauth)$/) {
+ $authtype = $domdefaults{'auth_def'};
+ $authparam = $domdefaults{'auth_arg_def'};
+ }
+ }
+ } elsif ($usertype eq 'unofficial') {
+ if ($authtype eq '') {
+ $authtype = 'internal';
+ $authparam = '';
+ }
+ } else {
+ $authtype = $domdefaults{'auth_def'};
+ $authparam = $domdefaults{'auth_arg_def'};
+ }
+ if (($authtype eq '') ||
+ (($authtype =~/^krb(4|5)$/) && ($authparam eq '')) ||
+ ($authtype !~ /^(krb4|krb5|internal|localauth)$/)) {
+ next;
+ } else {
+ $personnel{$uname.':'.$udom}{'authtype'} = $authtype;
+ $personnel{$uname.':'.$udom}{'autharg'} = $authparam;
+ }
+ } else {
+ next;
+ }
+ } else {
+ next;
+ }
}
my $role = $env{'form.person_'.$i.'_role'};
unless ($role eq '') {
--raeburn1294253266--