--- loncom/auth/migrateuser.pm 2005/10/28 21:51:43 1.3 +++ loncom/auth/migrateuser.pm 2009/04/14 23:52:07 1.15 @@ -1,7 +1,7 @@ # The LearningOnline Network # Starts a user off based of an existing token. # -# $Id: migrateuser.pm,v 1.3 2005/10/28 21:51:43 albertel Exp $ +# $Id: migrateuser.pm,v 1.15 2009/04/14 23:52:07 raeburn Exp $ # # Copyright Michigan State University Board of Trustees # @@ -29,38 +29,54 @@ 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(< - - - Going to login - - -

One moment please...

-

- Transferring to login page. - Continue -

- - -TOLOGIN + $r->print(&Apache::loncommon::start_page('Going to login',undef, + {'redirect' => + [0,'/adm/login'],}). + '

'.&mt('One moment please...').'

'. + '

'.&mt('Transferring to login page.').'

'. + &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'}); + 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'}) ) { @@ -71,20 +87,44 @@ sub handler { 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); + if (!$data{'role'}) { - &Apache::lonauth::success($r,$data{'username'},$data{'domain'}, - $home,'/adm/roles'); + 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); + + } return OK; + + } + + my $next_url='/adm/roles?selectrole=1&'.&escape($data{'role'}).'=1'; + if ($data{'origurl'} ne '') { + $next_url .= '&orgurl='.&escape($data{'origurl'}); + } + if ($data{'symb'} ne '') { + $next_url .= '&symb='.&escape($data{'symb'}); } - my $cookie=&Apache::lonauth::success($r,$data{'username'},$data{'domain'}, - $home,'noredirect'); - $r->header_out('Set-cookie',"lonID=$cookie; path=/"); - &Apache::lonnet::transfer_profile_to_env($r->dir_config('lonIDsDir'), - $cookie); - $env{'form.selectrole'}='1'; - $env{'form.'.$data{'role'}}='1'; - return &Apache::lonroles::handler($r); + &Apache::lonauth::success($r,$data{'username'},$data{'domain'},$home, + $next_url,$extra_env); + return OK; } 1;