0

We can authenticate employees using identityclass feature provided in yii2. What if Admin is not an employee.?

Can we have two identity class in config.php or how to implement such case?

Questions
  • 69
  • 1
  • 12
  • You don't need to have two identity class for it. Use the rbac wisely and it can be done via permission. – user773440 Aug 15 '17 at 15:15
  • How can we do it using RBAC – Questions Aug 15 '17 at 15:30
  • Create a table user group( amin, employee,moderator...) and create roles with those names, then use the user group in your user table. Follow user guide create permissions and roles. http://www.yiiframework.com/doc-2.0/guide-security-authorization.html#using-db-manager .and check in your controller using \Yii::$app->user->can('PERMISSON'). It is simple as that. – user773440 Aug 15 '17 at 15:52
  • As Samit stated, you can do it using RBAC - create two roles "Admin" and "Employee" and assign them to users. Or you can create two different applications (using advanced yii2 template) and implement 2 identityclasses for each of them (of course you should divide users somehow in DB) – Yerke Aug 15 '17 at 15:52
  • I just have Employee table where fields are(EmpId, FirstName,MiddleName,) etc. Now I have assigned identityClass to be app\models\Employee. I have created the four tables auth_item, auth_item_child, auth_rule and cuth_assignment and inserted the entries in auth_item as admin and fieldofficer (i.e, roles created). Similarly I also assigned admin to one employee and field officer to two another employee. Now in Controller I have coded the access rules for above roles. Now when first field officer creates group, he should be able to view and update only his group details and not others – Questions Aug 15 '17 at 16:13
  • @Questions creates the rules. It is mentioned in the link I shared above. – user773440 Aug 15 '17 at 17:15
  • I have employee table and RBAC is implemented successfully. Now I have Pastor table. I can't have employee as Pastor because there are some fields in pastor table different from employee table. I will have to create a section for pastor. Now how should I implement login functionality using these two tables and at the same time how to make changes in the RBAC tables? – Questions Sep 11 '18 at 12:41

1 Answers1

0

Yes , You can create another identity class for admin type user follow below link :

Vist multiple user identity in config Yii2