I am getting this error after logging in.
LOGIN FORM:
class LoginForm extends CFormModel
{
public $username;
public $password;
public $rememberMe;
private $_identity;
public function rules()
{
return array(
// username and password are required
array('username, password', 'required'),
// rememberMe needs to be a boolean
array('rememberMe', 'boolean'),
// password needs to be authenticated
array('password', 'authenticate'),
);
}
public function attributeLabels()
{
return array(
'rememberMe'=>'Remember me next time',
);
}
public function authenticate($attribute,$params)
{
if(!$this->hasErrors())
{
$this->_identity=new UserIdentity($this->username,$this->password);
if(!$this->_identity->authenticate())
$this->addError('password','Incorrect username or password.');
}
}
public function login($identity,$duration)
{
if($this->_identity===null)
{
$this->_identity=new UserIdentity($this->username,$this->password);
$this->_identity->authenticate();
}
if($this->_identity->errorCode===UserIdentity::ERROR_NONE)
{
$duration=$this->rememberMe ? 3600*24*30 : 0; // 30 days
Yii::app()->user->login($this->_identity,$duration);// --> HERE THE STACKTRACE SHOWING THE ERROR
return true;
}
else
return false;
}
}
USER.PHP
class user extends CActiveRecord
{
public function validatePassword($password)
{
return CPasswordHelper::verifyPassword($password,$this->password);
}
public function hashPassword($password)
{
return CPasswordHelper::hashPassword($password);
}
public static function model($className=__CLASS__)
{
return parent::model($className);
}
public function tableName()
{
return 'user';
}
public function rules()
{
return array(
array('', 'safe', 'on'=>'search'),
);
}
public function relations()
{
return array(
);
}
public function attributeLabels()
{
return array(
);
}
public function search()
{
$criteria=new CDbCriteria;
return new CActiveDataProvider('user', array(
'criteria'=>$criteria,
));
}
}
USER IDENTITY.PHP
class UserIdentity extends CUserIdentity
{
private $_id;
public function authenticate()
{
$user = Tblusers::model()->findByAttributes( array( 'email' => $this->username));
if ($user===null) { // No user was found!
$this->errorCode=self::ERROR_USERNAME_INVALID;
}
else if($user->password !== md5($this->password))
{
$this->errorCode=self::ERROR_PASSWORD_INVALID;
}
else {
$this->errorCode=self::ERROR_NONE;
$this->_id = $user->user_id;
}
return !$this->errorCode;
}
public function getId() // override Id
{
return $this->_id;
}
}