After sometime of ideal page this error is coming
Property "CWebUser.role" is not defined.
D:\xampp\htdocs\project\framework\web\auth\CWebUser.php(146)
Here is my code below
DefaultController:
class DefaultController extends Controller
{
[indent]
public function actionLogin() {
[indent]$this->layout = ‘//layouts/limitless_login’;
if (!isset(Yii::app()->user->id)) {
$model = new AdminLoginForm;
if (isset($_POST[‘AdminLoginForm’])) {
[indent]$model->attributes = $_POST['AdminLoginForm'];
if ($model->validate() && $model->login()) {
$this->redirect(Yii::app()->user->returnUrl);
}[/indent]
}
$this->render('login', array('model' => $model,'authUrl'=>$authUrl));
}
[/indent]
[/indent]
}
AdminLoginForm:
class AdminLoginForm extends CFormModel
{
[indent]public $username;
public $password;
public $email;
public $rememberMe;
public function rules()
{
[indent]return array(
[indent]// 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'),[/indent]
);[/indent]
}
public function attributeLabels()
{
[indent]return array(
[indent]'rememberMe'=>'Remember me next time',
'username'=>'User Name',[/indent]
);[/indent]
}
public function authenticate($attribute,$params)
{
[indent]if(!$this->hasErrors())
{
[indent]$this->_identity=new UserIdentity($this->username,$this->password);
if(!$this->_identity->authenticate())
[indent]$this->addError('password','Incorrect username or password');[/indent][/indent]
}[/indent]
}
public function login()
{
[indent]if($this->_identity===null)
{
[indent]$this->_identity=new UserIdentity($this->username,$this->password);
$this->_identity->authenticate();[/indent]
}
if($this->_identity->errorCode===UserIdentity::ERROR_NONE)
{
[indent]$duration=$this->rememberMe ? 3600*24*30 : 0; // 30 days
Yii::app()->user->login($this->_identity,$duration);
return true;[/indent]
}
else
[indent]return false;[/indent][/indent]
}[/indent]
}
UserIdentity :
class UserIdentity extends CUserIdentity
{
[indent] private $_id;
private $_name;
private $_role;
public function authenticate()
{
[indent] $user = AdminUser::model()->find('LOWER(username)=?', array(strtolower($this->username)));
if ($user === null)
{
[indent]$this->errorCode = self::ERROR_USERNAME_INVALID;[/indent]
}
else {
[indent] $this->_id = $user->user_id;
$this->_role = $user->role;
$this->_name = $user->username;
Yii::app()->user->setState('name',$user->username);
Yii::app()->user->setState('username',$user->username);
Yii::app()->user->setState('role',$user->role);
$this->errorCode = self::ERROR_NONE;[/indent]
}
return!$this->errorCode;[/indent]
}
public function getId()
{
[indent] return $this->_id;[/indent]
}
public function getUsername() {
[indent] return $this->_name;[/indent]
}
public function getRole() {
[indent]return $this->_role;[/indent]
}[/indent]
}
Can some one say why is this happening, if session time out it goes to login page. The session is on I can get user->id but not user->role, but it coming all the time after I logged in and continuous use of app, after ideal time this message is coming.
Thanks in advance