Authorization, Authentication and User Management library for Codeigniter 2.x and 3.x to make easy user management and permission operations
Aauth is a User Authorization Library for CodeIgniter 2.x and 3.x, which aims to make easy some essential jobs such as login, permissions and access operations. Despite its ease of use, it has also very advanced features like private messages, groupping, access management, and public access.
This is Quick Start page. You can also take a look at the detailed Documentation Wiki to learn about other great Features
Let’s get started 😃
First, we will load the Aauth Library into the system
$this->load->library("Aauth");
That was easy!
Now let’s create two new users, Frodo
and Legolas
.
$this->aauth->create_user('[email protected]','frodopass','FrodoBaggins');
$this->aauth->create_user('[email protected]','legolaspass','Legolas');
We now we have two users.
OK, now we can create two groups, hobbits
and elves
.
$this->aauth->create_group('hobbits');
$this->aauth->create_group('elves');
Now, let’s create a user with power, Gandalf (for our example, let’s assume he was given the id
of 12).
$this->aauth->create_user('[email protected]', 'gandalfpass', 'GandalfTheGray');
OK, now we have two groups and three users.
Let’s create two permissions walk_unseen
and immortality
$this->aauth->create_perm('walk_unseen');
$this->aauth->create_perm('immortality');
Ok, now let’s give accesses to our groups. The Hobbits seem to have ability to walk unseen, so we will assign that privilage to them. The Elves have imortality, so we will assign that privilage to them.
We will assign access with allow_group()
function.
$this->aauth->allow_group('hobbits','walk_unseen');
$this->aauth->allow_group('elves','immortality');
$this->aauth->allow_group('hobbits','immortality');
Wait a minute! Hobbits should not have immortality
. We need to fix this, we can use deny_group()
to remove the permission.
$this->aauth->deny_group('hobbits','immortality');
Gandalf can also live forever.
$this->aauth->allow_user(12,'immortality');
Ok now let’s check if Hobbits have immortality
.
if($this->aauth->is_group_allowed('hobbits','immortality')){
echo "Hobbits are immortal";
} else {
echo "Hobbits are NOT immortal";
}
Results:
Hobbits are NOT immortal
Does Gandalf have the ability to live forever?
if($this->aauth->is_allowed(12,'immortality')){
echo "Gandalf is immortal";
} else {
echo "Gandalf is NOT immortal";
}
Results:
Gandalf is immortal
Since we don’t accually live in Middle Earth, we are not aware of actual immortality. Alas, we must delete the permission.
$this->aauth->delete_perm('immortality');
It is gone.
So, how about un-authenticated users? In Aauth they are part of the public
group. Let’s give them permissions to travel
.
We will assume we already have a permission set up named travel
.
$this->aauth->allow_group('public','travel');
What about the Admin users? The Admin
user and any member of the Admin
group is a superuser who had access everthing, There is no need to grant additional permissions.
For each user, variables can be defined as individual key/value pairs.
$this->aauth->set_user_var("key","value");
For example, if you want to store a user’s phone number.
$this->aauth->set_user_var("phone","1-507-555-1234");
To retreive value you will use get_user_var()
:
$this->aauth->get_user_var("key");
Aauth also permits you to define System Variables. These can be which can be accesed by all users in the system.
$this->aauth->set_system_var("key","value");
$this->aauth->get_system_var("key");
OK, let’s look at private messages. Frodo (id
= 3) will send a PM to Legolas (id
= 4);
$this->aauth->send_pm(3,4,'New cloaks','These new cloaks are fantastic!')
Frodo has broke the rules and will now need to be banned from the system.
$this->aauth->ban_user(3);
You have reached the end of the Quick Start Guide, but please take a look at the detailed Documentation Wiki for additional information.
Don’t forget to keep and eye on Aauth, we are constantly improving the system.
You can also contribute and help me out. 😃