Advertisement
Guest User

useridentity

a guest
Dec 19th, 2012
77
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
PHP 1.21 KB | None | 0 0
  1. <?php
  2.  
  3. /**
  4.  * UserIdentity represents the data needed to identity a user.
  5.  * It contains the authentication method that checks if the provided
  6.  * data can identity the user.
  7.  */
  8. class UserIdentity extends CUserIdentity
  9. {
  10.  
  11.      // Need to store the user's ID:
  12.      private $_id;
  13.  
  14.  
  15.     /**
  16.      * Authenticates a user.
  17.      * The example implementation makes sure if the username and password
  18.      * are both 'demo'.
  19.      * In practical applications, this should be changed to authenticate
  20.      * against some persistent user identity storage (e.g. database).
  21.      * @return boolean whether authentication succeeds.
  22.      */
  23.     public function authenticate()
  24.     {
  25.         $user = leraar::model()->findByAttributes(array('leraarCode'=>$this->username));
  26.  
  27.         if ($user===null) { // No user found!
  28.             $this->errorCode=self::ERROR_USERNAME_INVALID;
  29.         } else if ($user->password !== SHA1($this->password) ) { // Invalid password!
  30.             $this->errorCode=self::ERROR_PASSWORD_INVALID;
  31.         } else { // Okay!
  32.             $this->errorCode=self::ERROR_NONE;
  33.             // Store the role in a session:
  34.             //$this->setState('role', $user->role);
  35.             $this->_id = $user->id;
  36.         }
  37.         return !$this->errorCode;
  38.     }
  39.    
  40.     public function getId()
  41.     {
  42.      return $this->_id;
  43.     }
  44.  
  45.    
  46. }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement