version 1.11, 2018/05/14 19:56:05
|
version 1.17, 2018/12/26 20:10:29
|
Line 57 sub handler {
|
Line 57 sub handler {
|
} |
} |
} |
} |
# |
# |
# Retrieve data POSTed by LTI Consumer on launch |
# Retrieve data POSTed by LTI Consumer on launch |
# |
# |
&Apache::lonacc::get_posted_cgi($r); |
&Apache::lonacc::get_posted_cgi($r); |
my $params = {}; |
my $params = {}; |
Line 205 sub handler {
|
Line 205 sub handler {
|
$mapurl = $tail; |
$mapurl = $tail; |
} else { |
} else { |
$symb = $tail; |
$symb = $tail; |
$symb =~ s{^/+}{}; |
$symb =~ s{^/}{}; |
} |
} |
} elsif ($tail =~ m{^/res/(?:$match_domain)/(?:$match_username)/.+\.(?:sequence|page)(|___\d+___.+)$}) { |
} elsif ($tail =~ m{^/res/(?:$match_domain)/(?:$match_username)/.+\.(?:sequence|page)(|___\d+___.+)$}) { |
if ($1 eq '') { |
if ($1 eq '') { |
$mapurl = $tail; |
$mapurl = $tail; |
} else { |
} else { |
$symb = $tail; |
$symb = $tail; |
$symb =~ s{^/+}{}; |
$symb =~ s{^/res/}{}; |
} |
} |
} elsif ($tail =~ m{^/($match_domain)/($match_courseid)$}) { |
} elsif ($tail =~ m{^/($match_domain)/($match_courseid)$}) { |
($urlcdom,$urlcnum) = ($1,$2); |
($urlcdom,$urlcnum) = ($1,$2); |
Line 294 sub handler {
|
Line 294 sub handler {
|
$protocol = 'https'; |
$protocol = 'https'; |
} |
} |
|
|
|
if (exists($params->{'oauth_callback'})) { |
|
$Net::OAuth::PROTOCOL_VERSION = Net::OAuth::PROTOCOL_VERSION_1_0A; |
|
} else { |
|
$Net::OAuth::PROTOCOL_VERSION = Net::OAuth::PROTOCOL_VERSION_1_0; |
|
} |
|
|
my ($itemid,$consumer_key,$secret); |
my ($itemid,$consumer_key,$secret); |
$consumer_key = $params->{'oauth_consumer_key'}; |
$consumer_key = $params->{'oauth_consumer_key'}; |
if (ref($lti_by_key{$consumer_key}) eq 'ARRAY') { |
if (ref($lti_by_key{$consumer_key}) eq 'ARRAY') { |
Line 333 sub handler {
|
Line 339 sub handler {
|
} |
} |
|
|
# |
# |
|
# Determine if a username is required from the domain |
|
# configuration for the specific LTI Consumer |
|
# |
|
|
|
if (!$lti{$itemid}{'requser'}) { |
|
if ($tail =~ m{^/tiny/($match_domain)/(\w+)$}) { |
|
foreach my $key (%{$params}) { |
|
delete($env{'form.'.$key}); |
|
} |
|
my $ltoken = &Apache::lonnet::tmpput({'linkprot' => $itemid.':'.$tail}, |
|
$lonhost); |
|
if ($ltoken) { |
|
$r->internal_redirect($tail.'?ltoken='.$ltoken); |
|
$r->set_handlers('PerlHandler'=> undef); |
|
} else { |
|
&invalid_request($r,9); |
|
} |
|
} else { |
|
&invalid_request($r,10); |
|
} |
|
return OK; |
|
} |
|
|
|
# |
# Determine if source of username matches requirement from the |
# Determine if source of username matches requirement from the |
# domain configuration for the specific LTI Consumer. |
# domain configuration for the specific LTI Consumer. |
# |
# |
Line 388 sub handler {
|
Line 418 sub handler {
|
if ($consumers{$sourcecrs} =~ /^$match_courseid$/) { |
if ($consumers{$sourcecrs} =~ /^$match_courseid$/) { |
my $crshome = &Apache::lonnet::homeserver($consumers{$sourcecrs},$cdom); |
my $crshome = &Apache::lonnet::homeserver($consumers{$sourcecrs},$cdom); |
if ($crshome =~ /(con_lost|no_host|no_such_host)/) { |
if ($crshome =~ /(con_lost|no_host|no_such_host)/) { |
&invalid_request($r,9); |
&invalid_request($r,11); |
return OK; |
return OK; |
} else { |
} else { |
$posscnum = $consumers{$sourcecrs}; |
$posscnum = $consumers{$sourcecrs}; |
Line 400 sub handler {
|
Line 430 sub handler {
|
if ($urlcnum ne '') { |
if ($urlcnum ne '') { |
if ($posscnum ne '') { |
if ($posscnum ne '') { |
if ($posscnum ne $urlcnum) { |
if ($posscnum ne $urlcnum) { |
&invalid_request($r,10); |
&invalid_request($r,12); |
return OK; |
return OK; |
} else { |
} else { |
$cnum = $posscnum; |
$cnum = $posscnum; |
Line 408 sub handler {
|
Line 438 sub handler {
|
} else { |
} else { |
my $crshome = &Apache::lonnet::homeserver($urlcnum,$cdom); |
my $crshome = &Apache::lonnet::homeserver($urlcnum,$cdom); |
if ($crshome =~ /(con_lost|no_host|no_such_host)/) { |
if ($crshome =~ /(con_lost|no_host|no_such_host)/) { |
&invalid_request($r,11); |
&invalid_request($r,13); |
return OK; |
return OK; |
} else { |
} else { |
$cnum = $urlcnum; |
$cnum = $urlcnum; |
Line 428 sub handler {
|
Line 458 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) = |
if ($params->{'roles'} =~ /,/) { |
&LONCAPA::ltiutils::get_lc_roles($params->{'roles'}, |
my @possltiroles = split(/\s*,\s*/,$params->{'roles'}); |
\@lcroleorder, |
foreach my $ltirole (@ltiroleorder) { |
$lti{$itemid}{maproles}); |
if (grep(/^\Q$ltirole\E$/,@possltiroles)) { |
if (ref($lcrolesref) eq 'ARRAY') { |
push(@ltiroles,$ltirole); |
@lcroles = @{$lcrolesref}; |
} |
|
} |
|
} 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 479 sub handler {
|
Line 490 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,14); |
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 582 sub handler {
|
Line 512 sub handler {
|
} |
} |
} |
} |
} else { |
} else { |
&invalid_request($r,13); |
&invalid_request($r,15); |
return OK; |
return OK; |
} |
} |
} else { |
} else { |
&invalid_request($r,14); |
&invalid_request($r,16); |
return OK; |
return OK; |
} |
} |
} |
} |
} else { |
} else { |
&invalid_request($r,15); |
&invalid_request($r,17); |
return OK; |
return OK; |
} |
} |
|
|
Line 613 sub handler {
|
Line 543 sub handler {
|
$symb,$cdom,$cnum,$params,\@ltiroles,$lti{$itemid},\@lcroles, |
$symb,$cdom,$cnum,$params,\@ltiroles,$lti{$itemid},\@lcroles, |
$reqcrs,$sourcecrs); |
$reqcrs,$sourcecrs); |
} else { |
} else { |
&invalid_request($r,16); |
&invalid_request($r,18); |
} |
} |
} else { |
} else { |
&invalid_request($r,17); |
&invalid_request($r,19); |
} |
} |
return OK; |
return OK; |
} |
} |
Line 702 sub handler {
|
Line 632 sub handler {
|
} |
} |
} |
} |
if ($reqrole eq '') { |
if ($reqrole eq '') { |
&invalid_request($r,18); |
&invalid_request($r,20); |
return OK; |
return OK; |
} else { |
} else { |
unless (%crsenv) { |
unless (%crsenv) { |
Line 712 sub handler {
|
Line 642 sub handler {
|
my $default_enrollment_end_date = $crsenv{'default_enrollment_end_date'}; |
my $default_enrollment_end_date = $crsenv{'default_enrollment_end_date'}; |
my $now = time; |
my $now = time; |
if ($default_enrollment_end_date && $default_enrollment_end_date <= $now) { |
if ($default_enrollment_end_date && $default_enrollment_end_date <= $now) { |
&invalid_request($r,19); |
&invalid_request($r,21); |
return OK; |
return OK; |
} elsif ($default_enrollment_start_date && $default_enrollment_start_date >$now) { |
} elsif ($default_enrollment_start_date && $default_enrollment_start_date >$now) { |
&invalid_request($r,20); |
&invalid_request($r,22); |
return OK; |
return OK; |
} else { |
} else { |
$selfenrollrole = $reqrole.'./'.$cdom.'/'.$cnum; |
$selfenrollrole = $reqrole.'./'.$cdom.'/'.$cnum; |
Line 757 sub lti_enroll {
|
Line 687 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"; |
$enrollresult = &LONCAPA::ltiutils::enrolluser($udom,$uname,$role,$cdom,$cnum,$sec, |
if (($role ne 'cc') && ($role ne 'co') && ($sec ne '')) { |
$start,$end,1); |
$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') { |
|
my (%userroles,%newrole,%newgroups); |
|
&Apache::lonnet::standard_roleprivs(\%newrole,$role,$cdom,$spec,$cnum, |
|
$area); |
|
&Apache::lonnet::set_userprivs(\%userroles,\%newrole,\%newgroups); |
|
$userroles{'user.role.'.$spec} = $start.'.'.$end; |
|
&Apache::lonnet::appenv(\%userroles,[$role,'cm']); |
|
} |
|
} |
} |
} |
} |
return $enrollresult; |
return $enrollresult; |
Line 847 sub lti_session {
|
Line 754 sub lti_session {
|
&Apache::lonauth::success($r,$uname,$udom,$uhome,'noredirect'); |
&Apache::lonauth::success($r,$uname,$udom,$uhome,'noredirect'); |
if ($symb) { |
if ($symb) { |
$env{'form.symb'} = $symb; |
$env{'form.symb'} = $symb; |
$env{'request.lti.uri'} = $symb; |
$env{'request.lti.uri'} = $tail; |
} else { |
} else { |
if ($mapurl) { |
if ($mapurl) { |
$env{'form.origurl'} = $mapurl; |
$env{'form.origurl'} = $mapurl; |
Line 990 sub invalid_request {
|
Line 897 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; |