Guest User

Untitled

a guest
Oct 23rd, 2017
87
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
PHP 0.90 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.     private $_id;
  11.  
  12.     public function authenticate()
  13.     {
  14.         $username=strtolower($this->username);
  15.         $user=User::model()->find('LOWER(username)=?',array($username));
  16.         if($user===null)
  17.             $this->errorCode=self::ERROR_USERNAME_INVALID;
  18.         else if(!$user->validatePassword($this->password))
  19.             $this->errorCode=self::ERROR_PASSWORD_INVALID;
  20.         else
  21.         {
  22.             $this->_id=$user->id;
  23.             $this->username=$user->username;
  24.             $this->errorCode=self::ERROR_NONE;
  25.         }
  26.         return $this->errorCode==self::ERROR_NONE;
  27.     }
  28.  
  29.     public function getId()
  30.     {
  31.         return $this->_id;
  32.     }
  33. }
Add Comment
Please, Sign In to add comment