version 1.1, 2017/12/06 01:53:56
|
version 1.7, 2018/03/23 18:08:45
|
Line 36 use Apache::lonlocal;
|
Line 36 use Apache::lonlocal;
|
use Apache::lonnet; |
use Apache::lonnet; |
use Apache::loncommon; |
use Apache::loncommon; |
use Apache::lonacc; |
use Apache::lonacc; |
|
use Apache::lonrequestcourse; |
|
use LONCAPA::ltiutils; |
|
|
sub handler { |
sub handler { |
my $r = shift; |
my $r = shift; |
Line 141 sub handler {
|
Line 143 sub handler {
|
# (b) from tail of requested URL (after /adm/lti) if it has format of a symb |
# (b) from tail of requested URL (after /adm/lti) if it has format of a symb |
# (c) from tail of requested URL (after /adm/lti) if it has format of a map |
# (c) from tail of requested URL (after /adm/lti) if it has format of a map |
# (d) from tail of requested URL (after /adm/lti) if it has format /domain/courseID |
# (d) from tail of requested URL (after /adm/lti) if it has format /domain/courseID |
# (e) from tail of requested URL (after /adm/lti) if it has format /tiny/domain/... |
# (e) from tail of requested URL (after /adm/lti) if it has format /tiny/domain/\w+ |
# i.e., a shortened URL (see bug #6400) -- not implemented yet. |
# i.e., a shortened URL (see bug #6400). |
# (f) same as user's domain |
# (f) same as user's domain |
# |
# |
# Request invalid if custom_coursedomain is defined and is inconsistent with |
# Request invalid if custom_coursedomain is defined and is inconsistent with |
Line 180 sub handler {
|
Line 182 sub handler {
|
$symb = $tail; |
$symb = $tail; |
$symb =~ s{^/+}{}; |
$symb =~ s{^/+}{}; |
} |
} |
#FIXME Need to handle encrypted URLs |
|
} elsif ($tail =~ m{^/($match_domain)/($match_courseid)$}) { |
} elsif ($tail =~ m{^/($match_domain)/($match_courseid)$}) { |
($urlcdom,$urlcnum) = ($1,$2); |
($urlcdom,$urlcnum) = ($1,$2); |
if (($cdom ne '') && ($cdom ne $urlcdom)) { |
if (($cdom ne '') && ($cdom ne $urlcdom)) { |
&invalid_request($r,4); |
&invalid_request($r,4); |
return OK; |
return OK; |
} |
} |
|
} elsif ($tail =~ m{^/tiny/($match_domain)/(\w+)$}) { |
|
($urlcdom,my $key) = ($1,$2); |
|
if (($cdom ne '') && ($cdom ne $urlcdom)) { |
|
&invalid_request($r,5); |
|
return OK; |
|
} |
|
my $tinyurl; |
|
my ($result,$cached)=&Apache::lonnet::is_cached_new('tiny',$urlcdom."\0".$key); |
|
if (defined($cached)) { |
|
$tinyurl = $result; |
|
} else { |
|
my $configuname = &Apache::lonnet::get_domainconfiguser($urlcdom); |
|
my %currtiny = &Apache::lonnet::get('tiny',[$key],$urlcdom,$configuname); |
|
if ($currtiny{$key} ne '') { |
|
$tinyurl = $currtiny{$key}; |
|
&Apache::lonnet::do_cache_new('tiny',$urlcdom."\0".$key,$currtiny{$key},600); |
|
} |
|
} |
|
if ($tinyurl ne '') { |
|
$urlcnum = (split(/\&/,$tinyurl))[0]; |
|
} |
} |
} |
if (($cdom eq '') && ($urlcdom ne '')) { |
if (($cdom eq '') && ($urlcdom ne '')) { |
my $cprimary_id = &Apache::lonnet::domain($urlcdom,'primary'); |
my $cprimary_id = &Apache::lonnet::domain($urlcdom,'primary'); |
Line 216 sub handler {
|
Line 238 sub handler {
|
|
|
my %lti = &Apache::lonnet::get_domain_lti($cdom,'provider'); |
my %lti = &Apache::lonnet::get_domain_lti($cdom,'provider'); |
unless (keys(%lti) > 0) { |
unless (keys(%lti) > 0) { |
&invalid_request($r,5); |
&invalid_request($r,6); |
return OK; |
return OK; |
} |
} |
my %lti_by_key; |
my %lti_by_key; |
Line 240 sub handler {
|
Line 262 sub handler {
|
$protocol = 'https'; |
$protocol = 'https'; |
} |
} |
|
|
my $itemid; |
my ($itemid,$consumer_key,$secret); |
my $key = $params->{'oauth_consumer_key'}; |
$consumer_key = $params->{'oauth_consumer_key'}; |
my @ltiroles; |
if (ref($lti_by_key{$consumer_key}) eq 'ARRAY') { |
if (ref($lti_by_key{$key}) eq 'ARRAY') { |
foreach my $id (@{$lti_by_key{$consumer_key}}) { |
foreach my $id (@{$lti_by_key{$key}}) { |
|
if (ref($lti{$id}) eq 'HASH') { |
if (ref($lti{$id}) eq 'HASH') { |
my $secret = $lti{$id}{'secret'}; |
$secret = $lti{$id}{'secret'}; |
my $request = Net::OAuth->request('request token')->from_hash($params, |
my $request = Net::OAuth->request('request token')->from_hash($params, |
request_url => $protocol.'://'.$hostname.$requri, |
request_url => $protocol.'://'.$hostname.$requri, |
request_method => $env{'request.method'}, |
request_method => $env{'request.method'}, |
Line 265 sub handler {
|
Line 286 sub handler {
|
# configuration in LON-CAPA for that LTI Consumer. |
# configuration in LON-CAPA for that LTI Consumer. |
# |
# |
unless (($itemid) && (ref($lti{$itemid}) eq 'HASH')) { |
unless (($itemid) && (ref($lti{$itemid}) eq 'HASH')) { |
&invalid_request($r,6); |
&invalid_request($r,7); |
return OK; |
return OK; |
} |
} |
|
|
Line 273 sub handler {
|
Line 294 sub handler {
|
# Determine if nonce in POSTed data has expired. |
# Determine if nonce in POSTed data has expired. |
# If unexpired, confirm it has not already been used. |
# If unexpired, confirm it has not already been used. |
# |
# |
unless (&check_nonce($r,$params->{'oauth_nonce'},$params->{'oauth_timestamp'},$lti{$itemid}{'lifetime'},$cdom)) { |
unless (&LONCAPA::ltiutils::check_nonce($params->{'oauth_nonce'},$params->{'oauth_timestamp'}, |
&invalid_request($r,7); |
$lti{$itemid}{'lifetime'},$cdom,$r->dir_config('lonLTIDir'))) { |
|
&invalid_request($r,8); |
return OK; |
return OK; |
} |
} |
|
|
# |
# |
# Determinine 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 310 sub handler {
|
Line 332 sub handler {
|
# (b) from tail of requested URL (after /adm/lti) if it has format of a symb |
# (b) from tail of requested URL (after /adm/lti) if it has format of a symb |
# (c) from tail of requested URL (after /adm/lti) if it has format of a map |
# (c) from tail of requested URL (after /adm/lti) if it has format of a map |
# (d) from tail of requested URL (after /adm/lti) if it has format /domain/courseID |
# (d) from tail of requested URL (after /adm/lti) if it has format /domain/courseID |
# (e) from tail of requested URL (after /adm/lti) if it has format /tiny/domain/... |
# (e) from tail of requested URL (after /adm/lti) if it has format /tiny/domain/\w+ |
# i.e., a shortened URL (see bug #6400) -- not implemented yet. |
# i.e., a shortened URL (see bug #6400). |
# |
# |
# If Consumer course included in POSTed data points as a target course which |
# If Consumer course included in POSTed data points as a target course which |
# has a format which matches a LON-CAPA courseID, but the course does not |
# has a format which matches a LON-CAPA courseID, but the course does not |
Line 334 sub handler {
|
Line 356 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,8); |
&invalid_request($r,9); |
return OK; |
return OK; |
} else { |
} else { |
$posscnum = $consumers{$sourcecrs}; |
$posscnum = $consumers{$sourcecrs}; |
Line 346 sub handler {
|
Line 368 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,9); |
&invalid_request($r,10); |
return OK; |
return OK; |
} else { |
} else { |
$cnum = $posscnum; |
$cnum = $posscnum; |
Line 354 sub handler {
|
Line 376 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,10); |
&invalid_request($r,11); |
return OK; |
return OK; |
} else { |
} else { |
$cnum = $urlcnum; |
$cnum = $urlcnum; |
Line 365 sub handler {
|
Line 387 sub handler {
|
} |
} |
|
|
# |
# |
# Get LON-CAPA role to use from role-mapping of Consumer roles |
# Get LON-CAPA role(s) to use from role-mapping of Consumer roles |
# defined in domain configuration for the appropriate LTI |
# defined in domain configuration for the appropriate LTI |
# Consumer. |
# Consumer. |
# |
# |
# If multiple LON-CAPA roles are indicated, choose based |
# If multiple LON-CAPA roles are indicated for the current user, |
# on the order: cc, in, ta, ep, st |
# ordering (from first to last) is: cc/co, in, ta, ep, st. |
# |
# |
|
|
my $reqrole; |
my (@ltiroles,@lcroles); |
|
|
my @roleorder = ('cc','in','ta','ep','st'); |
my @lcroleorder = ('cc','in','ta','ep','st'); |
|
my @ltiroleorder = ('Instructor','TeachingAssistant','Mentor','Learner'); |
if ($params->{'roles'} =~ /,/) { |
if ($params->{'roles'} =~ /,/) { |
@ltiroles = split(/\s*,\s*/,$params->{'role'}); |
my @possltiroles = split(/\s*,\s*/,$params->{'role'}); |
|
foreach my $ltirole (@ltiroleorder) { |
|
if (grep(/^\Q$ltirole\E$/,@possltiroles)) { |
|
push(@ltiroles,$ltirole); |
|
} |
|
} |
} else { |
} else { |
my $singlerole = $params->{'roles'}; |
my $singlerole = $params->{'roles'}; |
$singlerole =~ s/^\s|\s+$//g; |
$singlerole =~ s/^\s|\s+$//g; |
@ltiroles = ($singlerole); |
if (grep(/^\Q$singlerole\E$/,@ltiroleorder)) { |
|
@ltiroles = ($singlerole); |
|
} |
} |
} |
if (@ltiroles) { |
if (@ltiroles) { |
if (ref($lti{$itemid}{maproles}) eq 'HASH') { |
if (ref($lti{$itemid}{maproles}) eq 'HASH') { |
my %possroles; |
my %possroles; |
map { $possroles{$lti{$itemid}{maproles}{$_}} = 1; } @ltiroles; |
map { $possroles{$lti{$itemid}{maproles}{$_}} = 1; } @ltiroles; |
my @possibles = keys(%possroles); |
if (keys(%possroles) > 0) { |
if (@possibles == 1) { |
foreach my $item (@lcroleorder) { |
if (grep(/^\Q$possibles[0]\E$/,@roleorder)) { |
|
$reqrole = $possibles[0]; |
|
|
|
} |
|
} elsif (@possibles > 1) { |
|
foreach my $item (@roleorder) { |
|
if ($possroles{$item}) { |
if ($possroles{$item}) { |
$reqrole = $item; |
push(@lcroles,$item); |
last; |
|
} |
} |
} |
} |
} |
} |
Line 418 sub handler {
|
Line 441 sub handler {
|
foreach my $ltirole (@ltiroles) { |
foreach my $ltirole (@ltiroles) { |
if (grep(/^\Q$ltirole\E$/,@{$lti{$itemid}{'makeuser'}})) { |
if (grep(/^\Q$ltirole\E$/,@{$lti{$itemid}{'makeuser'}})) { |
$selfcreate = 1; |
$selfcreate = 1; |
|
last; |
} |
} |
} |
} |
} |
} |
} |
} |
if ($selfcreate) { |
if ($selfcreate) { |
#FIXME Do user creation here. |
my (%rulematch,%inst_results,%curr_rules,%got_rules,%alerts,%info); |
return OK |
my $checkhash = { "$uname:$udom" => { 'newuser' => 1, }, }; |
|
my $checks = { 'username' => 1, }; |
|
&Apache::loncommon::user_rule_check($checkhash,$checks,\%alerts,\%rulematch, |
|
\%inst_results,\%curr_rules,\%got_rules); |
|
my ($userchkmsg,$lcauth,$lcauthparm); |
|
my $allowed = 1; |
|
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 = |
|
&Apache::lonnet::modifyuser($udom,$uname,$info{'id'}, |
|
$lcauth,$lcauthparm,$info{'firstname'}, |
|
$info{'middlename'},$info{'lastname'}, |
|
$info{'generation'},undef,undef, |
|
$info{'permanentemail'},$info{'inststatus'}); |
|
if ($result eq 'ok') { |
|
if (($ltiroles[0] eq 'Instructor') && ($lcroles[0] eq 'cc') && ($lti{$itemid}{'mapcrs'}) && |
|
($lti{$itemid}{'makecrs'})) { |
|
unless (&Apache::lonnet::usertools_access($uname,$udom,'lti','reload','requestcourses')) { |
|
&Apache::lonnet::put('environment',{ 'requestcourses.lti' => 1, },$udom,$uname); |
|
} |
|
} |
|
} else { |
|
&invalid_request($r,13); |
|
return OK; |
|
} |
} else { |
} else { |
&invalid_request($r,11); |
&invalid_request($r,14); |
return OK; |
return OK; |
} |
} |
} |
} |
} else { |
} else { |
&invalid_request($r,12); |
&invalid_request($r,15); |
return OK; |
return OK; |
} |
} |
|
|
# |
# |
# If no LON-CAPA course available, check if domain's configuration |
# If no LON-CAPA course available, check if domain's configuration |
# for the specific LTI Consumer allows a new course to be created |
# for the specific LTI Consumer allows a new course to be created |
# (requires role in Consumer to be: Instructor). |
# (requires role in Consumer to be: Instructor and Instructor to map to CC) |
# |
# |
|
|
|
my $reqcrs; |
if ($cnum eq '') { |
if ($cnum eq '') { |
if ((@ltiroles) && (grep(/^Instructor$/,@ltiroles)) && |
if ((@ltiroles) && ($lti{$itemid}{'mapcrs'}) && |
($lti{$itemid}{'mapcrs'})) { |
($ltiroles[0] eq 'Instructor') && ($lcroles[0] eq 'cc') && ($lti{$itemid}{'makecrs'})) { |
#FIXME Create a new LON-CAPA course here. |
my (%can_request,%request_domains); |
return OK; |
&Apache::lonnet::check_can_request($cdom,\%can_request,\%request_domains,$uname,$udom); |
|
if ($can_request{'lti'}) { |
|
$reqcrs = 1; |
|
<i_session($r,$itemid,$uname,$udom,$uhome,$lonhost,undef,$mapurl,$tail, |
|
$symb,$cdom,$cnum,$params,\@ltiroles,$lti{$itemid},\@lcroles, |
|
$reqcrs,$sourcecrs); |
|
} else { |
|
&invalid_request($r,16); |
|
} |
} else { |
} else { |
&invalid_request($r,13); |
&invalid_request($r,17); |
return OK; |
|
} |
} |
|
return OK; |
} |
} |
|
|
# |
# |
Line 457 sub handler {
|
Line 594 sub handler {
|
# indicated is cc, change role indicated to co. |
# indicated is cc, change role indicated to co. |
# |
# |
|
|
if ($reqrole eq 'cc') { |
my %crsenv; |
|
if ($lcroles[0] eq 'cc') { |
if (($cdom ne '') && ($cnum ne '')) { |
if (($cdom ne '') && ($cnum ne '')) { |
my %crsenv = &Apache::lonnet::coursedescription($cnum.'_'.$cdom,{ 'one_time' => 1,}); |
%crsenv = &Apache::lonnet::coursedescription($cdom.'_'.$cnum,{ 'one_time' => 1,}); |
if ($crsenv{'type'} eq 'Community') { |
if ($crsenv{'type'} eq 'Community') { |
$reqrole = 'co'; |
$lcroles[0] = 'co'; |
} |
} |
} |
} |
} |
} |
|
|
# |
# |
# Determine if user has required LON-CAPA role |
# Determine if user has a LON-CAPA role in the mapped LON-CAPA course. |
# in the mapped LON-CAPA course. |
# If multiple LON-CAPA roles are available for the user's assigned LTI roles, |
|
# choose the first available LON-CAPA role in the order: cc/co, in, ta, ep, st |
# |
# |
|
|
my $role; |
my ($role,$usec,$withsec); |
my %crsroles = &Apache::lonnet::get_my_roles($uname,$udom,'userroles',undef,[$reqrole],[$cdom]); |
unless ((($lcroles[0] eq 'cc') || ($lcroles[0] eq 'co')) && (@lcroles == 1)) { |
if (exists($crsroles{$cnum.':'.$cdom.':'.$reqrole})) { |
if ($lti{$itemid}{'section'} ne '') { |
$role = $reqrole.'./'.$cdom.'/'.$cnum; |
if ($lti{$itemid}{'section'} eq 'course_section_sourcedid') { |
#FIXME Need to accommodate sections |
if ($env{'form.course_section_sourcedid'} !~ /\W/) { |
} elsif (ref($lti{$itemid}{'selfenroll'}) eq 'ARRAY') { |
$usec = $env{'form.course_section_sourcedid'}; |
if (grep(/^\Q$reqrole\E$/,@{$lti{$itemid}{'selfenroll'}})) { |
} |
#FIXME Do self-enrollment here |
} elsif ($env{'form.'.$lti{$itemid}{'section'}} !~ /\W/) { |
|
$usec = $env{'form.'.$lti{$itemid}{'section'}}; |
|
} |
|
} |
|
if ($usec ne '') { |
|
$withsec = 1; |
|
} |
|
} |
|
|
|
if (@lcroles) { |
|
my %crsroles = &Apache::lonnet::get_my_roles($uname,$udom,'userroles',undef,\@lcroles, |
|
[$cdom],$withsec); |
|
foreach my $reqrole (@lcroles) { |
|
if ($withsec) { |
|
my $incsec; |
|
if (($reqrole eq 'cc') || ($reqrole eq 'co')) { |
|
$incsec = ''; |
|
} else { |
|
$incsec = $usec; |
|
} |
|
if (exists($crsroles{$cnum.':'.$cdom.':'.$reqrole.':'.$incsec})) { |
|
$role = $reqrole.'./'.$cdom.'/'.$cnum; |
|
if ($incsec ne '') { |
|
$role .= '/'.$usec; |
|
} |
|
last; |
|
} |
|
} else { |
|
if (exists($crsroles{$cnum.':'.$cdom.':'.$reqrole})) { |
|
$role = $reqrole.'./'.$cdom.'/'.$cnum; |
|
last; |
|
} |
|
} |
|
} |
|
} |
|
|
|
# |
|
# Determine if user can selfenroll |
|
# |
|
|
|
my ($reqrole,$selfenrollrole); |
|
if ($role eq '') { |
|
if ((@ltiroles) && (ref($lti{$itemid}{'selfenroll'}) eq 'ARRAY')) { |
|
foreach my $ltirole (@ltiroles) { |
|
if (grep(/^\Q$ltirole\E$/,@{$lti{$itemid}{'selfenroll'}})) { |
|
if (ref($lti{$itemid}{maproles}) eq 'HASH') { |
|
$reqrole = $lti{$itemid}{maproles}{$ltirole}; |
|
last; |
|
} |
|
} |
|
} |
|
} |
|
if ($reqrole eq '') { |
|
&invalid_request($r,18); |
return OK; |
return OK; |
} else { |
} else { |
&invalid_request($r,14); |
unless (%crsenv) { |
|
%crsenv = &Apache::lonnet::coursedescription($cdom.'_'.$cnum); |
|
} |
|
my $default_enrollment_start_date = $crsenv{'default_enrollment_start_date'}; |
|
my $default_enrollment_end_date = $crsenv{'default_enrollment_end_date'}; |
|
my $now = time; |
|
if ($default_enrollment_end_date && $default_enrollment_end_date <= $now) { |
|
&invalid_request($r,19); |
|
return OK; |
|
} elsif ($default_enrollment_start_date && $default_enrollment_start_date >$now) { |
|
&invalid_request($r,20); |
|
return OK; |
|
} else { |
|
$selfenrollrole = $reqrole.'./'.$cdom.'/'.$cnum; |
|
if (($withsec) && ($reqrole ne 'cc') && ($reqrole ne 'co')) { |
|
if ($usec ne '') { |
|
$selfenrollrole .= '/'.$usec; |
|
} |
|
} |
|
} |
} |
} |
} |
} |
|
|
# |
# |
# Store consumer-to-LON-CAPA course mapping |
# Store consumer-to-LON-CAPA course mapping |
# |
# |
|
|
if (($sourcecrs ne '') && ($consumers{$sourcecrs} eq '') && ($cnum ne '')) { |
if (($sourcecrs ne '') && ($consumers{$sourcecrs} eq '') && ($cnum ne '')) { |
&Apache::lonnet::put_dom('lticonsumers',{ $sourcecrs => $cnum },$cdom); |
&Apache::lonnet::put_dom('lticonsumers',{ $sourcecrs => $cnum },$cdom); |
} |
} |
|
|
# |
# |
# Check if user should be hosted here or switched to another server. |
# Start user session |
# |
# |
|
|
&Apache::lonnet::logthis(" LTI authorized user: $uname:$udom role: $role course: $cnum:$cdom"); |
<i_session($r,$itemid,$uname,$udom,$uhome,$lonhost,$role,$mapurl,$tail,$symb, |
|
$cdom,$cnum,$params,\@ltiroles,$lti{$itemid},\@lcroles,undef,$sourcecrs, |
|
$selfenrollrole); |
|
return OK; |
|
} |
|
|
|
sub lti_enroll { |
|
my ($uname,$udom,$selfenrollrole) = @_; |
|
my $enrollresult; |
|
my ($role,$cdom,$cnum,$sec) = |
|
($selfenrollrole =~ m{^(\w+)\./($match_domain)/($match_courseid)(?:|/(\w*))$}); |
|
if (($cnum ne '') && ($cdom ne '')) { |
|
my $chome = &Apache::lonnet::homeserver($cnum,$cdom); |
|
if ($chome ne 'no_host') { |
|
my %coursehash = &Apache::lonnet::coursedescription($cdom.'_'.$cnum); |
|
my $start = $coursehash{'default_enrollment_start_date'}; |
|
my $end = $coursehash{'default_enrollment_end_date'}; |
|
my $area = "/$cdom/$cnum"; |
|
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') { |
|
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; |
|
} |
|
|
|
sub lti_reqcrs { |
|
my ($r,$cdom,$form,$uname,$udom) = @_; |
|
my (%can_request,%request_domains); |
|
&Apache::lonnet::check_can_request($cdom,\%can_request,\%request_domains,$uname,$udom); |
|
if ($can_request{'lti'}) { |
|
my %domconfig = &Apache::lonnet::get_dom('configuration',['requestcourses'],$cdom); |
|
my %domdefs = &Apache::lonnet::get_domain_defaults($cdom); |
|
&Apache::lonrequestcourse::print_textbook_form($r,$cdom,[$cdom],\%domdefs, |
|
$domconfig{'requestcourses'}, |
|
\%can_request,'lti',$form); |
|
} else { |
|
$r->print( |
|
&Apache::loncommon::start_page('Invalid LTI call',undef,{'only_body' => 1}). |
|
&mt('Invalid LTI call'). |
|
&Apache::loncommon::end_page() |
|
); |
|
} |
|
} |
|
|
|
sub lti_session { |
|
my ($r,$itemid,$uname,$udom,$uhome,$lonhost,$role,$mapurl,$tail,$symb,$cdom,$cnum, |
|
$params,$ltiroles,$ltihash,$lcroles,$reqcrs,$sourcecrs,$selfenrollrole) = @_; |
|
return unless ((ref($params) eq 'HASH') && (ref($ltiroles) eq 'ARRAY') && |
|
(ref($ltihash) eq 'HASH') && (ref($lcroles) eq 'ARRAY')); |
|
# |
|
# Check if user should be hosted here or switched to another server. |
|
# |
$r->user($uname); |
$r->user($uname); |
|
if ($cnum) { |
|
if ($role) { |
|
&Apache::lonnet::logthis(" LTI authorized user ($itemid): $uname:$udom, role: $role, course: $cdom\_$cnum"); |
|
} elsif ($selfenrollrole =~ m{^(\w+)\./$cdom/$cnum}) { |
|
&Apache::lonnet::logthis(" LTI authorized user ($itemid): $uname:$udom, desired role: $1 course: $cdom\_$cnum"); |
|
} |
|
} else { |
|
&Apache::lonnet::logthis(" LTI authorized user ($itemid): $uname:$udom, course dom: $cdom"); |
|
} |
my ($is_balancer,$otherserver,$hosthere); |
my ($is_balancer,$otherserver,$hosthere); |
($is_balancer,$otherserver) = |
($is_balancer,$otherserver) = |
&Apache::lonnet::check_loadbalancing($uname,$udom,'login'); |
&Apache::lonnet::check_loadbalancing($uname,$udom,'login'); |
Line 521 sub handler {
|
Line 815 sub handler {
|
&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; |
|
} else { |
|
if ($mapurl) { |
|
$env{'form.origurl'} = $mapurl; |
|
} elsif ($tail =~ m{^\Q/tiny/$cdom/\E\w+$}) { |
|
$env{'form.origurl'} = $tail; |
|
} else { |
|
unless ($tail eq '/adm/roles') { |
|
$env{'form.origurl'} = '/adm/navmaps'; |
|
} |
|
} |
} |
} |
if ($role) { |
if ($role) { |
$env{'form.role'} = $role; |
$env{'form.role'} = $role; |
} |
} |
if ($lti{$itemid}{'passback'}) { |
if (($lcroles->[0] eq 'cc') && ($reqcrs)) { |
|
$env{'request.lti.reqcrs'} = 1; |
|
$env{'request.lti.reqrole'} = 'cc'; |
|
$env{'request.lti.sourcecrs'} = $sourcecrs; |
|
} |
|
if ($selfenrollrole) { |
|
$env{'request.lti.selfenroll'} = $selfenrollrole; |
|
$env{'request.lti.sourcecrs'} = $sourcecrs; |
|
} |
|
if ($ltihash->{'passback'}) { |
if ($params->{'lis_result_sourcedid'}) { |
if ($params->{'lis_result_sourcedid'}) { |
$env{'request.lti.passbackid'} = $params->{'lis_result_sourcedid'}; |
$env{'request.lti.passbackid'} = $params->{'lis_result_sourcedid'}; |
} |
} |
Line 533 sub handler {
|
Line 846 sub handler {
|
$env{'request.lti.passbackurl'} = $params->{'lis_outcome_service_url'}; |
$env{'request.lti.passbackurl'} = $params->{'lis_outcome_service_url'}; |
} |
} |
} |
} |
if (($lti{$itemid}{'roster'}) && (grep(/^Instructor$/,@ltiroles))) { |
if (($ltihash->{'roster'}) && (grep(/^Instructor$/,@{$ltiroles}))) { |
if ($params->{'ext_ims_lis_memberships_id'}) { |
if ($params->{'ext_ims_lis_memberships_id'}) { |
$env{'request.lti.rosterid'} = $params->{'ext_ims_lis_memberships_id'}; |
$env{'request.lti.rosterid'} = $params->{'ext_ims_lis_memberships_id'}; |
} |
} |
if ($params->{'ext_ims_lis_memberships_url'}) { |
if ($params->{'ext_ims_lis_memberships_url'}) { |
$env{'request.lti.rosterurl'} = $params->{'ext_ims_lis_memberships_url'}; |
$env{'request.lti.rosterurl'} = $params->{'ext_ims_lis_memberships_url'}; |
Line 568 sub handler {
|
Line 881 sub handler {
|
$info{'role'} = $role; |
$info{'role'} = $role; |
} |
} |
if ($symb) { |
if ($symb) { |
$info{'symb'} = $symb; |
$info{'symb'} = $symb; |
|
} |
|
if (($lcroles->[0] eq 'cc') && ($reqcrs)) { |
|
$info{'lti.reqcrs'} = 1; |
|
$info{'lti.reqrole'} = 'cc'; |
|
$info{'lti.sourcecrs'} = $sourcecrs; |
} |
} |
if ($lti{$itemid}{'passback'}) { |
if ($selfenrollrole) { |
|
$info{'lti.selfenrollrole'} = $selfenrollrole; |
|
} |
|
if ($ltihash->{'passback'}) { |
if ($params->{'lis_result_sourcedid'}) { |
if ($params->{'lis_result_sourcedid'}) { |
$info{'lti.passbackid'} = $params->{'lis_result_sourcedid'} |
$info{'lti.passbackid'} = $params->{'lis_result_sourcedid'} |
} |
} |
Line 578 sub handler {
|
Line 899 sub handler {
|
$info{'lti.passbackurl'} = $params->{'lis_outcome_service_url'} |
$info{'lti.passbackurl'} = $params->{'lis_outcome_service_url'} |
} |
} |
} |
} |
if (($lti{$itemid}{'roster'}) && (grep(/^Instructor$/,@ltiroles))) { |
if (($ltihash->{'roster'}) && (grep(/^Instructor$/,@{$ltiroles}))) { |
if ($params->{'ext_ims_lis_memberships_id'}) { |
if ($params->{'ext_ims_lis_memberships_id'}) { |
$info{'lti.rosterid'} = $params->{'ext_ims_lis_memberships_id'}; |
$info{'lti.rosterid'} = $params->{'ext_ims_lis_memberships_id'}; |
} |
} |
Line 589 sub handler {
|
Line 910 sub handler {
|
unless ($info{'symb'}) { |
unless ($info{'symb'}) { |
if ($mapurl) { |
if ($mapurl) { |
$info{'origurl'} = $mapurl; |
$info{'origurl'} = $mapurl; |
if ($mapurl =~ m{/default_\d+\.sequence$}) { |
} elsif ($tail =~ m{^\Q/tiny/$cdom/\E\w+$}) { |
$info{'origurl'} .= (($mapurl =~/\?/)?'&':'?').'navmap=1'; |
$info{'origurl'} = $tail; |
} |
|
} else { |
} else { |
unless ($tail eq '/adm/roles') { |
unless ($tail eq '/adm/roles') { |
$info{'origurl'} = '/adm/navmaps'; |
$info{'origurl'} = '/adm/navmaps'; |
Line 606 sub handler {
|
Line 926 sub handler {
|
$r->internal_redirect('/adm/migrateuser'); |
$r->internal_redirect('/adm/migrateuser'); |
$r->set_handlers('PerlHandler'=> undef); |
$r->set_handlers('PerlHandler'=> undef); |
} |
} |
return OK; |
return; |
} |
|
|
|
sub check_nonce { |
|
my ($r,$nonce,$timestamp,$lifetime,$domain) = @_; |
|
if (($timestamp eq '') || ($timestamp =~ /^\D/) || ($lifetime eq '') || ($lifetime =~ /\D/) || ($domain eq '')) { |
|
return 0; |
|
} |
|
my $now = time; |
|
if (($timestamp) && ($timestamp < ($now - $lifetime))) { |
|
return 0; |
|
} |
|
if ($nonce eq '') { |
|
return 0; |
|
} |
|
my $lonltidir = $r->dir_config('lonLTIDir'); |
|
if (-e "$lonltidir/$domain/$nonce") { |
|
return 0; |
|
} else { |
|
unless (-e "$lonltidir/$domain") { |
|
mkdir("$lonltidir/$domain",0755); |
|
} |
|
if (open(my $fh,'>',"$lonltidir/$domain/$nonce")) { |
|
print $fh $now; |
|
close($fh); |
|
} else { |
|
return 0; |
|
} |
|
} |
|
return 1; |
|
} |
} |
|
|
sub invalid_request { |
sub invalid_request { |
Line 653 sub invalid_request {
|
Line 944 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; |