mejuliver / CI-roles-permissions

Roles and permissions for codeigniter
Apache License 2.0
1 stars 1 forks source link

Practical example #1

Open oldcastlehq opened 6 years ago

oldcastlehq commented 6 years ago

I'm trying to get my head around it, but I still cannot figure out this works.

Let's say I'm building a ecommerce marketplace website. As a marketplace, there are 3 main roles. The admin, the vendors and the customers. Can this helper do this setup?

Futher, can this help handle with sub-groups or sub-users. For example. Let's say that a vendor ACME has multiple deparments. So, I would like to create an account for each department like electroncis, clothes, shoes..and so on, but all of them would belong to the ACME account.

I hope I made sense. It would be great to see a tutorial or a demo showing a practical example of how to work with this script.

mejuliver commented 6 years ago

@oldcastlehq

First copy the isauth_helper and rolespermissions_helper to your application helpers folder (application/helpers)

then copy the hooks.php to your application/config

then autoload isauth helper and rolespermissions helper

make sure you enabled the hooks from the config.php by setting it to TRUE

user must be authenticated first so that everything will work, attach session on user's authentication, example I have account controller where I process all the login things so I just do

$this->session->set_userdata('auth',true);
$user_info = [ 'users_id' => $users_id ];
$this->session->set_userdata('user_info',$user_info);

this module caters only the basic purpose of a roles and permissions. You can add multiple roles and permissions and attach multiple roles and permissions to a user. You can check if the current user has a role of admin for example

if( inRole('admin'))

or you can specify a group of roles by providing an array of roles

if( inRole(['admin','user'])

and if you want to check if the current user has a permission(s) you can do

if( canPerm('can edit') )

you can also specify a group of permissions by providing an array of permissions just like the role above, return false if neither from the items on the given array does not exist on user's permissions

oldcastlehq commented 6 years ago

Thank you @mejuliver, but I don't think you answered my questions. I understood how to install it. But I cannot figure out if I can create sub-groups for a particular users. Something like:

 -- User 1
 -- User 2 (parent)
    |_ _ _ user 3 (child)
    |_ _ _ user 4 (child)
-- User 5

Please correct me if I'm wrong, but the idea of having sub-groups is to keep related accounts together. In my example, let's say that a big retail wants to join my marketplace. However, they want that each of their departments to be independet and list their own products. So, what are my options here?

a) I create one accoutn for each deparment. OR b) I create one parent account, then sub-account for each department.