Welcome Guest, Not a member yet? Register   Sign In
Ion Auth - Lightweight Auth System based on Redux Auth 2

[eluser]fran-quero[/eluser]
Hello. Congratullations for this great library.

I´m new in CI and I´m testing Ion Auth in a test application.

I´d like to set access based on groups.

1. I haven´t see that in the code. Is there any pre-made function or way to do it?

2. If there isn´t, please, check my code to know if I have done a good practice, or if there´s a better way to do it:

I have added a function to ion_auth_model.php to control if the user´s group is allowed to acces and optionally if the user have made a payment (in my application there are free and payments users)

ion_auth_model.php
Code:
public function access($allowed_group,$check_payment=false)
    {
        if($user=$this->ion_auth->get_user())
        {
            if($user->group_id>=$allowed_group)
            {
                if($check_payment)
                {
                    if($user->payment)
                    {
                        return true;
                    } else {
                       redirect('welcome');
                    }
                } else {
                    return true;
                }
            } else {
                redirect('welcome');
            }
        } else {
            redirect('auth','refresh');
        }
    }

When I want to set the access level to a controller I add:
Code:
$this->ion_auth->access(2,true);//Grant access to users from group 2 or higher who have paid

I´m new in CI and in MVC, is that a good practice? Is there a better way to do this?

Thanks for your advice.


Messages In This Thread
Ion Auth - Lightweight Auth System based on Redux Auth 2 - by El Forum - 02-19-2011, 02:17 PM



Theme © iAndrew 2016 - Forum software by © MyBB