version 1.12, 2018/05/14 20:10:15
|
version 1.13, 2018/05/28 23:26:04
|
Line 434 sub handler {
|
Line 434 sub handler {
|
# |
# |
|
|
my (@ltiroles,@lcroles); |
my (@ltiroles,@lcroles); |
|
|
my @lcroleorder = ('cc','in','ta','ep','st'); |
my @lcroleorder = ('cc','in','ta','ep','st'); |
my @ltiroleorder = ('Instructor','TeachingAssistant','Mentor','Learner'); |
my ($lcrolesref,$ltirolesref) = &LONCAPA::ltiutils::get_lc_roles($params->{'roles'}, |
if ($params->{'roles'} =~ /,/) { |
\@lcroleorder); |
my @possltiroles = split(/\s*,\s*/,$params->{'roles'}); |
if (ref($lcrolesref) eq 'ARRAY') { |
foreach my $ltirole (@ltiroleorder) { |
@lcroles = @{$lcrolesref}; |
if (grep(/^\Q$ltirole\E$/,@possltiroles)) { |
|
push(@ltiroles,$ltirole); |
|
} |
|
} |
|
} else { |
|
my $singlerole = $params->{'roles'}; |
|
$singlerole =~ s/^\s|\s+$//g; |
|
if (grep(/^\Q$singlerole\E$/,@ltiroleorder)) { |
|
@ltiroles = ($singlerole); |
|
} |
|
} |
} |
if (@ltiroles) { |
if (ref($ltirolesref) eq 'ARRAY') { |
if (ref($lti{$itemid}{maproles}) eq 'HASH') { |
@ltiroles = @{$ltirolesref}; |
my %possroles; |
|
map { $possroles{$lti{$itemid}{maproles}{$_}} = 1; } @ltiroles; |
|
if (keys(%possroles) > 0) { |
|
foreach my $item (@lcroleorder) { |
|
if ($possroles{$item}) { |
|
push(@lcroles,$item); |
|
} |
|
} |
|
} |
|
} |
|
} |
} |
|
|
# |
# |
Line 485 sub handler {
|
Line 464 sub handler {
|
} |
} |
} |
} |
if ($selfcreate) { |
if ($selfcreate) { |
my (%rulematch,%inst_results,%curr_rules,%got_rules,%alerts,%info); |
my (%rulematch,%inst_results,%curr_rules,%got_rules,%alerts); |
my $checkhash = { "$uname:$udom" => { 'newuser' => 1, }, }; |
my $domdesc = &Apache::lonnet::domain($udom,'description'); |
my $checks = { 'username' => 1, }; |
my %data = ( |
&Apache::loncommon::user_rule_check($checkhash,$checks,\%alerts,\%rulematch, |
'permanentemail' => $env{'form.lis_person_contact_email_primary'}, |
\%inst_results,\%curr_rules,\%got_rules); |
'firstname' => $env{'form.lis_person_name_given'}, |
my ($userchkmsg,$lcauth,$lcauthparm); |
'lastname' => $env{'form.lis_person_name_family'}, |
my $allowed = 1; |
'fullname' => $env{'form.lis_person_name_full'}, |
if (ref($alerts{'username'}) eq 'HASH') { |
); |
if (ref($alerts{'username'}{$udom}) eq 'HASH') { |
|
my $domdesc = |
|
&Apache::lonnet::domain($udom,'description'); |
|
if ($alerts{'username'}{$udom}{$uname}) { |
|
if (ref($curr_rules{$udom}) eq 'HASH') { |
|
$userchkmsg = |
|
&Apache::loncommon::instrule_disallow_msg('username',$domdesc,1). |
|
&Apache::loncommon::user_rule_formats($udom,$domdesc, |
|
$curr_rules{$udom}{'username'}, |
|
'username'); |
|
} |
|
$allowed = 0; |
|
} |
|
} |
|
} |
|
if ($allowed) { |
|
if (ref($rulematch{$uname.':'.$udom}) eq 'HASH') { |
|
my $matchedrule = $rulematch{$uname.':'.$udom}{'username'}; |
|
my ($rules,$ruleorder) = |
|
&Apache::lonnet::inst_userrules($udom,'username'); |
|
if (ref($rules) eq 'HASH') { |
|
if (ref($rules->{$matchedrule}) eq 'HASH') { |
|
$lcauth = $rules->{$matchedrule}{'authtype'}; |
|
$lcauthparm = $rules->{$matchedrule}{'authparm'}; |
|
} |
|
} |
|
} |
|
if ($lcauth eq '') { |
|
$lcauth = $lti{$itemid}{'lcauth'}; |
|
if ($lcauth eq 'internal') { |
|
$lcauthparm = &create_passwd(); |
|
} else { |
|
$lcauthparm = $lti{$itemid}{'lcauthparm'}; |
|
} |
|
} |
|
} else { |
|
&invalid_request($r,12); |
|
} |
|
my @userinfo = ('firstname','middlename','lastname','generation', |
|
'permanentemail','id'); |
|
my %useinstdata; |
|
if (ref($lti{$itemid}{'instdata'}) eq 'ARRAY') { |
|
map { $useinstdata{$_} = 1; } @{$lti{$itemid}{'instdata'}}; |
|
} |
|
foreach my $item (@userinfo) { |
|
if (($useinstdata{$item}) && (ref($inst_results{$uname.':'.$udom}) eq 'HASH') && |
|
($inst_results{$uname.':'.$udom}{$item} ne '')) { |
|
$info{$item} = $inst_results{$uname.':'.$udom}{$item}; |
|
} else { |
|
if ($item eq 'permanentemail') { |
|
if ($env{'form.lis_person_contact_email_primary'} =~/^[^\@]+\@[^@]+$/) { |
|
$info{$item} = $env{'form.lis_person_contact_email_primary'}; |
|
} |
|
} elsif ($item eq 'firstname') { |
|
$info{$item} = $env{'form.lis_person_name_given'}; |
|
} elsif ($item eq 'lastname') { |
|
$info{$item} = $env{'form.lis_person_name_family'}; |
|
} |
|
} |
|
} |
|
if (($info{'middlename'} eq '') && ($env{'form.lis_person_name_full'} ne '')) { |
|
unless ($useinstdata{'middlename'}) { |
|
my $fullname = $env{'form.lis_person_name_full'}; |
|
if ($info{'firstname'}) { |
|
$fullname =~ s/^\s*\Q$info{'firstname'}\E\s*//i; |
|
} |
|
if ($info{'lastname'}) { |
|
$fullname =~ s/\s*\Q$info{'lastname'}\E\s*$//i; |
|
} |
|
if ($fullname ne '') { |
|
$fullname =~ s/^\s+|\s+$//g; |
|
if ($fullname ne '') { |
|
$info{'middlename'} = $fullname; |
|
} |
|
} |
|
} |
|
} |
|
if (ref($inst_results{$uname.':'.$udom}{'inststatus'}) eq 'ARRAY') { |
|
my @inststatuses = @{$inst_results{$uname.':'.$udom}{'inststatus'}}; |
|
$info{'inststatus'} = join(':',map { &escape($_); } @inststatuses); |
|
} |
|
my $result = |
my $result = |
&Apache::lonnet::modifyuser($udom,$uname,$info{'id'}, |
&LONCAPA::ltiutils::create_user($lti{$itemid},$uname,$udom, |
$lcauth,$lcauthparm,$info{'firstname'}, |
$domdesc,\%data,\%alerts,\%rulematch, |
$info{'middlename'},$info{'lastname'}, |
\%inst_results,\%curr_rules,%got_rules); |
$info{'generation'},undef,undef, |
if ($result eq 'notallowed') { |
$info{'permanentemail'},$info{'inststatus'}); |
&invalid_request($r,12); |
if ($result eq 'ok') { |
} elsif ($result eq 'ok') { |
if (($ltiroles[0] eq 'Instructor') && ($lcroles[0] eq 'cc') && ($lti{$itemid}{'mapcrs'}) && |
if (($ltiroles[0] eq 'Instructor') && ($lcroles[0] eq 'cc') && ($lti{$itemid}{'mapcrs'}) && |
($lti{$itemid}{'makecrs'})) { |
($lti{$itemid}{'makecrs'})) { |
unless (&Apache::lonnet::usertools_access($uname,$udom,'lti','reload','requestcourses')) { |
unless (&Apache::lonnet::usertools_access($uname,$udom,'lti','reload','requestcourses')) { |
Line 763 sub lti_enroll {
|
Line 661 sub lti_enroll {
|
my %coursehash = &Apache::lonnet::coursedescription($cdom.'_'.$cnum); |
my %coursehash = &Apache::lonnet::coursedescription($cdom.'_'.$cnum); |
my $start = $coursehash{'default_enrollment_start_date'}; |
my $start = $coursehash{'default_enrollment_start_date'}; |
my $end = $coursehash{'default_enrollment_end_date'}; |
my $end = $coursehash{'default_enrollment_end_date'}; |
my $area = "/$cdom/$cnum"; |
my $enrollresult = &LONCAPA::ltiutils::enrolluser($role,$cdom,$cnum,$sec,$start,$end); |
if (($role ne 'cc') && ($role ne 'co') && ($sec ne '')) { |
|
$area .= '/'.$sec; |
|
} |
|
my $spec = $role.'.'.$area; |
|
my $instcid; |
|
if ($role eq 'st') { |
|
$enrollresult = |
|
&Apache::lonnet::modify_student_enrollment($udom,$uname,undef,undef,undef, |
|
undef,undef,$sec,$end,$start, |
|
'ltienroll',undef,$cdom.'_'.$cnum,1, |
|
'ltienroll','',$instcid); |
|
} elsif ($role =~ /^(cc|in|ta|ep)$/) { |
|
$enrollresult = |
|
&Apache::lonnet::assignrole($udom,$uname,$area,$role,$end,$start, |
|
undef,1,'ltienroll'); |
|
} |
|
if ($enrollresult eq 'ok') { |
if ($enrollresult eq 'ok') { |
my (%userroles,%newrole,%newgroups); |
my (%userroles,%newrole,%newgroups); |
&Apache::lonnet::standard_roleprivs(\%newrole,$role,$cdom,$spec,$cnum, |
&Apache::lonnet::standard_roleprivs(\%newrole,$role,$cdom,$spec,$cnum, |
Line 996 sub invalid_request {
|
Line 878 sub invalid_request {
|
return; |
return; |
} |
} |
|
|
sub create_passwd { |
|
my $passwd = ''; |
|
my @letts = ("a".."z"); |
|
for (my $i=0; $i<8; $i++) { |
|
my $lettnum = int(rand(2)); |
|
my $item = ''; |
|
if ($lettnum) { |
|
$item = $letts[int(rand(26))]; |
|
my $uppercase = int(rand(2)); |
|
if ($uppercase) { |
|
$item =~ tr/a-z/A-Z/; |
|
} |
|
} else { |
|
$item = int(rand(10)); |
|
} |
|
$passwd .= $item; |
|
} |
|
return ($passwd); |
|
} |
|
|
|
1; |
1; |