Handle DIMP/Ajax logout stuff entirely within ajax.php
authorMichael M Slusarz <slusarz@curecanti.org>
Thu, 6 Aug 2009 18:45:14 +0000 (12:45 -0600)
committerMichael M Slusarz <slusarz@curecanti.org>
Thu, 6 Aug 2009 20:59:50 +0000 (14:59 -0600)
imp/ajax.php
imp/js/DimpCore.js
imp/lib/base.php
imp/templates/javascript_defs_dimp.php

index c6038f2..3bb8af3 100644 (file)
@@ -164,9 +164,21 @@ if (in_array($action, array('chunkContent', 'Html2Text', 'Text2Html', 'GetReplyD
     $imp_session_control = 'readonly';
 }
 
-$imp_dimp_logout = ($action == 'LogOut');
-$imp_session_timeout = 'json';
-require_once IMP_BASE . '/lib/base.php';
+$imp_authentication = 'throw';
+try {
+    require_once IMP_BASE . '/lib/base.php';
+} catch (Horde_Exception $e) {
+    /* Handle session timeouts when they come from an AJAX request. */
+    if ($e->getCode() == Horde_Registry::AUTH_FAILURE) {
+        $notification = Horde_Notification::singleton();
+        $imp_notify = $notification->attach('status', array('viewmode' => 'dimp'), 'IMP_Notification_Listener_Status');
+        $notification->push(str_replace('&amp;', '&', Horde_Auth::getLogoutUrl(array('reason' => Horde_Auth::REASON_SESSION))), 'dimp.timeout', array('content.raw'));
+        Horde::sendHTTPResponse(Horde::prepareResponse(null, $imp_notify), 'json');
+        exit;
+    }
+
+    Horde_Auth::authenticateFailure('imp', $e);
+}
 
 // Process common request variables.
 $mbox = Horde_Util::getPost('view');
@@ -181,6 +193,12 @@ $notify = true;
 $result = false;
 
 switch ($action) {
+case 'LogOut':
+    /* Handle logout requests. This needs to be done here because the logout
+     * tokens might expire otherwise. */
+    Horde::redirect(str_replace('&amp;', '&', Horde::getServiceLink('logout', 'imp')));
+    break;
+
 case 'CreateFolder':
     if (empty($mbox)) {
         break;
index fe6ea00..757106f 100644 (file)
@@ -210,7 +210,7 @@ var DimpCore = {
 
             switch (m.type) {
             case 'dimp.timeout':
-                this.logout(DIMP.conf.URI_TIMEOUT);
+                this.logout(m.message);
                 return true;
 
             case 'horde.error':
index 6b59855..7a7dd61 100644 (file)
  *   [DEFAULT] - Authenticate to IMAP/POP server; on no auth redirect to login
  *               screen
  * $imp_compose_page - If true, we are on IMP's compose page
- * $imp_dimp_logout - Logout and redirect to the login page.
  * $imp_no_compress - Controls whether the page should be compressed
  * $imp_session_control - Sets special session control limitations:
  *   'netscape' - TODO; start read/write session
  *   'none' - Do not start a session
  *   'readonly' - Start session readonly
  *   [DEFAULT] - Start read/write session
- * $imp_session_timeout - Sets special handling for session timeouts:
- *   'json' - Send session logout request to browser.
  * </pre>
  *
  * Global variables defined:
@@ -63,16 +60,6 @@ case 'readonly':
 }
 $registry = Horde_Registry::singleton($s_ctrl);
 
-// Determine view mode.
-$viewmode = isset($_SESSION['imp']['view'])
-    ? $_SESSION['imp']['view']
-    : 'imp';
-
-// Handle dimp logout requests.
-if (($viewmode == 'dimp') && Horde_Util::nonInputVar('imp_dimp_logout')) {
-    Horde::redirect(str_replace('&amp;', '&', Horde::getServiceLink('logout', 'imp')));
-}
-
 // Determine imp authentication type.
 $authentication = Horde_Util::nonInputVar('imp_authentication');
 if ($authentication == 'horde') {
@@ -86,23 +73,14 @@ try {
     $registry->pushApp('imp', array('check_perms' => ($authentication != 'none'), 'logintasks' => true));
 } catch (Horde_Exception $e) {
     if ($e->getCode() == Horde_Registry::AUTH_FAILURE) {
-        if ($authentication == 'throw') {
-            throw $e;
-        }
-
-        // Handle session timeouts when they come from an AJAX request.
-        if (($viewmode == 'dimp') &&
-            (Horde_Util::nonInputVar('imp_session_timeout') == 'json')) {
-            $notification = Horde_Notification::singleton();
-            $notification->push(null, 'dimp.timeout');
-            Horde::sendHTTPResponse(Horde::prepareResponse(), 'json');
-            exit;
-        }
-
         if (Horde_Util::nonInputVar('imp_compose_page')) {
             $imp_compose = IMP_Compose::singleton();
             $imp_compose->sessionExpireDraft();
         }
+
+        if ($authentication == 'throw') {
+            throw $e;
+        }
     }
 
     Horde_Auth::authenticateFailure('imp', $e);
index 0f7a317..24d4fa0 100644 (file)
@@ -49,7 +49,6 @@ $code['conf'] = array_filter(array(
     'URI_MESSAGE' => Horde::applicationUrl('message-dimp.php'),
     'URI_PREFS' => Horde::getServiceLink('prefsapi', 'imp'),
     'URI_PREFS_IMP' => str_replace('&amp;', '&', Horde::getServiceLink('options', 'imp')),
-    'URI_TIMEOUT' => Horde_Auth::getLogoutUrl(array('reason' => Horde_Auth::REASON_SESSION)),
     'URI_VIEW' => Horde::applicationUrl('view.php'),
 
     'SESSION_ID' => defined('SID') ? SID : '',