benedmunds / CodeIgniter-Ion-Auth

Simple and Lightweight Auth System for CodeIgniter
http://benedmunds.com/ion_auth/
MIT License
2.34k stars 1.14k forks source link

Is it possible to restrict users to be in more than one group? #995

Closed joha0123 closed 7 years ago

joha0123 commented 8 years ago

Hi, in my application i have three groups (admins, clients, employees). The groups are disjunct. How can i make sure, that a user cannot be in the clients and employees group?

avenirer commented 8 years ago

By adding them only in one group... I guess...

lloricode commented 7 years ago

from documentaion of ion_auth

        # single group (by name)
        $group = 'gangstas';
        if (!$this->ion_auth->in_group($group))
        {
            $this->session->set_flashdata('message', 'You must be a gangsta to view this page');
            redirect('welcome/index');
        }

        # single group (by id)
        $group = 1;
        if (!$this->ion_auth->in_group($group))
        {
            $this->session->set_flashdata('message', 'You must be part of the group 1 to view this page');
            redirect('welcome/index');
        }

        # multiple groups (by name)
        $group = array('gangstas', 'hoodrats');
        if (!$this->ion_auth->in_group($group))
            $this->session->set_flashdata('message', 'You must be a gangsta OR a hoodrat to view this page');
            redirect('welcome/index');
        }

        # multiple groups (by id)
        $group = array(1, 2);
        if (!$this->ion_auth->in_group($group))
            $this->session->set_flashdata('message', 'You must be a part of group 1 or 2 to view this page');
            redirect('welcome/index');
        }

        # multiple groups (by id and name)
        $group = array('gangstas', 2);
        if (!$this->ion_auth->in_group($group))
            $this->session->set_flashdata('message', 'You must be a part of the gangstas or group 2');
            redirect('welcome/index');
        }

        # multiple groups (by id) and check if all exist
        $group = array(1, 2);
        if (!$this->ion_auth->in_group($group, false, true))
            $this->session->set_flashdata('message', 'You must be a part of group 1 and 2 to view this page');
            redirect('welcome/index');
        }