Hi all
In my database I have a table called user_table. It has columns called user_name, user_type and password.
In my application when I give admin , admin as username and password it will shows manage tables to me. if I use another name instead of admin, it will not display manage page to me.
How can I fix that problem.
This is my UserIdentity.php
<?php
/**
* UserIdentity represents the data needed to identity a user.
* It contains the authentication method that checks if the provided
* data can identity the user.
*/
class UserIdentity extends CUserIdentity
{
/**
* Authenticates a user.
* The example implementation makes sure if the username and password
* are both 'demo'.
* In practical applications, this should be changed to authenticate
* against some persistent user identity storage (e.g. database).
* @return boolean whether authentication succeeds.
*/
private $_id;
public function authenticate()
{
$record=UserTable::model()->findByAttributes(array('user_name'=>$this->username)); // here I use Email as user name which comes from database
if($record===null)
{
$this->_id='user Null';
$this->errorCode=self::ERROR_USERNAME_INVALID;
}
else if($record->user_password!==$this->password) // here I compare db password with passwod field
{ $this->_id=$this->username;
$this->errorCode=self::ERROR_PASSWORD_INVALID;
}
/*else if($record['E_STATUS']!=='Active') // here I check status as Active in db
{
$err = "You have been Inactive by Admin.";
$this->errorCode = $err;
} */
else
{
//$this->_id=$record['user_name'];
$this->_id=$record->user_id;
//$this->setState('title', $record['user_name']);
$this->setState('user_type', $record->user_type);
//Yii::app()->user->getState('user_type', $record->user_type);
$this->errorCode=self::ERROR_NONE;
}
return !$this->errorCode;
}
public function getId() // override Id
{
return $this->_id;
}
}