Various auth fixes.
authorMichael M Slusarz <slusarz@curecanti.org>
Wed, 22 Jul 2009 04:41:10 +0000 (22:41 -0600)
committerMichael M Slusarz <slusarz@curecanti.org>
Wed, 22 Jul 2009 05:04:34 +0000 (23:04 -0600)
Use correct username when authenticating
Fix generation of initial URL when it is mailbox view
Use better "is currently authenticated" function
Correctly set realm'ed username as Horde username

imp/lib/Auth.php
imp/lib/IMP.php
imp/lib/api.php

index 4d03cf0..09cb946 100644 (file)
@@ -217,7 +217,7 @@ class IMP_Auth
         }
 
         /* Determine the unique user name. */
-        if (Horde_Auth::isAuthenticated()) {
+        if (Horde_Auth::getAuth()) {
             $sess['uniquser'] = Horde_Auth::removeHook(Horde_Auth::getAuth());
         } else {
             $sess['uniquser'] = $credentials['userid'];
@@ -231,7 +231,7 @@ class IMP_Auth
             self::authenticate(array(
                 'password' => $credentials['password'],
                 'server' => $credentials['server'],
-                'userid' => $sess['uniquser']
+                'userid' => $credentials['userid']
             ));
         } catch (Horde_Auth_Exception $e) {
             unset($_SESSION['imp']);
@@ -460,9 +460,12 @@ class IMP_Auth
                 break;
 
             default:
-                // TODO: Directly load mailbox.php
-                header('Location: ' . Horde_Util::addParameter(Horde::applicationUrl('mailbox.php', true), array('mailbox' => $init_url)));
-                exit;
+                $page = 'mailbox.php';
+                if ($url) {
+                    return Horde_Util::addParameter(Horde::applicationUrl($page, true), array('mailbox' => $init_url));
+                }
+                $GLOBALS['imp_mbox'] = IMP::getCurrentMailboxInfo($init_url);
+                break;
             }
         }
 
index 3010f92..ea0c6f4 100644 (file)
@@ -1119,6 +1119,8 @@ class IMP
     /**
      * Process mailbox/index information for current page load.
      *
+     * @param boolean $mbox  Use this mailbox, instead of form data.
+     *
      * @return array  Array with the following elements:
      * <pre>
      * 'mailbox' - The current active mailbox (may be search mailbox).
@@ -1126,13 +1128,21 @@ class IMP
      * 'index' - The IMAP message index.
      * </pre>
      */
-    static public function getCurrentMailboxInfo()
+    static public function getCurrentMailboxInfo($mbox = null)
     {
-        $mbox = Horde_Util::getFormData('mailbox');
+        if (is_null($mbox)) {
+            $mbox = Horde_Util::getFormData('mailbox');
+            return array(
+                'mailbox' => empty($mbox) ? 'INBOX' : $mbox,
+                'thismailbox' => Horde_Util::getFormData('thismailbox', $mbox),
+                'index' => Horde_Util::getFormData('index')
+            );
+        }
+
         return array(
-            'mailbox' => empty($mbox) ? 'INBOX' : $mbox,
-            'thismailbox' => Horde_Util::getFormData('thismailbox', $mbox),
-            'index' => Horde_Util::getFormData('index')
+            'mailbox' => $mbox,
+            'thismailbox' => $mbox,
+            'index' => null
         );
     }
 
index f34310c..918d078 100644 (file)
@@ -676,6 +676,10 @@ function _imp_authAuthenticate($userId, $credentials)
                   $conf['cookie']['domain']);
 
         $_SESSION['imp']['view'] = $view;
+
+        /* Set the Horde ID, since it may have been altered by the 'realm'
+         * setting. */
+        $credentials['auth_ob']->setCredential('userId', $_SESSION['imp']['uniquser']);
     }
 }