SmartyACL is a library with basic authentication and authorization functions for Codeigniter 3. This library was based on Ion Auth but with the addition of ACL / RBAC and some other features.
- Register
- Register admin or user
- Send mail verification (optional)
- Login
- Single or Multi login(email, username or both)
- Limit max attempts
- Remember me
- Checks account status(inactive or banned) (optional)
- Check mail verification (optional)
- Forgot Password
- Send reset password mail
- Reset Password
- Validate security code and update user email/password
- Roles
- Create, update, delete
- Assign module permissions
- Modules
- Create, update and delete
- Admin Group - Users with role/permission access
- User Group - Common users without role/permission access
- Cache data to improve performance (optional)
- Codeigniter 3 (developed on 3.1.11)
- PHP 7.x (developed on 7.3)
Download a demo application here
- Download latest released version
- Put SmartyAcl folder on
application/third_party
directory - Add to
$autoload['packages']
Âą inapplication/config/autoload.php
$autoload['packages'] = array(APPPATH.'third_party/SmartyAcl');
- Import DB tables using migration or database.sql file
- Config library preferences on
application/third_party/SmartyAcl/config/smarty_acl.php
Âą Alternatively, you can copy the contents of the SmartyAcl folder to the respective directories in the application folder and load the library directly into the controller using $this->load->library('smarty_acl');
Username: admin
Password: 123456
Methods List
Method | Description |
---|---|
register() | Register a new Admin User |
register_user() | Register a new User |
login() | User or Admin Login |
activate() | Activate admin user with code(email) |
activate_user() | Activate user with code(email) |
resend_activation() | Resend email confirmation code (admin/user) |
forgotten_password() | Send reset password email (admin/user) |
forgotten_password_check() | Validate forgotten password code (admin/user) |
reset_password() | Reset email and password (admin/user) |
logged_in() | Check if user is logged in (admin/user) |
logout() | Logout current logged in user (admin/user) |
roles() | Get roles list |
role() | Get single role |
create_role() | Create a new Role |
update_role() | Update a single Role |
delete_role() | Delete a single Role |
modules() | Get modules list |
module() | Get single module |
create_module() | Create a new Module |
update_module() | Update a single Module |
delete_module() | Delete a single Module |
module_permissions() | Get a single Module Permissions |
authorized() | Check if logged in user is authorized to access current module |
module_authorized() | Check if logged in user has permission to a specific module |
authorized_action() | Check if logged in user has permission to current module action method |
has_permission() | Check if logged in user has permission to a specific module action method |
admins() | Get admins |
users() | Get users |
get_user() | Get a single user |
get_admin() | Get a single admin |
update_user() | Update a single user (admin/user) |
delete_user() | Delete a single user (admin/user) |
set_delimiter() | Set delimiters for error messages |
errors() | Show error messages |
Call:
$this->smarty_acl->register($identity, $password, $email, $additional_data, $role_id);
Responses:
int = user registered
array = user data array if verification is enabled but 'email_sender' is disabled
false(bool) = failed to register
Field | Required | Info |
---|---|---|
$identity | yes | field used to register/login user (username, email, phone, etc) |
$password | yes | user password |
yes | user email address | |
$additional_data | no | array with additional data(name, address, country, etc) (optional) |
$role_id | no | role id to assign(optional). If null, will use $config['default_role'] |
Call:
$this->smarty_acl->register_user($identity, $password, $email, $additional_data, $role_id);
Responses:
int = user registered
array = user data array if verification is enabled but 'email_sender' is disabled
false(bool) = failed to register
Field | Required | Info |
---|---|---|
$identity | yes | field used to register/login user (username, email, phone, etc) |
$password | yes | user password |
yes | user email address | |
$additional_data | no | array with additional data(name, address, country, etc) (optional) |
Call:
$this->smarty_acl->login($identity, $password, $remember, $admin);
Response:
(bool) = true if logged in
Field | Required | Info |
---|---|---|
$identity | yes | field used to register/login user (username, email, phone, etc) |
$password | yes | user password |
$admin | no (default TRUE) | (bool) set FALSE to user login |
Call:
//Admin user
$this->smarty_acl->activate($user_id, $code);
//User
$this->smarty_acl->activate_user($user_id, $code);
Response:
(bool) = true if activated
Field | Required | Info |
---|---|---|
$user_id | yes | User ID |
$code | yes | Activation Security Code |
Call:
$this->smarty_acl->resend_activation($email, $admin);
Response:
(bool) = true if sent successfully
Field | Required | Info |
---|---|---|
yes | User email address | |
$admin | no (default TRUE) | (bool) set FALSE to use for users |
Call:
$this->smarty_acl->forgotten_password($email, $admin);
Response:
(bool) = true if sent successfully
Field | Required | Info |
---|---|---|
yes | User email address | |
$admin | no (default TRUE) | (bool) set FALSE to use for users |
Call:
$this->smarty_acl->forgotten_password_check($code, $admin);
Response:
(bool) = false if code is invalid or expired
(array) = user data array
Field | Required | Info |
---|---|---|
$code | yes | Secret Code |
$admin | no (default TRUE) | (bool) set FALSE to use for users |
Call:
$this->smarty_acl->reset_password($user, $email, $password, $admin);
Response:
(bool) = true if updated successfully
Field | Required | Info |
---|---|---|
$user | yes | Array with current user data(from forgotten_password_check()) |
yes | New email address | |
$password | yes | New password |
$admin | no (default TRUE) | (bool) set FALSE to use for users |
Call:
$this->smarty_acl->logged_in($admin);
Response:
(bool) = true if user is logged in
Field | Required | Info |
---|---|---|
$admin | no (default TRUE) | (bool) set FALSE to use for users |
Call:
$this->smarty_acl->logout($admin);
Response:
(bool) = true if user is logged out
Field | Required | Info |
---|---|---|
$admin | no (default TRUE) | (bool) set FALSE to use for users |
Call:
$this->smarty_acl->roles($result);
Response:
Roles list as object or array
Field | Required | Info |
---|---|---|
$result | no (default TRUE) | (bool) set FALSE to return array |
Call:
$this->smarty_acl->create_role($data);
Response:
(bool) = true if created
Field | Required | Info |
---|---|---|
$data | yes | array with role fields/values |
Call:
$this->smarty_acl->role($role_id);
Response:
(object) = if found
(bool) = false if not found
Field | Required | Info |
---|---|---|
$role_id | yes | Role ID |
Call:
$this->smarty_acl->update_role($role_id, $data);
Response:
(bool) = true if updated
Field | Required | Info |
---|---|---|
$role_id | yes | Role ID |
$data | yes | array with role fields/values |
Call:
$this->smarty_acl->delete_role($role_id);
Response:
(bool) = true if deleted
Field | Required | Info |
---|---|---|
$role_id | yes | Role ID |
Call:
$this->smarty_acl->modules($result);
Response:
Roles list as object or array
Field | Required | Info |
---|---|---|
$result | no (default TRUE) | (bool) set FALSE to return array |
Call:
$this->smarty_acl->create_module($data);
Response:
(bool) = true if created
Field | Required | Info |
---|---|---|
$data | yes | array with module fields/values |
Call:
$this->smarty_acl->module($module_id);
Response:
(object) = if found
(bool) = false if not found
Field | Required | Info |
---|---|---|
$role_id | yes | Role ID |
Call:
$this->smarty_acl->update_module($module_id, $data);
Response:
(bool) = true if updated
Field | Required | Info |
---|---|---|
$role_id | yes | Role ID |
$data | yes | array with module fields/values |
Call:
$this->smarty_acl->delete_module($module_id);
Response:
(bool) = true if deleted
Field | Required | Info |
---|---|---|
$role_id | yes | Role ID |
Call:
$this->smarty_acl->module_permissions($role_id);
Response:
(array) = multidimensional array with
{
[module_id] => {
[permission_id] => [permission_method_name]
}
}
Field | Required | Info |
---|---|---|
$role_id | yes | Role ID |
Call:
$this->smarty_acl->authorized();
Response:
redirect to unathorized route if not authorized
Call:
$this->smarty_acl->module_authorized($module);
Response:
(bool) = false if not authorized
Field | Required | Info |
---|---|---|
$module | yes | Module Controller Name |
Call:
$this->smarty_acl->authorized_action();
Response:
redirect to unathorized route if not authorized
Call:
$this->smarty_acl->has_permission($permission);
Response:
(bool) = false if not authorized
Field | Required | Info |
---|---|---|
$permission | yes | Module Permission Name |
Call:
$this->smarty_acl->admins($result);
Response:
Admins list as object or array
Field | Required | Info |
---|---|---|
$result | no (default TRUE) | (bool) set FALSE to return array |
Call:
$this->smarty_acl->users($result);
Response:
Users list as object or array
Field | Required | Info |
---|---|---|
$result | no (default TRUE) | (bool) set FALSE to return array |
Call:
$this->smarty_acl->get_user($user_id);
Response:
User data as array
Field | Required | Info |
---|---|---|
$user_id | yes | User ID |
Call:
$this->smarty_acl->get_admin($user_id);
Response:
Admin data as array
Field | Required | Info |
---|---|---|
$user_id | yes | User ID |
Call:
$this->smarty_acl->update_user($data, $user_id, $admin);
Response:
(bool) = true if updated
Field | Required | Info |
---|---|---|
$data | yes | array with user fields/values |
$user_id | yes | User ID |
$admin | no (default TRUE) | (bool) set FALSE to use for users |
Call:
$this->smarty_acl->delete_user($user_id,$admin);
Response:
(bool) = true if deleted
Field | Required | Info |
---|---|---|
$user_id | yes | User ID |
$admin | no (default TRUE) | (bool) set FALSE to use for users |
Call:
$this->smarty_acl->set_delimiter($start, $end);
Response:
(bool) = true if set successfully
Field | Required | Info |
---|---|---|
$start | yes | Start delimiter (<p>,<li>,<span> , etc) |
$end | yes | End delimiter (</p>,</li>,</span> , etc) |
Call:
$this->smarty_acl->errors();
Response:
(string) = for single error
(array) = for multiple errors
Feel free to contribute with corrections, optimizations or improvements. Just send a Pull Request with your contribution.
If you found a bug, Create an Issue. If you're having an issue with CodeIgniter or for general help with development I recommend checking out the CodeIgniter Forums
- Ion Auth repository used as reference