Reputation: 1051
I've been following the instructions here (http://www.yiiframework.com/doc/guide/1.1/en/topics.auth) to add DB based authorization and users with Yii. I can log in with a user defined in the user table, but i cannot log in as an admin. I can see 1 row in my authassignment table with itemname 'admin' with a key to user id 1 - which is the user im using to log in.
My authManager looks like this:
'authManager'=>array(
'class'=>'CDbAuthManager',
'connectionID'=>'db',
'defaultRoles'=>array('authenticated', 'admin'),
),
And the access rules for the particular controller im using are:
public function accessRules() {
return array(
array('allow', // allow all users to perform 'index' and 'view' actions
'actions' => array('index', 'view'),
'users' => array('*'),
),
array('allow', // allow admin user to perform 'admin' and 'delete' actions
'actions' => array('admin', 'delete','create', 'update'),
'users' => array('admin'),
),
array('deny', // deny all users
'users' => array('*'),
),
);
}
Attempting to use the 'admin' action results in a 403 error. I can't seem to get around this. Any suggestions?
EDIT:
So knowing that the bizrule for the admin authitem is return Yii::app()->user->name === "admin";
, I changed the username of the user to 'admin' and it of course worked. What do I need to change the bizrule to to let anyway who is an admin in the authassignment table log in as a admin?
Upvotes: 0
Views: 2351
Reputation: 4708
You can specify roles
in the accessRules, see http://www.yiiframework.com/doc/guide/1.1/en/topics.auth#access-control-filter and http://www.yiiframework.com/doc/api/1.1/CAccessRule#roles-detail
class PostController extends CController
{
......
public function accessRules()
{
return array(
array('allow',
'actions'=>array('admin'),
'roles'=>array('admin'),
),
);
}
}
Upvotes: 1