checkAccess() doesn't work


        'authManager'=>array(

            'class'=>'CDbAuthManager',

            'defaultRoles'=>array('guest'),

            'connectionID'=>'db',

That is my default role and for some reason it remains the active role, even after logging in. When I log in as superadmin with all operations and child roles assigned to my account, Yii::app()->user->checkAccess() only returns true for operations that are assigned to guests.

Did you assigned the role to your superadmin?




Yii::app()->authManager->assign('aminUser', 'adminRole');



Yes, print_r(Yii::app()->authManager->getRoles(1)); returns a CAuthItem Object called superadmin. "1" is my user id.

I have found the problem. For some reason Yii::app->user->getId() returns the name rather than the unique key of the member.

Hi, did you find a way to resolve the problem? I’m having the same issue… getId returns the name and checkAccess doesn’t work…

found it :) forgot to override the getId method in UserIdentity class to return $_id :)

could you please help me. let me know this is correct or not

private $_id;

/**


* Authenticates a user using the User data model.


* @return boolean whether authentication succeeds.


*/


public function authenticate()


{


	$user=User::model()->findByAttributes(array('username'=>$this->username));


	if($user===null)


	{


		$this->errorCode=self::ERROR_USERNAME_INVALID;


	}


	else


	{


		if($user->password!==$user->encrypt($this->password))


		{


			$this->errorCode=self::ERROR_PASSWORD_INVALID;


		}


		else


		{


			$this->_id = $user->id;


			if(null===$user->last_login_time)


		{


			$lastLogin = time();


		}		


		else


		{


			$lastLogin = strtotime($user->last_login_time);


		}


	$this->setState('lastLoginTime', $lastLogin); $this->errorCode=self::ERROR_NONE;


		}


	}


	return !$this->errorCode;


}


public function getId()


{


	return $this->_id;


}