1: # The LearningOnline Network
2: # Starts a user off based of an existing token.
3: #
4: # $Id: migrateuser.pm,v 1.6 2006/05/15 17:45:46 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 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 handler {
53: my ($r) = @_;
54:
55: &Apache::loncommon::get_unprocessed_cgi($ENV{'QUERY_STRING'},['token']);
56: my %data = &Apache::lonnet::tmpget($env{'form.token'});
57: my $delete = &Apache::lonnet::tmpdel($env{'form.token'});
58:
59: &Apache::lonlocal::get_language_handle($r);
60:
61: if ($delete ne 'ok') {
62: return &goto_login($r);
63: }
64:
65: if ($data{'ip'} ne $ENV{'REMOTE_ADDR'} || !defined($data{'username'}) ||
66: !defined($data{'domain'}) ) {
67: return &goto_login($r);
68: }
69:
70: &Apache::lonnet::logthis("Allowing access for $data{'username'}\@$data{'domain'} to $data{'role'}");
71: my $home=&Apache::lonnet::homeserver($data{'username'},$data{'domain'});
72: if ($home =~ /(con_lost|no_such_host)/) { return &goto_login($r); }
73:
74: if (!$data{'role'}) {
75: &Apache::lonauth::success($r,$data{'username'},$data{'domain'},
76: $home,'/adm/roles');
77: return OK;
78: }
79:
80: my $next_url='/adm/roles?selectrole=1&'.&escape($data{'role'}).'=1';
81:
82:
83: &Apache::lonauth::success($r,$data{'username'},$data{'domain'},$home,
84: $next_url);
85: return OK;
86: }
87:
88: 1;
89: __END__
FreeBSD-CVSweb <freebsd-cvsweb@FreeBSD.org>