Move the authentication check and restoring the tasklist from the session into the...
authorGunnar Wrobel <p@rdus.de>
Wed, 3 Mar 2010 10:28:36 +0000 (11:28 +0100)
committerGunnar Wrobel <p@rdus.de>
Wed, 3 Mar 2010 10:28:36 +0000 (11:28 +0100)
framework/LoginTasks/lib/Horde/LoginTasks.php
framework/LoginTasks/lib/Horde/LoginTasks/Backend.php
framework/LoginTasks/lib/Horde/LoginTasks/Backend/Horde.php

index 4310b63..35fbfe9 100644 (file)
@@ -78,7 +78,7 @@ class Horde_LoginTasks
     {
         if (empty(self::$_instances[$app])) {
             self::$_instances[$app] = new self(
-                new Horde_LoginTasks_Backend_Horde(), $app
+                new Horde_LoginTasks_Backend_Horde($app), $app
             );
         }
 
@@ -98,14 +98,12 @@ class Horde_LoginTasks
 
         $this->_app = $app;
 
-        if (!Horde_Auth::getAuth()) {
+        if (!$this->_backend->isAuthenticated()) {
             return;
         }
 
         /* Retrieves a cached tasklist or make sure one is created. */
-        if (isset($_SESSION['horde_logintasks'][$app])) {
-            $this->_tasklist = @unserialize($_SESSION['horde_logintasks'][$app]);
-        }
+        $this->_tasklist = $this->_backend->getTaskListFromCache();
 
         if (empty($this->_tasklist)) {
             $this->_createTaskList();
index 5d41ffc..150260a 100644 (file)
  * @author  Gunnar Wrobel <wrobel@pardus.de>
  * @package Horde_LoginTasks
  */
-class Horde_LoginTasks_Backend
+abstract class Horde_LoginTasks_Backend
 {
+    /**
+     * Is the current session authenticated?
+     *
+     * @return boolean True if the user is authenticated, false otherwise.
+     */
+    abstract public function isAuthenticated();
+
+    /**
+     * Retrieve a cached tasklist if it exists.
+     *
+     * @return Horde_LoginTasks_Tasklist|boolean The cached task list or false
+     * if no task list was cached.
+     */
+    abstract public function getTasklistFromCache();
 }
\ No newline at end of file
index 11cbff8..544b070 100644 (file)
 class Horde_LoginTasks_Backend_Horde
 extends Horde_LoginTasks_Backend
 {
+    /**
+     * The Horde application that is currently active.
+     *
+     * @var string
+     */
+    private $_app;
+
+    /**
+     * Constructor
+     *
+     * @param string $app The Horde application that is currently active.
+     */
+    public function __construct($app)
+    {
+        $this->_app = $app;
+    }
+    
+    /**
+     * Is the current session authenticated?
+     *
+     * @return boolean True if the user is authenticated, false otherwise.
+     */
+    public function isAuthenticated()
+    {
+        return (Horde_Auth::getAuth() !== false);
+    }
+
+    /**
+     * Retrieve a cached tasklist if it exists.
+     *
+     * @return Horde_LoginTasks_Tasklist|boolean The cached task list or false
+     * if no task list was cached.
+     */
+    public function getTasklistFromCache()
+    {
+        if (isset($_SESSION['horde_logintasks'][$this->_app])) {
+            return @unserialize($_SESSION['horde_logintasks'][$this->_app]);
+        }
+        return false;
+    }
 }
\ No newline at end of file