File:  [LON-CAPA] / loncom / auth / migrateuser.pm
Revision 1.5: download - view: text, annotated - select for diffs
Wed Apr 5 22:39:55 2006 UTC (18 years, 2 months ago) by albertel
Branches: MAIN
CVS tags: HEAD
- start_page

    1: # The LearningOnline Network
    2: # Starts a user off based of an existing token.
    3: #
    4: # $Id: migrateuser.pm,v 1.5 2006/04/05 22:39:55 albertel Exp $
    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: 
   29: package Apache::migrateuser;
   30: 
   31: use strict;
   32: use Apache::Constants qw(:common :http :methods);
   33: use Apache::lonauth;
   34: use Apache::lonnet;
   35: 
   36: sub goto_login {
   37:     my ($r) = @_;
   38:     &Apache::loncommon::content_type($r,'text/html');
   39:     $r->send_http_header;
   40:     $r->print(&Apache::loncommon::start_page('Going to login',undef,
   41: 					     {'redirect' =>
   42: 						  [0,'/adm/login'],}).
   43: 	      '<h1>'.&mt('One moment please...').'</h1>'.
   44: 	      '<p>'.&mt('Transferring to login page.').'</p>'.
   45: 	      &Apache::loncommon::end_page());
   46:     return OK;
   47: }
   48: 
   49: 
   50: sub handler {
   51:     my ($r) = @_;
   52:     
   53:     &Apache::loncommon::get_unprocessed_cgi($ENV{'QUERY_STRING'},['token']);
   54:     my %data =   &Apache::lonnet::tmpget($env{'form.token'});
   55:     my $delete = &Apache::lonnet::tmpdel($env{'form.token'});
   56: 
   57:     if ($delete ne 'ok') {
   58: 	return &goto_login($r);
   59:     }
   60: 
   61:     if ($data{'ip'} ne $ENV{'REMOTE_ADDR'} || !defined($data{'username'}) ||
   62: 	!defined($data{'domain'}) ) {
   63: 	return &goto_login($r);
   64:     }
   65: 
   66:     &Apache::lonnet::logthis("Allowing access for $data{'username'}\@$data{'domain'} to $data{'role'}");
   67:     my $home=&Apache::lonnet::homeserver($data{'username'},$data{'domain'});
   68:     if ($home =~ /(con_lost|no_such_host)/) { return &goto_login($r); }
   69: 
   70:     if (!$data{'role'}) {
   71: 	&Apache::lonauth::success($r,$data{'username'},$data{'domain'},
   72: 				  $home,'/adm/roles');
   73: 	return OK;
   74:     }
   75:     
   76:     my $cookie=&Apache::lonauth::success($r,$data{'username'},$data{'domain'},
   77: 					 $home,'noredirect');
   78:     $r->header_out('Set-cookie',"lonID=$cookie; path=/");
   79:     &Apache::lonnet::transfer_profile_to_env($r->dir_config('lonIDsDir'),
   80: 					     $cookie);
   81:     $env{'form.selectrole'}='1';
   82:     $env{'form.'.$data{'role'}}='1';
   83:     return &Apache::lonroles::handler($r);
   84: }
   85: 
   86: 1;
   87: __END__

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