Useraccess

Hi All,

I am developing a site for a tour and travel company. Site defines various roles like admin, agent, members. I want to give access to modules based on the role type. Pl i need urgent help.

what should i change in accessRules() of the controller file

    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 authenticated user to perform 'create' and 'update' actions


			'actions'=>array('create','update'),


			'users'=>array('@'),


		),


		array('allow', // allow admin user to perform 'admin' and 'delete' actions


			'actions'=>array('admin','delete'),


			'users'=>array('admin'),


		),


		array('deny',  // deny all users


			'users'=>array('*'),


		),


	);


}

I have attached a screenshot that defines db structure. Text highlighted in bold are table name, text in red are field names and text in blue are values. 4441

Access.png

My suggestion. Try to use single user table and split the user by user type

Hello,

Even if i do that i have 3 roles Admin, Agent and Member. I want to give admin,create and delete access to Admin only, Modify access to Agent and view access to all Admin, Agent and Member.

Pl help how to achive this.

I have taken below steps to see if it works

I enabled authManager in main.php by added below code

   'authManager'=>array(


        'class'=>'CDbAuthManager',


        'connectionID'=>'db',


    ),

I modified UserIdentity.php as below :

    $auth=Yii::app()->authManager;


    $auth->createRole($user_account->id);


        


    if (!$auth->isAssigned($user->role, $this->_id)) {


    	if ($auth->assign($model->role, $this->_id)) {


        		yii::app()->authmanager->save();


        	}


    }

It started giveing me error:

CDbCommand failed to execute the SQL statement: SQLSTATE[42S02]: Base table or view not found: 1146 Table ‘testdrive.AuthItem’ doesn’t exist. The SQL statement executed was: INSERT INTO AuthItem (name, type, description, bizrule, data) VALUES (:name, :type, :description, :bizrule, :data)

I wants to know what is the table structure of AuthItem. The fields getting seen in the insert query are the only one or there are more fields.

Hi

you can something like this


public function defaultAccessRules()

	{

		return array(

               array('allow',  // allow all users to perform 'index' and 'view' actions

				'actions'=>array('index','view',),

				'users'=>array('*'),

		),

		array('allow', // allow authenticated user to perform 'create' and 'update' actions

				'actions'=>array('create','delete'),

				'users'=>array('admin'),

		),

		array('allow', // allow authenticated user to perform 'create' and 'update' actions

				'actions'=>array('update'),

				'users'=>array('Agent'),

		),

		

	);

	}

Can you help me with the below authorization code… where to put and how to execute:

$auth=Yii::app()->authManager;

$bizRule=‘return !Yii::app()->user->isGuest;’;

$auth->createRole(‘authenticated’, ‘authenticated user’, $bizRule);

$bizRule=‘return Yii::app()->user->isGuest;’;

$auth->createRole(‘guest’, ‘guest user’, $bizRule);

$bizRule=‘return Yii::app()->user->name === “admin”;’;

$role = $auth->createRole(‘admin’, ‘administrator’);

$auth->assign(‘admin’,1); // adding admin to first user created

$bizRule = ‘return Yii::app()->user->id==$params[“User”]->id;’;

$auth->createTask(‘updateSelf’, ‘update own information’, $bizRule);

$role = $auth->getAuthItem(‘authenticated’); // pull up the authenticated role

$role->addChild(‘updateSelf’); // assign updateSelf tasks to authenticated users

$auth->save();

Solved: pl check http://www.yiiframework.com/forum/index.php/topic/44894-creating-authorization-roles/