andri-sudarmawijaya / smartyacl
Lightweight Auth System with ACL for CodeIgniter 3
Installs: 13
Dependents: 2
Suggesters: 0
Security: 0
Stars: 0
Watchers: 1
Forks: 4
Type:codeigniter-third-party
Requires
This package is auto-updated.
Last update: 2024-10-21 10:21:20 UTC
README
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.
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)
Summary
Requirements
- Codeigniter 3 (developed on 3.1.11)
- PHP 7.x (developed on 7.3)
Demo
Download a demo application here
Installation
- Download latest released version
- Put SmartyAcl folder on
application/third_party
directory or install using composercomposer require andri-sudarmawijaya/smartyacl:1.0.x-dev
- 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');
Default Login
Username: admin
Password: 123456
Usage
Methods List
Register Admin
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
Register User
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
Login
Call:
$this->smarty_acl->login($identity, $password, $remember, $admin);
Response:
(bool) = true if logged in
Activate Admin or user
Call:
//Admin user $this->smarty_acl->activate($user_id, $code); //User $this->smarty_acl->activate_user($user_id, $code);
Response:
(bool) = true if activated
Resend Activation Mail
Call:
$this->smarty_acl->resend_activation($email, $admin);
Response:
(bool) = true if sent successfully
Forgotten Password
Call:
$this->smarty_acl->forgotten_password($email, $admin);
Response:
(bool) = true if sent successfully
Forgotten Password Check
Call:
$this->smarty_acl->forgotten_password_check($code, $admin);
Response:
(bool) = false if code is invalid or expired
(array) = user data array
Reset Password
Call:
$this->smarty_acl->reset_password($user, $email, $password, $admin);
Response:
(bool) = true if updated successfully
Logged in
Call:
$this->smarty_acl->logged_in($admin);
Response:
(bool) = true if user is logged in
Logout
Call:
$this->smarty_acl->logout($admin);
Response:
(bool) = true if user is logged out
Get Roles
Call:
$this->smarty_acl->roles($result);
Response:
Roles list as object or array
Create Role
Call:
$this->smarty_acl->create_role($data);
Response:
(bool) = true if created
Get Role
Call:
$this->smarty_acl->role($role_id);
Response:
(object) = if found
(bool) = false if not found
Update Role
Call:
$this->smarty_acl->update_role($role_id, $data);
Response:
(bool) = true if updated
Delete Role
Call:
$this->smarty_acl->delete_role($role_id);
Response:
(bool) = true if deleted
Get Modules
Call:
$this->smarty_acl->modules($result);
Response:
Roles list as object or array
Create Module
Call:
$this->smarty_acl->create_module($data);
Response:
(bool) = true if created
Get Module
Call:
$this->smarty_acl->module($module_id);
Response:
(object) = if found
(bool) = false if not found
Update Module
Call:
$this->smarty_acl->update_module($module_id, $data);
Response:
(bool) = true if updated
Delete Module
Call:
$this->smarty_acl->delete_module($module_id);
Response:
(bool) = true if deleted
Get Module Permissions
Call:
$this->smarty_acl->module_permissions($role_id);
Response:
(array) = multidimensional array with
{
[module_id] => {
[permission_id] => [permission_method_name]
}
}
Authorized
Call:
$this->smarty_acl->authorized();
Response:
redirect to unathorized route if not authorized
Module Authorized
Call:
$this->smarty_acl->module_authorized($module);
Response:
(bool) = false if not authorized
Authorized Module Action
Call:
$this->smarty_acl->authorized_action();
Response:
redirect to unathorized route if not authorized
Has Permission
Call:
$this->smarty_acl->has_permission($permission);
Response:
(bool) = false if not authorized
Get Admins
Call:
$this->smarty_acl->admins($result);
Response:
Admins list as object or array
Get Users
Call:
$this->smarty_acl->users($result);
Response:
Users list as object or array
Get User
Call:
$this->smarty_acl->get_user($user_id);
Response:
User data as array
Get Admin
Call:
$this->smarty_acl->get_admin($user_id);
Response:
Admin data as array
Update User
Call:
$this->smarty_acl->update_user($data, $user_id, $admin);
Response:
(bool) = true if updated
Delete User
Call:
$this->smarty_acl->delete_user($user_id,$admin);
Response:
(bool) = true if deleted
Errors Delimiters
Call:
$this->smarty_acl->set_delimiter($start, $end);
Response:
(bool) = true if set successfully
Error Messages
Call:
$this->smarty_acl->errors();
Response:
(string) = for single error
(array) = for multiple errors
Contributing
Feel free to contribute with corrections, optimizations or improvements. Just send a Pull Request with your contribution.
Support
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
References
- Ion Auth repository used as reference