Yii Framework Forum: property "AdminWebUser.role" is not defined - Yii Framework Forum

Jump to content

Page 1 of 1
  • You cannot start a new topic
  • You cannot reply to this topic

property "AdminWebUser.role" is not defined Rate Topic: -----

#1 User is offline   naveen107 

  • Newbie
  • Yii
  • Group: Members
  • Posts: 8
  • Joined: 17-January 13
  • Location:chennai

Posted 02 March 2018 - 02:43 AM

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
{

public function actionLogin() {
$this->layout = '//layouts/limitless_login';
if (!isset(Yii::app()->user->id)) {
$model = new AdminLoginForm;
if (isset($_POST['AdminLoginForm'])) {
$model->attributes = $_POST['AdminLoginForm'];
if ($model->validate() && $model->login()) {
$this->redirect(Yii::app()->user->returnUrl);
}

}
$this->render('login', array('model' => $model,'authUrl'=>$authUrl));
}


}

AdminLoginForm:
class AdminLoginForm extends CFormModel
{
public $username;
public $password;
public $email;
public $rememberMe;

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',
'username'=>'User Name',

);

}

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()
{
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);
return true;

}
else
return false;

}


}

UserIdentity :
class UserIdentity extends CUserIdentity
{
private $_id;
private $_name;
private $_role;

public function authenticate()
{
$user = AdminUser::model()->find('LOWER(username)=?', array(strtolower($this->username)));
if ($user === null)
{
$this->errorCode = self::ERROR_USERNAME_INVALID;

}
else {
$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;

}
return!$this->errorCode;


}

public function getId()
{
return $this->_id;

}

public function getUsername() {
return $this->_name;

}

public function getRole() {
return $this->_role;

}


}


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
0

Share this topic:


Page 1 of 1
  • You cannot start a new topic
  • You cannot reply to this topic

1 User(s) are reading this topic
0 members, 1 guests, 0 anonymous users