Annotation of loncom/auth/migrateuser.pm, revision 1.17

1.1       albertel    1: # The LearningOnline Network
                      2: # Starts a user off based of an existing token.
                      3: #
1.17    ! raeburn     4: # $Id: migrateuser.pm,v 1.16 2009/07/23 17:40:29 raeburn Exp $
1.1       albertel    5: #
                      6: # Copyright Michigan State University Board of Trustees
                      7: #
                      8: # This file is part of the LearningOnline Network with CAPA (LON-CAPA).
                      9: #
                     10: # LON-CAPA is free software; you can redistribute it and/or modify
                     11: # it under the terms of the GNU General Public License as published by
                     12: # the Free Software Foundation; either version 2 of the License, or
                     13: # (at your option) any later version.
                     14: #
                     15: # LON-CAPA is distributed in the hope that it will be useful,
                     16: # but WITHOUT ANY WARRANTY; without even the implied warranty of
                     17: # MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the
                     18: # GNU General Public License for more details.
                     19: #
                     20: # You should have received a copy of the GNU General Public License
                     21: # along with LON-CAPA; if not, write to the Free Software
                     22: # Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA  02111-1307  USA
                     23: #
                     24: # /home/httpd/html/adm/gpl.txt
                     25: #
                     26: # http://www.lon-capa.org/
                     27: #
                     28: 
1.2       albertel   29: package Apache::migrateuser;
1.1       albertel   30: 
                     31: use strict;
1.6       albertel   32: use LONCAPA;
1.1       albertel   33: use Apache::Constants qw(:common :http :methods);
                     34: use Apache::lonauth;
                     35: use Apache::lonnet;
1.6       albertel   36: use Apache::lonlocal;
1.1       albertel   37: 
                     38: sub goto_login {
1.2       albertel   39:     my ($r) = @_;
                     40:     &Apache::loncommon::content_type($r,'text/html');
                     41:     $r->send_http_header;
1.5       albertel   42:     $r->print(&Apache::loncommon::start_page('Going to login',undef,
                     43: 					     {'redirect' =>
                     44: 						  [0,'/adm/login'],}).
                     45: 	      '<h1>'.&mt('One moment please...').'</h1>'.
                     46: 	      '<p>'.&mt('Transferring to login page.').'</p>'.
                     47: 	      &Apache::loncommon::end_page());
1.2       albertel   48:     return OK;
1.1       albertel   49: }
                     50: 
1.2       albertel   51: 
1.7       albertel   52: sub sso_check {
                     53:     my ($data) = @_;
1.8       albertel   54:     my %extra_env;
1.7       albertel   55:     if ($data->{'sso.login'}) {
1.8       albertel   56: 	$extra_env{'request.sso.login'} = $data->{'sso.login'};
1.7       albertel   57:     }
1.10      raeburn    58:     if ($data->{'sso.reloginserver'}) {
                     59:         $extra_env{'request.sso.reloginserver'} = 
                     60:             $data->{'sso.reloginserver'};
                     61:     }
1.8       albertel   62:     return \%extra_env;
1.7       albertel   63: }
                     64: 
1.1       albertel   65: sub handler {
                     66:     my ($r) = @_;
                     67:     
                     68:     &Apache::loncommon::get_unprocessed_cgi($ENV{'QUERY_STRING'},['token']);
1.4       albertel   69:     my %data =   &Apache::lonnet::tmpget($env{'form.token'});
1.13      raeburn    70:     if (keys(%data) == 0) {
                     71:         return &goto_login($r);
                     72:     }
1.4       albertel   73:     my $delete = &Apache::lonnet::tmpdel($env{'form.token'});
                     74: 
1.6       albertel   75:     &Apache::lonlocal::get_language_handle($r);
                     76: 
1.4       albertel   77:     if ($delete ne 'ok') {
                     78: 	return &goto_login($r);
                     79:     }
1.2       albertel   80: 
                     81:     if ($data{'ip'} ne $ENV{'REMOTE_ADDR'} || !defined($data{'username'}) ||
                     82: 	!defined($data{'domain'}) ) {
                     83: 	return &goto_login($r);
                     84:     }
                     85: 
1.17    ! raeburn    86:     &Apache::lonnet::logthis("Allowing access for $data{'username'}:$data{'domain'} to $data{'role'}");
1.2       albertel   87:     my $home=&Apache::lonnet::homeserver($data{'username'},$data{'domain'});
                     88:     if ($home =~ /(con_lost|no_such_host)/) { return &goto_login($r); }
                     89: 
1.8       albertel   90:     my $extra_env = &sso_check(\%data);
                     91: 
1.16      raeburn    92:     my %form;
                     93:     if ($data{'symb'} ne '') {
                     94:         $form{'symb'} = $data{'symb'};
                     95:     }
                     96: 
1.3       albertel   97:     if (!$data{'role'}) {
1.12      albertel   98: 	my $handle = &Apache::lonnet::check_for_valid_session($r);
                     99: 	if ($handle) {
1.11      albertel  100: 	    &Apache::lonnet::transfer_profile_to_env($r->dir_config('lonIDsDir'),
                    101: 						     $handle);
1.14      raeburn   102:             if ($data{'origurl'} ne '') {
                    103:                 $r->internal_redirect($data{'origurl'});
                    104:             } elsif ($env{'request.course.id'}) {
                    105:                 $r->internal_redirect('/adm/navmaps');
1.11      albertel  106: 	    } else {
                    107: 		$r->internal_redirect('/adm/roles');
                    108: 	    }
                    109: 	} else {
1.14      raeburn   110:             my $desturl = '/adm/roles';
                    111:             if ($data{'origurl'} ne '') {
                    112:                 $desturl = $data{'origurl'};
                    113:             }
1.11      albertel  114: 	    &Apache::lonauth::success($r,$data{'username'},$data{'domain'},
1.16      raeburn   115: 				      $home,$desturl,$extra_env,\%form);
1.11      albertel  116: 
                    117: 	}
1.1       albertel  118: 	return OK;
1.11      albertel  119: 
1.1       albertel  120:     }
1.6       albertel  121: 
                    122:     my $next_url='/adm/roles?selectrole=1&amp;'.&escape($data{'role'}).'=1';
1.15      raeburn   123:     if ($data{'origurl'} ne '') {
                    124:         $next_url .= '&amp;orgurl='.&escape($data{'origurl'});
                    125:     }
1.6       albertel  126:     &Apache::lonauth::success($r,$data{'username'},$data{'domain'},$home,
1.16      raeburn   127: 			      $next_url,$extra_env,\%form);
1.6       albertel  128:     return OK;
1.1       albertel  129: }
                    130: 
                    131: 1;
                    132: __END__

FreeBSD-CVSweb <freebsd-cvsweb@FreeBSD.org>