LSauthMethod_anonymous : Added LSauth method and added feature in LSauth/LSsession...
authorBenjamin Renard <brenard@easter-eggs.com>
Thu, 25 Nov 2010 11:39:35 +0000 (12:39 +0100)
committerBenjamin Renard <brenard@easter-eggs.com>
Thu, 25 Nov 2010 11:39:35 +0000 (12:39 +0100)
public_html/conf/LSauth/config.LSauthMethod_anonymous.php [new file with mode: 0644]
public_html/includes/class/class.LSauth.php
public_html/includes/class/class.LSauthMethod_anonymous.php [new file with mode: 0644]
public_html/includes/class/class.LSsession.php
public_html/templates/default/top.tpl

diff --git a/public_html/conf/LSauth/config.LSauthMethod_anonymous.php b/public_html/conf/LSauth/config.LSauthMethod_anonymous.php
new file mode 100644 (file)
index 0000000..e8e8a5a
--- /dev/null
@@ -0,0 +1,32 @@
+<?php
+/*******************************************************************************
+ * Copyright (C) 2007 Easter-eggs
+ * http://ldapsaisie.labs.libre-entreprise.org
+ *
+ * Author: See AUTHORS file in top-level directory.
+ *
+ * This program is free software; you can redistribute it and/or
+ * modify it under the terms of the GNU General Public License version 2
+ * as published by the Free Software Foundation.
+ *
+ * This program is distributed in the hope that it will be useful,
+ * but WITHOUT ANY WARRANTY; without even the implied warranty of
+ * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the
+ * GNU General Public License for more details.
+ *
+ * You should have received a copy of the GNU General Public License
+ * along with this program; if not, write to the Free Software
+ * Foundation, Inc., 59 Temple Place - Suite 330, Boston, MA  02111-1307, USA.
+
+******************************************************************************/
+
+/*
+ ***********************************************************
+ * Configuration of the Anonymous authentification support *
+ ***********************************************************
+ */
+
+// User id used for anonymous connections
+define('LSAUTHMETHOD_ANONYMOUS_USER','ls');
+
+?>
index 2727420..dd16be5 100644 (file)
@@ -36,7 +36,8 @@ class LSauth {
   
   static private $params = array (
     'displayLoginForm' => true,
-    'displayLogoutBtn' => true
+    'displayLogoutBtn' => true,
+    'displaySelfAccess' => true
   );
 
   function start() {
@@ -115,6 +116,24 @@ class LSauth {
                return self :: $params['displayLogoutBtn'];
        }
   
+ /**
+  * Disable self access
+  *
+  * @retval void
+  **/
+  public function disableSelfAccess() {
+               self :: $params['displaySelfAccess'] = false;
+       }
+
+ /**
+  * Can display or not self access
+  *
+  * @retval boolean
+  **/
+  public function displaySelfAccess() {
+    return self :: $params['displaySelfAccess'];
+  }
+
   /*
    * For compatibillity until loginForm is migrated in LSauth
    */
diff --git a/public_html/includes/class/class.LSauthMethod_anonymous.php b/public_html/includes/class/class.LSauthMethod_anonymous.php
new file mode 100644 (file)
index 0000000..02343a4
--- /dev/null
@@ -0,0 +1,66 @@
+<?php
+/*******************************************************************************
+ * Copyright (C) 2007 Easter-eggs
+ * http://ldapsaisie.labs.libre-entreprise.org
+ *
+ * Author: See AUTHORS file in top-level directory.
+ *
+ * This program is free software; you can redistribute it and/or
+ * modify it under the terms of the GNU General Public License version 2
+ * as published by the Free Software Foundation.
+ *
+ * This program is distributed in the hope that it will be useful,
+ * but WITHOUT ANY WARRANTY; without even the implied warranty of
+ * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the
+ * GNU General Public License for more details.
+ *
+ * You should have received a copy of the GNU General Public License
+ * along with this program; if not, write to the Free Software
+ * Foundation, Inc., 59 Temple Place - Suite 330, Boston, MA  02111-1307, USA.
+
+******************************************************************************/
+
+/**
+ * Anonymous authentication provider for LSauth
+ *
+ * @author Benjamin Renard <brenard@easter-eggs.com>
+ */
+class LSauthMethod_anonymous extends LSauthMethod {
+
+  function LSauthMethod_anonymous() {
+               LSauth :: disableLoginForm();
+               LSauth :: disableLogoutBtn();
+               LSauth :: disableSelfAccess();
+               
+               if (!parent :: LSauthMethod())
+                       return;
+                       
+               if ( (!defined('LSAUTHMETHOD_ANONYMOUS_USER')) || (constant('LSAUTHMETHOD_ANONYMOUS_USER') == "")) {
+                       LSerror :: addErrorCode('LSauthMethod_anonymous_01');
+                       return;
+               }
+               return true;
+       }
+
+  /**
+   * Check Auth Data
+   * 
+   * Return authentication data or false
+   * 
+   * @retval Array|false Array of authentication data or False
+   **/
+  public function getAuthData() {
+               $this -> authData = array(
+                       'username' => LSAUTHMETHOD_ANONYMOUS_USER
+               );
+    return $this -> authData;
+  }
+  
+}
+/*
+ * Error Codes
+ */
+LSerror :: defineError('LSauthMethod_anonymous_01',
+_("LSauthMethod_anonymous : You must define the LSAUTHMETHOD_ANONYMOUS_USER contant in the configuration file.")
+);
+?>
index 110e047..1596f75 100644 (file)
@@ -1372,6 +1372,7 @@ class LSsession {
     $GLOBALS['Smarty'] -> assign('lang_label',_('Language'));
     
     $GLOBALS['Smarty'] -> assign('displayLogoutBtn',LSauth :: displayLogoutBtn());
+    $GLOBALS['Smarty'] -> assign('displaySelfAccess',LSauth :: displaySelfAccess());
 
     // Infos
     if((!empty($_SESSION['LSsession_infos']))&&(is_array($_SESSION['LSsession_infos']))) {
@@ -1627,13 +1628,15 @@ class LSsession {
         $LSaccess[self :: $topDn] = $access;
       }
     }
-    foreach($LSaccess as $dn => $access) {
-      $LSaccess[$dn] = array_merge(
-        array(
-          'SELF' => 'My account'
-        ),
-        $access
-      );
+    if (LSauth :: displaySelfAccess()) {
+      foreach($LSaccess as $dn => $access) {
+        $LSaccess[$dn] = array_merge(
+          array(
+            'SELF' => 'My account'
+          ),
+          $access
+        );
+      }
     }
     
     self :: $LSaccess = $LSaccess;
index 29b2b23..887d27a 100644 (file)
@@ -45,7 +45,7 @@
       </select>
       <input type='submit' value='->'/>
     </form>
-    {$connected_as} <span id='user_name'>{$LSsession_username}</span>{if $displayLogoutBtn} <a href='index.php?LSsession_logout'><img src='{$LS_IMAGES_DIR}/logout.png' alt='Logout' title='Logout' /></a>{/if}
+    {if $displaySelfAccess}{$connected_as} <span id='user_name'>{$LSsession_username}</span>{/if}{if $displayLogoutBtn} <a href='index.php?LSsession_logout'><img src='{$LS_IMAGES_DIR}/logout.png' alt='Logout' title='Logout' /></a>{/if}
     </td>
   </tr>
   <tr>