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 $cryptedpassword 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 $cryptedpassword the new encrypted password
  74.     * @return object user informations
  75.     * @deprecated since 1.2.10
  76.     */
  77.     public function getByLoginPassword($login$cryptedpassword);
  78. }
  79.  
  80.  
  81. /**
  82. * Driver for a class which implement an authentification
  83. @package    jelix
  84. @subpackage auth_driver
  85. @see jAuth
  86. @since 1.0a5
  87. */
  88. class classAuthDriver extends jAuthDriverBase implements jIAuthDriver {
  89.  
  90.     public function saveNewUser($user){
  91.         $class jClasses::create($this->_params['class']);
  92.         $class->insert($user);
  93.         return true;
  94.     }
  95.  
  96.     public function removeUser($login){
  97.         $class jClasses::create($this->_params['class']);
  98.         $class->deleteByLogin($login);
  99.         return true;
  100.     }
  101.  
  102.     public function updateUser($user){
  103.         $class jClasses::create($this->_params['class']);
  104.         $class->update($user);
  105.         return true;
  106.     }
  107.  
  108.     public function getUser($login){
  109.         $class jClasses::create($this->_params['class']);
  110.         return $class->getByLogin($login);
  111.     }
  112.  
  113.     public function createUserObject($login,$password){
  114.         $class jClasses::create($this->_params['class']);
  115.         $user $class->createUserObject();
  116.         $user->login $login;
  117.         $user->password $this->cryptPassword($password);
  118.         return $user;
  119.     }
  120.  
  121.     public function getUserList($pattern){
  122.         $class jClasses::create($this->_params['class']);
  123.         if($pattern == '%' || $pattern == ''){
  124.             return $class->findAll();
  125.         }else{
  126.             return $class->findByLoginPattern($pattern);
  127.         }
  128.     }
  129.  
  130.     public function changePassword($login$newpassword){
  131.         $class jClasses::create($this->_params['class']);
  132.         return $class->updatePassword($login$this->cryptPassword($newpassword));
  133.     }
  134.  
  135.     public function verifyPassword($login$password){
  136.         if (trim($password== '')
  137.             return false;
  138.         $class jClasses::create($this->_params['class']);
  139.         $user $class->getByLogin($login);
  140.         if (!$user{
  141.             return false;
  142.         }
  143.  
  144.         $result $this->checkPassword($password$user->password);
  145.         if ($result === false)
  146.             return false;
  147.  
  148.         if ($result !== true{
  149.             // it is a new hash for the password, let's update it persistently
  150.             $user->password $result;
  151.             $class->updatePassword($login$result);
  152.         }
  153.  
  154.         return $user;
  155.     }
  156.  
  157. }

Documentation generated on Thu, 19 Sep 2013 00:01:13 +0200 by phpDocumentor 1.4.3