From: Michael M Slusarz Date: Thu, 26 Mar 2009 23:39:57 +0000 (-0600) Subject: Attempt to clean up logout handling X-Git-Url: https://git.internetallee.de/?a=commitdiff_plain;h=998382d6723db763affbbba342a8d91c02984677;p=horde.git Attempt to clean up logout handling Use 1 function (getLogoutUrl()) instead of 2 (logoutUrl()). --- diff --git a/imp/lib/IMP.php b/imp/lib/IMP.php index c2616455d..6d90edefc 100644 --- a/imp/lib/IMP.php +++ b/imp/lib/IMP.php @@ -100,7 +100,7 @@ class IMP if (Util::getFormData('popup')) { Util::closeWindowJS(); } else { - $url = Util::addParameter(Auth::addLogoutParameters(self::logoutUrl()), 'url', Horde::selfUrl(true)); + $url = Util::addParameter(self::getLogoutUrl(null, true), 'url', Horde::selfUrl(true)); header('Location: ' . $url); } exit; @@ -454,43 +454,6 @@ class IMP } /** - * Generates an URL to the logout screen that includes any known - * information, such as username, server, etc., that can be filled in on - * the login form. - * - * @return string Logout URL with logout parameters added. - */ - static public function logoutUrl() - { - // TODO - $params = array( - 'imapuser' => isset($_SESSION['imp']['user']) ? - $_SESSION['imp']['user'] : - Util::getFormData('imapuser'), - 'server' => isset($_SESSION['imp']['server']) ? - $_SESSION['imp']['server'] : - Util::getFormData('server'), - 'port' => isset($_SESSION['imp']['port']) ? - $_SESSION['imp']['port'] : - Util::getFormData('port'), - 'protocol' => isset($_SESSION['imp']['protocol']) ? - $_SESSION['imp']['protocol'] : - Util::getFormData('protocol'), - 'language' => isset($_SESSION['imp']['language']) ? - $_SESSION['imp']['language'] : - Util::getFormData('language'), - 'smtphost' => isset($_SESSION['imp']['smtphost']) ? - $_SESSION['imp']['smtphost'] : - Util::getFormData('smtphost'), - 'smtpport' => isset($_SESSION['imp']['smtpport']) ? - $_SESSION['imp']['smtpport'] : - Util::getFormData('smtpport'), - ); - - return Util::addParameter($GLOBALS['registry']->get('webroot', 'imp') . '/login.php', array_diff($params, array('')), null, false); - } - - /** * If there is information available to tell us about a prefix in front of * mailbox names that shouldn't be displayed to the user, then use it to * strip that prefix out. Additionally, translate prefix text if this @@ -1364,13 +1327,36 @@ class IMP /** * Returns the proper logout URL for logging out of IMP. * + * @param integer $reason + * @param boolean $force Force URL to IMP login page. + * * @return string The logout URL. */ - static public function getLogoutUrl() + static public function getLogoutUrl($reason = null, $force = false) { - return ((Auth::getProvider() == 'imp') || $_SESSION['imp']['autologin']) - ? Horde::getServiceLink('logout', 'horde', true) - : Auth::addLogoutParameters($GLOBALS['registry']->get('webroot', 'imp') . '/login.php', AUTH_REASON_LOGOUT); + $params = array_filter(array( + 'server_key' => isset($_SESSION['imp']['server_key']) ? + $_SESSION['imp']['server_key'] : + Util::getFormData('server_key'), + 'language' => Util::getFormData('language') + )); + + if ($force || + !((Auth::getProvider() != 'imp') || !$_SESSION['imp']['autologin'])) { + $url = $GLOBALS['registry']->get('webroot', 'imp') . '/login.php'; + } else { + $url = Horde::getServiceLink('logout', 'horde', true); + } + + $url = (!is_null($reason) && is_array($reason)) + ? Auth::addLogoutParameters($url, $reason[0], $reason[1]) + : Auth::addLogoutParameters($url, $reason); + + if (!empty($params)) { + $url = Util::addParameter($url, $params, null, false); + } + + return $url; } /** diff --git a/imp/lib/MIMP.php b/imp/lib/MIMP.php index ef44c1fae..16daeda1e 100644 --- a/imp/lib/MIMP.php +++ b/imp/lib/MIMP.php @@ -45,9 +45,9 @@ class MIMP // if ($options_link = Horde::getServiceLink('options', 'mimp')) { // $items[Util::addParameter($options_link, 'mobile', 1, false)] = _("Options"); // } - $logout_link = IMP::getLogoutUrl(); + $logout_link = IMP::getLogoutUrl(AUTH_REASON_LOGOUT); if (!empty($logout_link)) { - $items[Auth::addLogoutParameters($logout_link, AUTH_REASON_LOGOUT)] = _("Log out"); + $items[$logout_link] = _("Log out"); } foreach ($items as $link => $label) { diff --git a/imp/lib/Maintenance/Task/tos_agreement.php b/imp/lib/Maintenance/Task/tos_agreement.php index d1a4138ca..d423fcad5 100644 --- a/imp/lib/Maintenance/Task/tos_agreement.php +++ b/imp/lib/Maintenance/Task/tos_agreement.php @@ -28,7 +28,7 @@ class Maintenance_Task_tos_agreement extends Maintenance_Task { $result = Util::getFormData('not_agree'); if (isset($result)) { - header('Location: ' . Auth::addLogoutParameters(IMP::logoutUrl(), AUTH_REASON_MESSAGE, _("You did not agree to the Terms of Service agreement, so you were not allowed to login."))); + header('Location: ' . IMP::getLogoutUrl(array(AUTH_REASON_MESSAGE => _("You did not agree to the Terms of Service agreement, so you were not allowed to login.")), true)); exit; } } diff --git a/imp/lib/Session.php b/imp/lib/Session.php index bbe36e415..cff470a9c 100644 --- a/imp/lib/Session.php +++ b/imp/lib/Session.php @@ -43,6 +43,7 @@ class IMP_Session * 'protocol' -- Either 'imap' or 'pop'. * 'rteavail' -- Is the HTML editor available? * 'search' -- Settings used by the IMP_Search library. + * 'server_key' -- Server used to login. * 'smime' -- Settings related to the S/MIME viewer. * 'smtp' -- SMTP options ('host' and 'port') * 'showunsub' -- Show unsusubscribed mailboxes on the folders screen. @@ -69,6 +70,7 @@ class IMP_Session $_SESSION['imp'] = array( 'cache' => array(), 'imap' => array(), + 'server_key' => $server, 'showunsub' => false ); $sess = &$_SESSION['imp']; diff --git a/imp/redirect.php b/imp/redirect.php index 5daf5e7d1..88ff10da1 100644 --- a/imp/redirect.php +++ b/imp/redirect.php @@ -117,7 +117,7 @@ if (isset($_SESSION['imp']) && is_array($_SESSION['imp'])) { (!is_null($pass) && ($pass != $GLOBALS['imp_imap']->ob->getParam('password')))) { /* Disable the old session. */ unset($_SESSION['imp']); - _redirect(Auth::addLogoutParameters(IMP::logoutUrl(), AUTH_REASON_FAILED)); + _redirect(IMP::getLogoutUrl(AUTH_REASON_FAILED, true)); } /* Finish up any login tasks we haven't completed yet. */ @@ -174,7 +174,7 @@ if (!is_null($imapuser) && !is_null($pass)) { _redirect(_framesetUrl(_newSessionUrl($actionID, $isLogin))); } - _redirect(Auth::addLogoutParameters(IMP::logoutUrl())); + _redirect(IMP::getLogoutUrl(null, true)); } /* No session, and no login attempt. Just go to the login page. */