[ Index ]

PHP Cross Reference of moodle-2.8

title

Body

[close]

/auth/mnet/ -> land.php (source)

   1  <?php
   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/>.
  16  
  17  /**
  18   * Authentication Plugin: Moodle Network Authentication
  19   * Multiple host authentication support for Moodle Network.
  20   *
  21   * @package auth_mnet
  22   * @author Martin Dougiamas
  23   * @license http://www.gnu.org/copyleft/gpl.html GNU Public License
  24   */
  25  
  26  require_once dirname(dirname(dirname(__FILE__))) . '/config.php';
  27  require_once $CFG->dirroot . '/mnet/xmlrpc/client.php';
  28  
  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  
  35  $url = new moodle_url('/auth/mnet/jump.php', array('token'=>$token, 'idp'=>$remotewwwroot, 'wantsurl'=>$wantsurl));
  36  if ($wantsremoteurl !== false) $url->param('remoteurl', $wantsremoteurl);
  37  $PAGE->set_url($url);
  38  
  39  $site = get_site();
  40  
  41  if (!is_enabled_auth('mnet')) {
  42      print_error('mnetdisable');
  43  }
  44  
  45  // confirm the MNET session
  46  $mnetauth = get_auth_plugin('mnet');
  47  $remotepeer = new mnet_peer();
  48  $remotepeer->set_wwwroot($remotewwwroot);
  49  // this creates the local user account if necessary, or updates it if it already exists
  50  $localuser = $mnetauth->confirm_mnet_session($token, $remotepeer);
  51  
  52  // log in
  53  $user = get_complete_user_data('id', $localuser->id, $localuser->mnethostid);
  54  complete_user_login($user);
  55  // now that we've logged in, set up the mnet session properly
  56  $mnetauth->update_mnet_session($user, $token, $remotepeer);
  57  
  58  if (!empty($localuser->mnet_foreign_host_array)) {
  59      $USER->mnet_foreign_host_array = $localuser->mnet_foreign_host_array;
  60  }
  61  
  62  // redirect
  63  if ($wantsremoteurl) {
  64      redirect($remotewwwroot . $wantsurl);
  65  }
  66  redirect($CFG->wwwroot . $wantsurl);
  67  
  68  


Generated: Fri Nov 28 20:29:05 2014 Cross-referenced by PHPXref 0.7.1