From bf41c01c124f310917d0bd00e78c4c024d88ca8d Mon Sep 17 00:00:00 2001 From: Dmitrii Metelkin Date: Fri, 19 Aug 2016 12:13:47 +1000 Subject: [PATCH] Refactor logoutpage_hook function --- auth.php | 27 +++++++++++++++++++++++++-- 1 file changed, 25 insertions(+), 2 deletions(-) diff --git a/auth.php b/auth.php index e7fe341..9dbe875 100644 --- a/auth.php +++ b/auth.php @@ -384,6 +384,29 @@ class auth_plugin_userkey extends auth_plugin_base { return $parameters; } + /** + * Check if we should redirect a user after logout. + * + * @return bool + */ + protected function should_redirect() { + global $SESSION; + + if (!isset($SESSION->userkey)) { + return false; + } + + if (!isset($this->config->redirecturl)) { + return false; + } + + if (empty($this->config->redirecturl)) { + return false; + } + + return true; + } + /** * Logout page hook. * @@ -392,9 +415,9 @@ class auth_plugin_userkey extends auth_plugin_base { * @see auth_plugin_base::logoutpage_hook() */ public function logoutpage_hook() { - global $redirect, $SESSION; + global $redirect; - if (!empty($this->config->redirecturl) && isset($SESSION->userkey)) { + if ($this->should_redirect()) { $redirect = $this->config->redirecturl; } }