File:
[LON-CAPA] /
loncom /
auth /
migrateuser.pm
Revision
1.16:
download - view:
text,
annotated -
select for diffs
Thu Jul 23 17:40:29 2009 UTC (15 years, 2 months ago) by
raeburn
Branches:
MAIN
CVS tags:
version_2_9_X,
version_2_9_99_0,
version_2_9_1,
version_2_9_0,
version_2_8_99_1,
version_2_8_99_0,
version_2_10_X,
version_2_10_1,
version_2_10_0_RC2,
version_2_10_0_RC1,
version_2_10_0,
loncapaMITrelate_1,
language_hyphenation_merge,
language_hyphenation,
bz6209-base,
bz6209,
bz2851,
PRINT_INCOMPLETE_base,
PRINT_INCOMPLETE,
HEAD,
GCI_3,
GCI_2,
BZ4492-merge,
BZ4492-feature_horizontal_radioresponse,
BZ4492-feature_Support_horizontal_radioresponse,
BZ4492-Support_horizontal_radioresponse
- Bug 3987. Deep-linking.
- Preserve role and symb from query string in call to SSO authenticator.
- Propagate to migrateuser when starting session.
# The LearningOnline Network
# Starts a user off based of an existing token.
#
# $Id: migrateuser.pm,v 1.16 2009/07/23 17:40:29 raeburn Exp $
#
# Copyright Michigan State University Board of Trustees
#
# This file is part of the LearningOnline Network with CAPA (LON-CAPA).
#
# LON-CAPA is free software; you can redistribute it and/or modify
# it under the terms of the GNU General Public License as published by
# the Free Software Foundation; either version 2 of the License, or
# (at your option) any later version.
#
# LON-CAPA is distributed in the hope that it will be useful,
# but WITHOUT ANY WARRANTY; without even the implied warranty of
# MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
# GNU General Public License for more details.
#
# You should have received a copy of the GNU General Public License
# along with LON-CAPA; if not, write to the Free Software
# Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA 02111-1307 USA
#
# /home/httpd/html/adm/gpl.txt
#
# http://www.lon-capa.org/
#
package Apache::migrateuser;
use strict;
use LONCAPA;
use Apache::Constants qw(:common :http :methods);
use Apache::lonauth;
use Apache::lonnet;
use Apache::lonlocal;
sub goto_login {
my ($r) = @_;
&Apache::loncommon::content_type($r,'text/html');
$r->send_http_header;
$r->print(&Apache::loncommon::start_page('Going to login',undef,
{'redirect' =>
[0,'/adm/login'],}).
'<h1>'.&mt('One moment please...').'</h1>'.
'<p>'.&mt('Transferring to login page.').'</p>'.
&Apache::loncommon::end_page());
return OK;
}
sub sso_check {
my ($data) = @_;
my %extra_env;
if ($data->{'sso.login'}) {
$extra_env{'request.sso.login'} = $data->{'sso.login'};
}
if ($data->{'sso.reloginserver'}) {
$extra_env{'request.sso.reloginserver'} =
$data->{'sso.reloginserver'};
}
return \%extra_env;
}
sub handler {
my ($r) = @_;
&Apache::loncommon::get_unprocessed_cgi($ENV{'QUERY_STRING'},['token']);
my %data = &Apache::lonnet::tmpget($env{'form.token'});
if (keys(%data) == 0) {
return &goto_login($r);
}
my $delete = &Apache::lonnet::tmpdel($env{'form.token'});
&Apache::lonlocal::get_language_handle($r);
if ($delete ne 'ok') {
return &goto_login($r);
}
if ($data{'ip'} ne $ENV{'REMOTE_ADDR'} || !defined($data{'username'}) ||
!defined($data{'domain'}) ) {
return &goto_login($r);
}
&Apache::lonnet::logthis("Allowing access for $data{'username'}\@$data{'domain'} to $data{'role'}");
my $home=&Apache::lonnet::homeserver($data{'username'},$data{'domain'});
if ($home =~ /(con_lost|no_such_host)/) { return &goto_login($r); }
my $extra_env = &sso_check(\%data);
my %form;
if ($data{'symb'} ne '') {
$form{'symb'} = $data{'symb'};
}
if (!$data{'role'}) {
my $handle = &Apache::lonnet::check_for_valid_session($r);
if ($handle) {
&Apache::lonnet::transfer_profile_to_env($r->dir_config('lonIDsDir'),
$handle);
if ($data{'origurl'} ne '') {
$r->internal_redirect($data{'origurl'});
} elsif ($env{'request.course.id'}) {
$r->internal_redirect('/adm/navmaps');
} else {
$r->internal_redirect('/adm/roles');
}
} else {
my $desturl = '/adm/roles';
if ($data{'origurl'} ne '') {
$desturl = $data{'origurl'};
}
&Apache::lonauth::success($r,$data{'username'},$data{'domain'},
$home,$desturl,$extra_env,\%form);
}
return OK;
}
my $next_url='/adm/roles?selectrole=1&'.&escape($data{'role'}).'=1';
if ($data{'origurl'} ne '') {
$next_url .= '&orgurl='.&escape($data{'origurl'});
}
&Apache::lonauth::success($r,$data{'username'},$data{'domain'},$home,
$next_url,$extra_env,\%form);
return OK;
}
1;
__END__
FreeBSD-CVSweb <freebsd-cvsweb@FreeBSD.org>