File:  [LON-CAPA] / loncom / auth / migrateuser.pm
Revision 1.15: download - view: text, annotated - select for diffs
Tue Apr 14 23:52:07 2009 UTC (15 years, 2 months ago) by raeburn
Branches: MAIN
CVS tags: bz5969, HEAD, BZ5971-printing-apage, BZ5434-fox
- HTML documents uploaded directly to a course can be edited by a Course Coordinator (mdc priv).
- "Edit this resource" link displayed in inline menu.
- Link will switch server to course's home server if session is currently hoosted elsewehere (unless a lock is in place).

- Deep linking:
  - origurl and symb args can be included in query string for switchserver call, so switched session will go to the same resource on the new server.

Work in progress.
Logging needed: changes, and by whom.

    1: # The LearningOnline Network
    2: # Starts a user off based of an existing token.
    3: #
    4: # $Id: migrateuser.pm,v 1.15 2009/04/14 23:52:07 raeburn 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 LONCAPA;
   33: use Apache::Constants qw(:common :http :methods);
   34: use Apache::lonauth;
   35: use Apache::lonnet;
   36: use Apache::lonlocal;
   37: 
   38: sub goto_login {
   39:     my ($r) = @_;
   40:     &Apache::loncommon::content_type($r,'text/html');
   41:     $r->send_http_header;
   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());
   48:     return OK;
   49: }
   50: 
   51: 
   52: sub sso_check {
   53:     my ($data) = @_;
   54:     my %extra_env;
   55:     if ($data->{'sso.login'}) {
   56: 	$extra_env{'request.sso.login'} = $data->{'sso.login'};
   57:     }
   58:     if ($data->{'sso.reloginserver'}) {
   59:         $extra_env{'request.sso.reloginserver'} = 
   60:             $data->{'sso.reloginserver'};
   61:     }
   62:     return \%extra_env;
   63: }
   64: 
   65: sub handler {
   66:     my ($r) = @_;
   67:     
   68:     &Apache::loncommon::get_unprocessed_cgi($ENV{'QUERY_STRING'},['token']);
   69:     my %data =   &Apache::lonnet::tmpget($env{'form.token'});
   70:     if (keys(%data) == 0) {
   71:         return &goto_login($r);
   72:     }
   73:     my $delete = &Apache::lonnet::tmpdel($env{'form.token'});
   74: 
   75:     &Apache::lonlocal::get_language_handle($r);
   76: 
   77:     if ($delete ne 'ok') {
   78: 	return &goto_login($r);
   79:     }
   80: 
   81:     if ($data{'ip'} ne $ENV{'REMOTE_ADDR'} || !defined($data{'username'}) ||
   82: 	!defined($data{'domain'}) ) {
   83: 	return &goto_login($r);
   84:     }
   85: 
   86:     &Apache::lonnet::logthis("Allowing access for $data{'username'}\@$data{'domain'} to $data{'role'}");
   87:     my $home=&Apache::lonnet::homeserver($data{'username'},$data{'domain'});
   88:     if ($home =~ /(con_lost|no_such_host)/) { return &goto_login($r); }
   89: 
   90:     my $extra_env = &sso_check(\%data);
   91: 
   92:     if (!$data{'role'}) {
   93: 	my $handle = &Apache::lonnet::check_for_valid_session($r);
   94: 	if ($handle) {
   95: 	    &Apache::lonnet::transfer_profile_to_env($r->dir_config('lonIDsDir'),
   96: 						     $handle);
   97:             if ($data{'origurl'} ne '') {
   98:                 $r->internal_redirect($data{'origurl'});
   99:             } elsif ($env{'request.course.id'}) {
  100:                 $r->internal_redirect('/adm/navmaps');
  101: 	    } else {
  102: 		$r->internal_redirect('/adm/roles');
  103: 	    }
  104: 	} else {
  105:             my $desturl = '/adm/roles';
  106:             if ($data{'origurl'} ne '') {
  107:                 $desturl = $data{'origurl'};
  108:             }
  109: 	    &Apache::lonauth::success($r,$data{'username'},$data{'domain'},
  110: 				      $home,$desturl,$extra_env);
  111: 
  112: 	}
  113: 	return OK;
  114: 
  115:     }
  116: 
  117:     my $next_url='/adm/roles?selectrole=1&amp;'.&escape($data{'role'}).'=1';
  118:     if ($data{'origurl'} ne '') {
  119:         $next_url .= '&amp;orgurl='.&escape($data{'origurl'});
  120:     }
  121:     if ($data{'symb'} ne '') {
  122:         $next_url .= '&amp;symb='.&escape($data{'symb'});
  123:     }
  124:     
  125:     &Apache::lonauth::success($r,$data{'username'},$data{'domain'},$home,
  126: 			      $next_url,$extra_env);
  127:     return OK;
  128: }
  129: 
  130: 1;
  131: __END__

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