Attempt to clean up logout handling
authorMichael M Slusarz <slusarz@curecanti.org>
Thu, 26 Mar 2009 23:39:57 +0000 (17:39 -0600)
committerMichael M Slusarz <slusarz@curecanti.org>
Thu, 26 Mar 2009 23:40:11 +0000 (17:40 -0600)
Use 1 function (getLogoutUrl()) instead of 2 (logoutUrl()).

imp/lib/IMP.php
imp/lib/MIMP.php
imp/lib/Maintenance/Task/tos_agreement.php
imp/lib/Session.php
imp/redirect.php

index c261645..6d90ede 100644 (file)
@@ -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;
     }
 
     /**
index ef44c1f..16daeda 100644 (file)
@@ -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) {
index d1a4138..d423fca 100644 (file)
@@ -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;
         }
     }
index bbe36e4..cff470a 100644 (file)
@@ -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'];
index 5daf5e7..88ff10d 100644 (file)
@@ -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. */