MDL-52975 mnet: Set system context on the MNet SSO landing page
[moodle.git] / auth / mnet / land.php
CommitLineData
c72fe801 1<?php
a2f10958
PS
2// This file is part of Moodle - http://moodle.org/
3//
4// Moodle is free software: you can redistribute it and/or modify
5// it under the terms of the GNU General Public License as published by
6// the Free Software Foundation, either version 3 of the License, or
7// (at your option) any later version.
8//
9// Moodle is distributed in the hope that it will be useful,
10// but WITHOUT ANY WARRANTY; without even the implied warranty of
11// MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
12// GNU General Public License for more details.
13//
14// You should have received a copy of the GNU General Public License
15// along with Moodle. If not, see <http://www.gnu.org/licenses/>.
c72fe801 16
17/**
c72fe801 18 * Authentication Plugin: Moodle Network Authentication
c72fe801 19 * Multiple host authentication support for Moodle Network.
20 *
a2f10958
PS
21 * @package auth_mnet
22 * @author Martin Dougiamas
23 * @license http://www.gnu.org/copyleft/gpl.html GNU Public License
c72fe801 24 */
25
26require_once dirname(dirname(dirname(__FILE__))) . '/config.php';
27require_once $CFG->dirroot . '/mnet/xmlrpc/client.php';
28
79151615 29// grab the GET params
30$token = required_param('token', PARAM_BASE64);
31$remotewwwroot = required_param('idp', PARAM_URL);
32$wantsurl = required_param('wantsurl', PARAM_LOCALURL);
33$wantsremoteurl = optional_param('remoteurl', false, PARAM_BOOL);
34
a6855934 35$url = new moodle_url('/auth/mnet/jump.php', array('token'=>$token, 'idp'=>$remotewwwroot, 'wantsurl'=>$wantsurl));
79151615 36if ($wantsremoteurl !== false) $url->param('remoteurl', $wantsremoteurl);
37$PAGE->set_url($url);
1ef135e7 38$PAGE->set_context(context_system::instance());
79151615 39
2a250a0b 40$site = get_site();
016bac47 41
139ebfdb 42if (!is_enabled_auth('mnet')) {
3db241b3 43 print_error('mnetdisable');
139ebfdb 44}
c72fe801 45
46// confirm the MNET session
47$mnetauth = get_auth_plugin('mnet');
2078b2a3
PL
48$remotepeer = new mnet_peer();
49$remotepeer->set_wwwroot($remotewwwroot);
50// this creates the local user account if necessary, or updates it if it already exists
51$localuser = $mnetauth->confirm_mnet_session($token, $remotepeer);
c72fe801 52
53// log in
1b813f5c 54$user = get_complete_user_data('id', $localuser->id, $localuser->mnethostid);
55complete_user_login($user);
2078b2a3
PL
56// now that we've logged in, set up the mnet session properly
57$mnetauth->update_mnet_session($user, $token, $remotepeer);
c72fe801 58
0743661e 59if (!empty($localuser->mnet_foreign_host_array)) {
60 $USER->mnet_foreign_host_array = $localuser->mnet_foreign_host_array;
61}
62
c72fe801 63// redirect
d9be2106 64if ($wantsremoteurl) {
65 redirect($remotewwwroot . $wantsurl);
66}
c72fe801 67redirect($CFG->wwwroot . $wantsurl);
68
5117d598 69