which sign means definit user (by status)

Hi,

In my table (bd) user I have a following field :

[sql]/* … */

status enum(‘admin’,‘user’,’’) DEFAULT ‘user’,[/sql]

And I put some condition on my product controller :




//...

// user --> logOUT Guest


if(Yii::$app->user->isGuest){

//...

'roles' => ['?'], // ? means  Guests 

//...

else if(!Yii::$app->user->isGuest && Yii::$app->user->identity->status == "admin")

//...

'roles' => ['@'], // '@' means All logged in users / or your access role e.g. 'admin', 'user'

//...

// user --> logIN and is NOT a 'admin' (status) so his status 'user' in db

else

//...

'allow' => true, // Has access


//'roles' => ['?'], // ? means  Guests

'roles' => ['user'], // user means  user

//etc



I want that, in last condition (the user is logged with ‘user’ status)

This user can view the product page but he do not not delete some item

When I use [’[font=“Arial Black”]?[/font]’] he can delete it :angry:

When I use [’[font=“Arial Black”]user[/font]’] he don not view the product page : You are not allowed to perform this action.

I can not use [’@’] for this situation

So what must I put it in [’ ']? :mellow:

Here is my code :


		// user --> logOUT Guest

		if(Yii::$app->user->isGuest){

			return 

				[

					'access' => 

						[

							'class' => AccessControl::className(),

							'rules' => 

							[

								[

									'allow' => false, // Has NOT access

									'roles' => ['?'], // ? means  Guests 

								],

							],

						],

					'verbs' => 

						[

							'class' => VerbFilter::className(),

							'actions' => 

								[

									'delete' => ['POST'],

								],

						],

				];

		}

		// user --> logIN and is a 'admin' (status)

		else if(!Yii::$app->user->isGuest && Yii::$app->user->identity->status == "admin"){

			return 

				[

					'access' => 

						[

							'class' => AccessControl::className(),

							'only' => 

								[

									'index',

									'view', 

									'create',

									'update'

								], //only be applied to

							'rules' => 

							[

								[

									'allow' => true, // Has access

									'roles' => ['@'], // '@' means All logged in users / or your access role e.g. 'admin', 'user'

								],

							],

						],

					'verbs' => 

						[

							'class' => VerbFilter::className(),

							'actions' => 

								[

									'delete' => ['POST'],

								],

						],

				];

		}

		// user --> logIN and is NOT a 'admin' (status) so his status 'user' in db Il supprime tout

		else

		{

			return

				[

					'access' =>

						[

							'class' => AccessControl::className(),

							'only' => 

								[

									'index',

									'view'

								],//only be applied to

								

							'rules' => 

								[

									[

										'allow' => true, // Has access

										//'roles' => ['?'], // ? means  Guests 

										'roles' => ['user'], // user means  user 

									],

								],

						],

				];

		}

    }	

	

Thanks

HI,

Do you have some idea for this problem :mellow:

Thanks

Sorry, I never used RBAC.

If you only need to discriminate between guest, authenticated users and a user e.g named "admin" ACF should be enough (I think) (I think I know)

The sections in the guide in this post

A wiki on easy impementation of RBAC in advanced template in this post

Installation guide for advanced template here

You may want to study how users stored in db is implemented in the advanced template and also other references to it in the wiki I found/linked to. I haven’t looked.

Tip: If you think you need to write a lot of if-then-else control statements you may be on the wrong track.

OK Thanks Tri :rolleyes: