emreakay / CodeIgniter-Aauth

Authorization, Authentication and User Management library for Codeigniter 2.x and 3.x to make easy user management and permission operations
http://emreakay.com
GNU Lesser General Public License v3.0
393 stars 235 forks source link

Create Another Function Like is_admin #246

Closed ikramkhizar closed 4 years ago

ikramkhizar commented 5 years ago

Hello Sir, first of all i love this library and having fun using it, i have a question i am using $this->aauth->is_admin() function it work's fine, i have another group for customer is there any possibilities to create a function like is_customer that validates if the user is customer ? if yes then how can you please guide ?

REJack commented 5 years ago

You mean is_member(), you can check with this functions if an user is member of a desired group, e.g. is_member('customer')

ikramkhizar commented 5 years ago

i have to check for a group like admin is a group and customer is also a group so i want to check like this aauth->is_customer? is it possible?

emreakay commented 5 years ago

Hi @ikramkhizar actually you can extend and create a function inside your your controller file (such as My_Controller) and create functions that u want.

ikramkhizar commented 5 years ago

i tried to extend is_admin() function in aauth file but it won't work.

ikramkhizar commented 5 years ago

can you please guide me properly in detail?

yahyaerturan commented 5 years ago
function is_admin()
{
    return is_member('admin');
}

Something like this, I presume.

ikramkhizar commented 5 years ago

I have tried this but it won't work.

REJack commented 5 years ago

Where did you placed this lines, inside the Aauth Class?

function is_admin()
{
    return is_member('admin');
}

If you placed this inside Aauth Class, try this

public function is_admin()
{
    return $this->is_member('admin');
}

also you can add this for a custom function

public function is_customer()
{
    return $this->is_member('customer');
}
emreakay commented 5 years ago

Where did you placed this lines, inside the Aauth Class?

function is_admin()
{
    return is_member('admin');
}

If you placed this inside Aauth Class, try this

public function is_admin()
{
    return $this->is_member('admin');
}

also you can add this for a custom function

public function is_customer()
{
    return $this->is_member('customer');
}

it should have worked.

ikramkhizar commented 5 years ago

could i have to do this in application->libraries->aauth ?

REJack commented 5 years ago

should be yes, but you can create a helper for this too ^^

the content for the helper could look like this:

function is_admin()
{
   $CII =& get_instance();
   $CII->load->library('aauth');
    return $CII->aauth->is_member('admin');
}
function is_customer()
{
   $CII =& get_instance();
   $CII->load->library('aauth');
    return $CII->aauth->is_member('customer');
}