Source for file class.auth.php

Documentation is available at class.auth.php

  1. <?php
  2. /**
  3. @package    jelix
  4. @subpackage auth_driver
  5. @author      Laurent Jouanneau
  6. @contributor Yannick Le Guédart (adaptation de jAuthDriverDb pour une classe quelconque)
  7. @copyright   2006-2011 Laurent Jouanneau, 2006 Yannick Le Guédart
  8. @licence  http://www.gnu.org/licenses/lgpl.html GNU Lesser General Public Licence, see LICENCE file
  9. */
  10.  
  11. /**
  12.  * interface for classes used with the jAuthDriverClass
  13. @package    jelix
  14. @subpackage auth_driver
  15. @see jAuth
  16. @since 1.0b2
  17.  */
  18. interface jIAuthDriverClass {
  19.     /**
  20.     * save a new user
  21.     * @param object $user user informations
  22.     */
  23.     public function insert($user);
  24.  
  25.     /**
  26.     * delete a user
  27.     * @param string $login login of the user to delete
  28.     */
  29.     public function deleteByLogin($login);
  30.  
  31.     /**
  32.     * update user informations
  33.     * @param object $user user informations
  34.     */
  35.     public function update($user);
  36.  
  37.     /**
  38.     * get user informations
  39.     * @param string $login login of the user on which we want to get informations
  40.     * @return object user informations
  41.     */
  42.     public function getByLogin($login);
  43.  
  44.     /**
  45.     * create an empty object which will contains user informations
  46.     * @return object user informations (empty)
  47.     */
  48.     public function createUserObject();
  49.  
  50.     /**
  51.     * gets all users
  52.     * @return array list of users
  53.     */
  54.     public function findAll();
  55.  
  56.     /**
  57.     * gets all users for which the login corresponds to the given pattern
  58.     * @param string $pattern the pattern
  59.     * @return array list of users
  60.     */
  61.     public function findByLoginPattern($pattern);
  62.  
  63.     /**
  64.     * change the password of a user
  65.     * @param string $login the user login
  66.     * @param string $password the new encrypted password
  67.     */
  68.     public function updatePassword($login$cryptedpassword);
  69.  
  70.     /**
  71.     * get the user corresponding to the given login and encrypted password
  72.     * @param string $login the user login
  73.     * @param string $password the new encrypted password
  74.     * @return object user informations
  75.     */
  76.     public function getByLoginPassword($login$cryptedpassword);
  77. }
  78.  
  79.  
  80. /**
  81. * Driver for a class which implement an authentification
  82. @package    jelix
  83. @subpackage auth_driver
  84. @see jAuth
  85. @since 1.0a5
  86. */
  87. class classAuthDriver extends jAuthDriverBase implements jIAuthDriver {
  88.  
  89.     public function saveNewUser($user){
  90.         $class jClasses::create($this->_params['class']);
  91.         $class->insert($user);
  92.         return true;
  93.     }
  94.  
  95.     public function removeUser($login){
  96.         $class jClasses::create($this->_params['class']);
  97.         $class->deleteByLogin($login);
  98.         return true;
  99.     }
  100.  
  101.     public function updateUser($user){
  102.         $class jClasses::create($this->_params['class']);
  103.         $class->update($user);
  104.         return true;
  105.     }
  106.  
  107.     public function getUser($login){
  108.         $class jClasses::create($this->_params['class']);
  109.         return $class->getByLogin($login);
  110.     }
  111.  
  112.     public function createUserObject($login,$password){
  113.         $class jClasses::create($this->_params['class']);
  114.         $user $class->createUserObject();
  115.         $user->login $login;
  116.         $user->password $this->cryptPassword($password);
  117.         return $user;
  118.     }
  119.  
  120.     public function getUserList($pattern){
  121.         $class jClasses::create($this->_params['class']);
  122.         if($pattern == '%' || $pattern == ''){
  123.             return $class->findAll();
  124.         }else{
  125.             return $class->findByLoginPattern($pattern);
  126.         }
  127.     }
  128.  
  129.     public function changePassword($login$newpassword){
  130.         $class jClasses::create($this->_params['class']);
  131.         return $class->updatePassword($login$this->cryptPassword($newpassword));
  132.     }
  133.  
  134.     public function verifyPassword($login$password){
  135.         if (trim($password== '')
  136.             return false;
  137.         $classuser jClasses::create($this->_params['class']);
  138.  
  139.         $user $classuser->getByLoginPassword($login$this->cryptPassword($password));
  140.  
  141.         return ($user?$user:false);
  142.     }
  143.  
  144. }

Documentation generated on Mon, 19 Sep 2011 14:11:24 +0200 by phpDocumentor 1.4.3