--- loncom/auth/lonauth.pm 2022/05/21 05:16:43 1.173 +++ loncom/auth/lonauth.pm 2022/09/17 23:38:50 1.178 @@ -1,7 +1,7 @@ # The LearningOnline Network # User Authentication Module # -# $Id: lonauth.pm,v 1.173 2022/05/21 05:16:43 raeburn Exp $ +# $Id: lonauth.pm,v 1.178 2022/09/17 23:38:50 raeburn Exp $ # # Copyright Michigan State University Board of Trustees # @@ -47,7 +47,7 @@ use CGI::Cookie(); # ------------------------------------------------------------ Successful login sub success { my ($r, $username, $domain, $authhost, $lowerurl, $extra_env, - $form,$skipcritical,$cid,$expirepub) = @_; + $form,$skipcritical,$cid,$expirepub,$write_to_opener) = @_; # ------------------------------------------------------------ Get cookie ready my $cookie = @@ -147,6 +147,10 @@ sub success { $destination .= 'selectrole=1&'.$newrole.'=1'; } } + } elsif (defined($form->{display})) { + if ($destination =~ m{^/adm/email($|\?)}) { + $destination .= ($destination =~ /\?/) ? '&' : '?' .'display='.&escape($form->{display}); + } } if (defined($form->{symb})) { my $destsymb = $form->{symb}; @@ -179,11 +183,21 @@ sub success { $destination .= 'source=login'; } + my $brcrum = [{'href' => '', + 'text' => 'Successful Login'},]; + my $args = {'no_inline_link' => 1, + 'bread_crumbs' => $brcrum,}; if (($env{'request.deeplink.login'} eq $lowerurl) && (($env{'request.linkprot'}) || ($env{'request.linkkey'} ne ''))) { my %info; if ($env{'request.linkprot'}) { $info{'linkprot'} = $env{'request.linkprot'}; + foreach my $item ('linkprotuser','linkprotexit') { + if ($form->{$item}) { + $info{$item} = $form->{$item}; + } + } + $args = {'only_body' => 1,}; } elsif ($env{'request.linkkey'} ne '') { $info{'linkkey'} = $env{'request.linkkey'}; } @@ -200,9 +214,6 @@ sub success { $windowname .= 'lti'; } my $windowinfo = Apache::lonhtmlcommon::scripttag('self.name="'.$windowname.'";'); - my $brcrum = [{'href' => '', - 'text' => 'Successful Login'},]; - my $args = {'bread_crumbs' => $brcrum,}; unless ((defined($form->{role})) || (defined($form->{symb}))) { my $update=$env{'user.update.time'}; if (!$update) { @@ -273,21 +284,22 @@ ENDJS } $start_page=&Apache::loncommon::start_page('',$js,$args); } else { - $args->{'redirect'} = [0,$destination]; + $args->{'redirect'} = [0,$destination,'',$write_to_opener]; $start_page=&Apache::loncommon::start_page('Successful Login', $js,$args); - - my %lt=&Apache::lonlocal::texthash( - 'wel' => 'Welcome', - 'pro' => 'Login problems?', + unless ($env{'request.linkprot'}) { + my %lt=&Apache::lonlocal::texthash( + 'wel' => 'Welcome', + 'pro' => 'Login problems?', ); - $pagebody = "

$lt{'wel'}

\n". - &mt('Welcome to the Learning[_1]Online[_2] Network with CAPA. Please wait while your session is being set up.','',''); - my $loginhelp = &loginhelpdisplay($domain); - if ($loginhelp) { - $pagebody .= '

'.$lt{'pro'}.'

'; + $pagebody = "

$lt{'wel'}

\n". + &mt('Welcome to the Learning[_1]Online[_2] Network with CAPA. Please wait while your session is being set up.','',''); + my $loginhelp = &loginhelpdisplay($domain); + if ($loginhelp) { + $pagebody .= '

'.$lt{'pro'}.'

'; + } } - } + } $end_page = &Apache::loncommon::end_page(); $r->print(< 1}; } + if ($form->{firsturl} =~ m{^/tiny/$match_domain/\w+$}) { + if ($form->{linkprot}) { + $args->{only_body} = 1; + } + } my @actions; my $start_page = &Apache::loncommon::start_page('Unsuccessful Login',undef,$args); @@ -357,7 +374,15 @@ sub failed { } } if (exists($form->{linkprot})) { - my $ltoken = &Apache::lonnet::tmpput({linkprot => $form->{'linkprot'}}, + my %info = ( + 'linkprot' => $form->{'linkprot'}, + ); + foreach my $item ('linkprotuser','linkprotexit') { + if ($form->{$item} ne '') { + $info{$item} = $form->{$item}; + } + } + my $ltoken = &Apache::lonnet::tmpput(\%info, $r->dir_config('lonHostID'),'retry'); if ($ltoken) { $retry .= (($retry =~ /\?/) ? '&' : '?').'ltoken='.$ltoken; @@ -475,6 +500,19 @@ sub handler { .$end_page); } else { if (($info{'linkprot'}) || ($info{'linkkey'} ne '')) { + if (($info{'linkprot'}) && ($info{'linkprotuser'} ne '')) { + unless ($info{'linkprotuser'} eq $env{'user.name'}.':'.$env{'user.domain'}) { + $r->print( + $start_page + .'

'.&mt('You are already logged in, but as a different user from the one expected for the link you followed from another system').'

' + .'

'.&mt('Please [_1]log out[_2] first, and then try following the link again from the other system', + '','') + + .'

' + .$end_page); + return OK; + } + } my $token = &Apache::lonnet::tmpput(\%info,$r->dir_config('lonHostID'),'link'); unless (($token eq 'con_lost') || ($token eq 'refused') || ($token eq 'unknown_cmd') || ($token eq 'no_such_host')) { @@ -730,6 +768,18 @@ sub handler { } } + if ($form{'firsturl'} =~ m{^/tiny/$match_domain/\w+$}) { + if (($form{'linkprot'}) && ($form{'linkprotuser'} ne '')) { + unless($form{'linkprotuser'} eq $form{'uname'}.':'.$form{'udom'}) { + delete($form{'udom'}); + delete($form{'uname'}); + &failed($r,'Username and/or domain are different to that expected for the link you followed from another system', + \%form,$authhost); + return OK; + } + } + } + my ($is_balancer,$otherserver); unless ($hosthere) { @@ -773,11 +823,21 @@ sub handler { } if ($form{'linkprot'}) { $env{'request.linkprot'} = $form{'linkprot'}; + foreach my $item ('linkprotuser','linkprotexit') { + if ($form{$item}) { + $env{'request.'.$item} = $form{$item}; + } + } } elsif ($form{'linkkey'} ne '') { $env{'request.linkkey'} = $form{'linkkey'}; } if ($form{'firsturl'} =~ m{^/tiny/$match_domain/\w+$}) { &set_deeplink_login(%form); + } elsif ($firsturl eq '/adm/email') { + if ($form{'display'} && ($form{'mailrecip'} eq "$form{'uname'}:$form{'udom'}")) { + $env{'request.display'} = $form{'display'}; + $env{'request.mailrecip'} = $form{'mailrecip'}; + } } $r->internal_redirect($switchto); } else { @@ -804,11 +864,21 @@ sub handler { } if ($form{'linkprot'}) { $env{'request.linkprot'} = $form{'linkprot'}; + foreach my $item ('linkprotuser','linkprotexit') { + if ($form{$item}) { + $env{'request.'.$item} = $form{$item}; + } + } } elsif ($form{'linkkey'} ne '') { $env{'request.linkkey'} = $form{'linkkey'}; } if ($form{'firsturl'} =~ m{^/tiny/$match_domain/\w+$}) { &set_deeplink_login(%form); + } elsif ($firsturl eq '/adm/email') { + if ($form{'display'} && ($form{'mailrecip'} eq "$form{'uname'}:$form{'udom'}")) { + $env{'request.display'} = $form{'display'}; + $env{'request.mailrecip'} = $form{'mailrecip'}; + } } $r->internal_redirect($switchto); } else { @@ -848,6 +918,11 @@ sub handler { } if ($form{'firsturl'} =~ m{^/tiny/$match_domain/\w+$}) { &set_deeplink_login(%form); + } elsif ($firsturl eq '/adm/email') { + if ($form{'display'} && ($form{'mailrecip'} eq "$form{'uname'}:$form{'udom'}")) { + $env{'request.display'} = $form{'display'}; + $env{'request.mailrecip'} = $form{'mailrecip'}; + } } $r->internal_redirect('/adm/switchserver?otherserver='.$unloaded.'&origurl='.$firsturl); return OK; @@ -867,6 +942,14 @@ sub handler { $form{$item} = $sessiondata{$item}; } } + if ($sessiondata{'origurl'} eq '/adm/email') { + if (($sessiondata{'display'}) && ($sessiondata{'mailrecip'})) { + if (&unescape($sessiondata{'mailrecip'}) eq "$form{'uname'}:$form{'udom'}") { + $form{'display'} = &unescape($sessiondata{'display'}); + $form{'mailrecip'} = &unescape($sessiondata{'mailrecip'}); + } + } + } } } if ($form{'linkprot'}) { @@ -887,6 +970,9 @@ sub handler { } else { $extra_env = {'request.linkprot' => $form{'linkprot'}}; } + if ($form{'linkprotexit'}) { + $extra_env->{'request.linkprotexit'} = $form{'linkprotexit'}; + } } elsif ($form{'linkkey'} ne '') { if (ref($extra_env) eq 'HASH') { %{$extra_env} = ( %{$extra_env}, 'request.linkkey' => $form{'linkkey'} ); @@ -975,7 +1061,7 @@ sub set_retry_token { my ($form,$lonhost,$querystr) = @_; if (ref($form) eq 'HASH') { my ($firsturl,$token,$extras,@names); - @names = ('role','symb','linkprot','linkkey','iptoken'); + @names = ('role','symb','linkprotuser','linkprotexit','linkprot','linkkey','iptoken'); foreach my $name (@names) { if ($form->{$name} ne '') { $extras .= '&'.$name.'='.&escape($form->{$name}); @@ -1062,6 +1148,11 @@ sub check_can_host { $form); if ($form->{'firsturl'} =~ m{^/tiny/$match_domain/\w+$}) { $env{'request.deeplink.login'} = $form->{'firsturl'}; + } elsif ($form->{'firsturl'} eq '/adm/email') { + if ($form->{'display'} && ($form->{'mailrecip'} eq $form->{'uname'}.':'.$form->{'udom'})) { + $env{'request.display'} = $form->{'mailrecip'}; + $env{'request.mailrecip'} = $form->{'mailrecip'}; + } } if ($form->{'linkprot'}) { $env{'request.linkprot'} = $form->{'linkprot'};