}
}
- /**
- * Logout from the CAS
- *
- */
- function prelogout_hook() {
- global $CFG;
-
- if (!empty($this->config->logoutcas)) {
- $backurl = $CFG->wwwroot;
- $this->connectCAS();
- phpCAS::logoutWithURL($backurl);
- }
- }
/**
* Connect to the CAS (clientcas connection or proxycas connection)
}
}
}
+
+ /**
+ * Post logout hook.
+ *
+ * Note: this method replace the prelogout_hook method to avoid redirect to CAS logout
+ * before the event userlogout being triggered.
+ *
+ * @param stdClass $user clone of USER object object before the user session was terminated
+ */
+ public function postlogout_hook($user) {
+ global $CFG;
+ // Only redirect to CAS logout if the user is logged as a CAS user.
+ if (!empty($this->config->logoutcas) && $user->auth == $this->authtype) {
+ $backurl = $CFG->wwwroot;
+ $this->connectCAS();
+ phpCAS::logoutWithRedirectService($backurl);
+ }
+ }
}
return $this->customfields;
}
+
+ /**
+ * Post logout hook.
+ *
+ * This method is used after moodle logout by auth classes to execute server logout.
+ *
+ * @param stdClass $user clone of USER object before the user session was terminated
+ */
+ public function postlogout_hook($user) {
+ }
}
/**
}
// Execute hooks before action.
+ $authplugins = array();
$authsequence = get_enabled_auth_plugins();
foreach ($authsequence as $authname) {
- $authplugin = get_auth_plugin($authname);
- $authplugin->prelogout_hook();
+ $authplugins[$authname] = get_auth_plugin($authname);
+ $authplugins[$authname]->prelogout_hook();
}
// Store info that gets removed during logout.
$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);
+ }
}
/**