예제 #1
0
 /**
  * Logout from the CAS
  *
  */
 function prelogout_hook()
 {
     global $CFG, $USER, $DB;
     if (!empty($this->config->logoutcas) && $USER->auth == $this->authtype) {
         $backurl = !empty($this->config->logout_return_url) ? $this->config->logout_return_url : $CFG->wwwroot;
         $this->connectCAS();
         // Note: Hack to stable versions to trigger the event before it redirect to CAS logout.
         $sid = session_id();
         $event = \core\event\user_loggedout::create(array('userid' => $USER->id, 'objectid' => $USER->id, 'other' => array('sessionid' => $sid)));
         if ($session = $DB->get_record('sessions', array('sid' => $sid))) {
             $event->add_record_snapshot('sessions', $session);
         }
         \core\session\manager::terminate_current();
         $event->trigger();
         phpCAS::logoutWithRedirectService($backurl);
     }
 }
예제 #2
0
/**
 * This function just makes sure a user is logged out.
 *
 * @package    core_access
 * @category   access
 */
function require_logout()
{
    global $USER, $DB;
    if (!isloggedin()) {
        // This should not happen often, no need for hooks or events here.
        \core\session\manager::terminate_current();
        return;
    }
    // Execute hooks before action.
    $authplugins = array();
    $authsequence = get_enabled_auth_plugins();
    foreach ($authsequence as $authname) {
        $authplugins[$authname] = get_auth_plugin($authname);
        $authplugins[$authname]->prelogout_hook();
    }
    // Store info that gets removed during logout.
    $sid = session_id();
    $event = \core\event\user_loggedout::create(array('userid' => $USER->id, 'objectid' => $USER->id, 'other' => array('sessionid' => $sid)));
    if ($session = $DB->get_record('sessions', array('sid' => $sid))) {
        $event->add_record_snapshot('sessions', $session);
    }
    // Clone of $USER object to be used by auth plugins.
    $user = fullclone($USER);
    // Delete session record and drop $_SESSION content.
    \core\session\manager::terminate_current();
    // Trigger event AFTER action.
    $event->trigger();
    // Hook to execute auth plugins redirection after event trigger.
    foreach ($authplugins as $authplugin) {
        $authplugin->postlogout_hook($user);
    }
}
예제 #3
0
function RWSLOMUser()
{
    global $USER;
    global $CFG;
    global $DB;
    global $RWSECAS;
    if (!$RWSECAS) {
        require_logout();
        RWSSStat("1001");
    }
    if (respondusws_floatcompare($CFG->version, 2010122500, 2) >= 0) {
        if (isloggedin()) {
            $r_aus = get_enabled_auth_plugins();
            foreach ($r_aus as $r_aun) {
                $r_aup = get_auth_plugin($r_aun);
                if (strcasecmp($r_aup->authtype, RWSCAS) == 0) {
                    $r_csp = $r_aup;
                    RWSPLOCas($r_csp);
                } else {
                    $r_aup->prelogout_hook();
                }
            }
        }
        if (respondusws_floatcompare($CFG->version, 2014051200, 2) >= 0) {
            $r_ssi = session_id();
            $r_evt = \core\event\user_loggedout::create(array('userid' => $USER->id, 'objectid' => $USER->id, 'other' => array('sessionid' => $r_ssi)));
            if ($r_ses = $DB->get_record('sessions', array('sid' => $r_ssi))) {
                $r_evt->add_record_snapshot('sessions', $r_ses);
            }
            \core\session\manager::terminate_current();
            $r_evt->trigger();
        } else {
            $r_prms = $USER;
            events_trigger('user_logout', $r_prms);
            if (respondusws_floatcompare($CFG->version, 2013111800, 2) >= 0) {
                \core\session\manager::terminate_current();
            } else {
                session_get_instance()->terminate_current();
            }
            unset($r_prms);
        }
    } else {
        RWSSErr("2006,{$CFG->version},2010122500");
    }
    RWSSStat("1001");
}