MCMS
[ class tree: MCMS ] [ index: MCMS ] [ all elements ]

Source for file AuthManager.php

Documentation is available at AuthManager.php

  1. <?php
  2. /* vim: set expandtab tabstop=4 shiftwidth=4: */
  3. // +----------------------------------------------------------------------+
  4. // | MCMS: a PHP Content Management System for creating accessible sites. |
  5. // | Copyright (C) 2005  Silvio Moioli                                    |
  6. // |                                                                      |
  7. // | This program is free software; you can redistribute it and/or modify |
  8. // | it under the terms of the GNU General Public License as published by |
  9. // | the Free Software Foundation; either version 2 of the License, or    |
  10. // | (at your option) any later version.                                  |
  11. // |                                                                      |
  12. // | This program is distributed in the hope that it will be useful,      |
  13. // | but WITHOUT ANY WARRANTY; without even the implied warranty of       |
  14. // | MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the        |
  15. // | GNU General Public License for more details.                         |
  16. // |                                                                      |
  17. // | You should have received a copy of the GNU General Public License    |
  18. // | along with this program; if not, write to the Free Software          |
  19. // | Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA  02111-1307 |
  20. // +----------------------------------------------------------------------+
  21. // | Authors: Silvio Moioli <silvio at moioli dot net> www.moioli.net     |
  22. // +----------------------------------------------------------------------+
  23. //
  24. //$Id:
  25.  
  26. /** Carica la classe base di MCMS per l'interfacciamento al Database */
  27. require_once $_SERVER["DOCUMENT_ROOT"]."/admin/lib/model/Engine.php";
  28. /** Carica il componente di PEAR per l'autenticazione degli utenti */
  29. require_once $_SERVER["DOCUMENT_ROOT"]."/admin/include/pear/Auth.php";
  30. /** Carica la pagina con il form per l'immissione della password */
  31. require_once $_SERVER["DOCUMENT_ROOT"]."/admin/lib/view/AdminLogin.php";
  32.  
  33. /**
  34.  * Gestore dei permessi degli utenti in MCMS. Permette l'aggiunta, la rimozione
  35.  * e la verifica dei permessi di ciascun utente. Inoltre permette il re-login
  36.  * degli utenti.
  37.  *
  38.  * @package MCMS
  39.  * @author Silvio Moioli
  40.  * @version 2
  41.  */
  42. class AuthManager extends PEAR
  43. {
  44.     /** @var Engine l'oggetto per la comunicazione al Database */
  45.     var $engine = null;
  46.     /** @var Auth il componente di PEAR per l'autenticazione degli utenti */
  47.     var $auth = null;
  48.     /** @var Author l'autore correntemente loggato o null */
  49.     var $currentAuthor = null;
  50.  
  51.     /**
  52.      * Costruttore standard.
  53.      *
  54.      * @param Engine $engine l'oggetto per la comunicazione al DB in uso
  55.      */
  56.     function AuthManager($engine)
  57.     {
  58. //        print "dsn: ".$engine->dataSourceName."<br/>";
  59.         $this->engine=$engine;
  60.         $this->initAuthWithoutLoginScreen();
  61.     }
  62.     
  63.     /**
  64.      * Inizializza (o re-inizializza) Auth per non mostrare schermate di login
  65.      * in caso di mancato riconoscimento dell'autore.
  66.      */
  67.     function initAuthWithoutLoginScreen()
  68.     {
  69.         $this->auth = new Auth("DB"$this->engine->dataSourceName,"",false);
  70.         $this->auth->start();
  71.     }
  72.  
  73.     /**
  74.      * Inizializza (o re-inizializza) Auth per mostrare la schermata di login
  75.      * relativa all'autore specificato in caso di mancato riconoscimento dello
  76.      * stesso.
  77.      *
  78.      * @param Author $author l'autore da settare
  79.      */
  80.     function initAuthWithLoginScreen($author)
  81.     {
  82.         $this->currentAuthor = $author;
  83.         $currentLoginPage new AdminLogin($author);  
  84.         $loginFunction array($currentLoginPage,"display");
  85.         $this->auth = new Auth("DB"$this->engine->dataSourceName$loginFunction);
  86.         $this->auth->start();
  87.     }
  88.     
  89.     /**
  90.      * Controlla che l'autore sia effettivamente loggato in MCMS.
  91.      *
  92.      * @param Author $author l'autore da controllare
  93.      * @return true se l'autore è autenticato correttamente
  94.      */
  95.     function checkLogin($author)
  96.     {
  97.         $result true;
  98.         
  99.         $this->initAuthWithoutLoginScreen();
  100.         
  101.         //Un nuovo login è necessario se nessuno lo ha già fatto...
  102.         if ($this->auth->getAuth(!= true{
  103.             $result false;
  104.         }       
  105.         //...o se l'autore tenta di fingersi qualcun altro...
  106.         if ($author->getID(!= $this->auth->getUsername()) {
  107.             $result false;
  108.         }
  109.         return $result;
  110.     }
  111.     
  112.     /**
  113.      * Controlla che l'autore sia effettivamente loggato in MCMS, e che
  114.      * abbia i permessi per modificare un certo oggetto.
  115.      *
  116.      * @param Author $author l'autore da controllare
  117.      * @param mixed l'oggetto da modificare
  118.      * @return true se l'autore è autenticato correttamente e può modificare
  119.      *  l'oggetto
  120.      */
  121.     function isEditAllowed($author$objectToModify)
  122.     {
  123.         $result true;
  124.         
  125.         $this->initAuthWithoutLoginScreen();
  126.                 
  127.         //Valgono innanzitutto le regole viste al metodo precedente
  128.         if ($this->checkLogin($author== false{
  129.             $result false;
  130.         }
  131.         //...o se l'autore non è in realtà il fondatore/autore originale
  132.         $tmp $objectToModify->getAuthor();
  133.         if ($tmp->getID(!= $author->getID()) {
  134.             $result false;
  135.         }
  136.         return $result;
  137.     }
  138.     
  139.     /**
  140.      * Forza l'autore specificato a rifare il login.
  141.      * @param Author $author l'autore
  142.      */
  143.     function reLogin($author)
  144.     {
  145.         $this->auth->logout();
  146.         //Reinizializza Auth
  147.         $this->initAuthWithLoginScreen($author);
  148.     }
  149.     
  150.     /**
  151.      * Rimuove l'autore da quelli che possono accedere a MCMS.
  152.      *
  153.      * @param Author $author l'autore da rimuovere
  154.      */    
  155.     function removeUser($author)
  156.     {
  157.         $this->auth->logout();
  158.         $this->auth->removeUser($author->getID());
  159.     }
  160.     
  161.     /**
  162.      * Aggiunge un nuovo autore tra quelli che possono
  163.      * accedere a MCMS.
  164.      *
  165.      * @param Author $author l'autore da aggiungere
  166.      * @param string $password la sua password
  167.      */    
  168.     function addUser($author$password)
  169.     {
  170.         $this->initAuthWithoutLoginScreen();
  171.         $this->auth->addUser($author->getID()$password);
  172.         $this->auth->setAuth($author->getID());
  173.     }
  174. }
  175.  
  176. ?>

Documentation generated on Wed, 26 Jul 2006 21:44:48 +0200 by phpDocumentor 1.3.0RC6