Add transparent auth
authorDuck (Jakob Munih) <duck@obala.net>
Sat, 17 Oct 2009 08:37:55 +0000 (10:37 +0200)
committerDuck (Jakob Munih) <duck@obala.net>
Sat, 17 Oct 2009 08:37:55 +0000 (10:37 +0200)
folks/lib/Application.php
folks/lib/base.php
folks/login.php

index e91f498..38d7048 100644 (file)
@@ -40,6 +40,30 @@ class Folks_Application extends Horde_Registry_Application
     }
 
     /**
+     * Tries to transparently authenticate
+     *
+     * @param Horde_Auth_Application $auth_ob  The authentication object.
+     *
+     * @return boolean  Whether transparent login is supported.
+     * @throws Horde_Auth_Exception
+     */
+    public function authTransparent($auth_ob)
+    {
+        if (empty($_COOKIE['folks_login_code']) ||
+            empty($_COOKIE['folks_login_user'])) {
+            return false;
+        }
+
+        require_once dirname(__FILE__) . '/base.php';
+        $GLOBALS['folks_driver'] = Folks_Driver::factory();
+        if ($_COOKIE['folks_login_code'] == $GLOBALS['folks_driver']->getCookie($_COOKIE['folks_login_user'])) {
+            return Horde_Auth::setAuth($_COOKIE['folks_login_user'], array('transparent' => 1));
+        }  else {
+            return false;
+        }
+    }
+
+    /**
      * Check if a user exists
      *
      * @param string $userID       Username
index a531353..43bbb3e 100644 (file)
@@ -20,7 +20,7 @@ require_once HORDE_BASE . '/lib/core.php';
 // Registry.
 $registry = Horde_Registry::singleton();
 try {
-    $registry->pushApp('folks', array('check_perms' => (Horde_Util::nonInputVar('folks_authentication') != 'none'), 'logintasks' => true));
+    $registry->pushApp('folks', array('check_perms' => (Horde_Util::nonInputVar('folks_authentication') != 'none')));
 } catch (Horde_Exception $e) {
     Horde_Auth::authenticateFailure('folks', $e);
 }
index ebd6a52..b6da13d 100644 (file)
@@ -89,7 +89,7 @@ if ($conf['login']['prelogin'] &&
  * Login parameters
  */
 $url_param = Horde_Util::getFormData('url');
-$login_url = Util::addParameter(Horde::getServiceLink('login', 'folks'), 'url', $url_param);
+$login_url = Horde_Util::addParameter(Horde::getServiceLink('login', 'folks'), 'url', $url_param);
 
 /*
  * We are already logged in?
@@ -115,6 +115,7 @@ if (isset($_COOKIE['folks_login_code']) &&
     if (empty($url_param)) {
         $url_param = Folks::getUrlFor('user', $_COOKIE['folks_login_user']);
     }
+
     header('Location: ' . $url_param);
     exit;
 }
@@ -129,7 +130,7 @@ $form = new Folks_Login_Form($vars, $title, 'folks_login');
 /*
  * Check time between one login and anther
  */
-$username = strtolower(trim(Horde_Util::getPost('username')));
+$username = Horde_String::lower(trim(Horde_Util::getPost('username')));
 if ($username && $conf['login']['diff']) {
     $last_try = $cache->get('login_last_try_' . $username, $conf['cache']['default_lifetime']);
     if ($last_try && $_SERVER['REQUEST_TIME'] - $last_try <= $conf['login']['diff']) {