<?php
class UserIdentity extends CUserIdentity
{
 private $_id;
 private $level;
  private $loket;
 private $usernamex;
 /**
 * Authenticates a user.
 * @return boolean whether authentication succeeds.
 */
 public function authenticate()
 {
 $username = strtolower($this->username);
 $user = User::model()->find('LOWER(username)=?', array($username));
 
 if($user===null)
   $this->errorCode=self::ERROR_USERNAME_INVALID;
 
 else if(!$user->check($this->password))
   $this->errorCode = self::ERROR_PASSWORD_INVALID;
 
 else{
   // successful login
   $this->_id = $user->id;
   $this->username = $user->username;
   $this->setState('level', $user->level);
    $this->setState('loket', $user->loket);
     $this->setState('usernamex', $user->username);
    //untuk memanggil level di database menggunakan EWebUser.php nanti
	//$this->setState('unit', $user->unit); //untuk memanggil unit di database menggunakan EWebUser.php nanti
   $this->errorCode = self::ERROR_NONE;
 }
 return $this->errorCode == self::ERROR_NONE;
 }
 
 public function getId()
 {
   return $this->_id;
 }
}