├── .gitignore
├── .travis.yml
├── CONTRIBUTING.md
├── LICENSE
├── README.md
├── composer.json
├── env
├── phpcs.xml
└── src
├── Controllers
├── AbstractAdminController.php
├── Home.php
├── Informations.php
└── Users.php
├── Language
├── en
│ └── Admin.php
└── fr
│ └── Admin.php
└── Views
├── home.php
├── informations.php
├── main.php
└── users
├── create_group.php
├── create_user.php
├── deactivate_user.php
├── edit_group.php
├── edit_user.php
└── users.php
/.gitignore:
--------------------------------------------------------------------------------
1 | composer.lock
2 | /vendor/
3 |
--------------------------------------------------------------------------------
/.travis.yml:
--------------------------------------------------------------------------------
1 | language: php
2 |
3 | php:
4 | - 7.1
5 | - 7.2
6 | - 7.3
7 |
8 | install:
9 | - composer selfupdate
10 | - composer install
11 |
12 | script:
13 | - ./vendor/bin/phpcs -s
14 | # - ./vendor/bin/phpunit --colors
15 |
--------------------------------------------------------------------------------
/CONTRIBUTING.md:
--------------------------------------------------------------------------------
1 | # Contributing to ci4-admin
2 |
3 |
4 | ## Contributions
5 |
6 | We expect all contributions to conform to our style guide, be commented (inside the PHP source files),
7 | be documented (in the user guide), and unit tested (in the test folder).
8 |
9 | ## Issues
10 |
11 | Issues are a quick way to point out a bug. If you find a bug or documentation error in ci4-admin then please check a few things first:
12 |
13 | 1. There is not already an open Issue
14 | 2. The issue has already been fixed (check the develop branch, or look for closed Issues)
15 | 3. Is it something really obvious that you can fix yourself?
16 |
17 | Reporting issues is helpful but an even better approach is to send a Pull Request, which is done by "Forking" the main repository and committing to your own copy. This will require you to use the version control system called Git.
18 |
19 | ## Guidelines
20 |
21 | Before we look into how, here are the guidelines. If your Pull Requests fail
22 | to pass these guidelines it will be declined and you will need to re-submit
23 | when you’ve made the changes. This might sound a bit tough, but it is required
24 | for us to maintain quality of the code-base.
25 |
26 | ### PHP Style
27 |
28 | All code must meet the [CodeIgniter 4 Style Guide](https://github.com/codeigniter4/CodeIgniter4/blob/develop/contributing/styleguide.rst).
29 | This makes certain that all code is the same format as the existing code and means it will be as readable as possible.
30 |
31 | ### Documentation
32 |
33 | If you change anything that requires a change to documentation then you will need to add it. New classes, methods, parameters, changing default values, etc are all things that will require a change to documentation. The change-log must also be updated for every change. Also PHPDoc blocks must be maintained.
34 |
35 | ### Branching
36 |
37 | ci4-admin uses the [Git-Flow](http://nvie.com/posts/a-successful-git-branching-model/) branching model which requires all pull requests to be sent to the "develop" branch. This is
38 | where the next planned version will be developed. The "master" branch will always contain the latest stable version and is kept clean so a "hotfix" (e.g: an emergency security patch) can be applied to master to create a new version, without worrying about other features holding it up. For this reason all commits need to be made to "develop" and any sent to "master" will be closed automatically. If you have multiple changes to submit, please place all changes into their own branch on your fork.
39 |
40 | One thing at a time: A pull request should only contain one change. That does not mean only one commit, but one change - however many commits it took. The reason for this is that if you change X and Y but send a pull request for both at the same time, we might really want X but disagree with Y, meaning we cannot merge the request. Using the Git-Flow branching model you can create new branches for both of these features and send two requests.
41 |
42 | ## How-to Guide
43 |
44 | The best way to contribute is to fork the [ci4-admin repository](https://github.com/bvrignaud/ci4-admin), and "clone" that to your development area. That sounds like some jargon, but "forking" on GitHub means "making a copy of that repo to your account" and "cloning" means "copying that code to your environment so you can work on it".
45 |
46 | 1. Set up Git (Windows, Mac & Linux)
47 | 2. Go to the [ci4-admin repo](https://github.com/bvrignaud/ci4-admin)
48 | 3. Fork it (to your Github account)
49 | 4. Clone your ci4-admin repo: git@github.com:\/ci4-admin.git
50 | 5. Create a new branch in your project for each set of changes you want to make.
51 | 6. Fix existing bugs on the Issue tracker after taking a look to see nobody else is working on them.
52 | 7. Commit the changed files in your contribution branch
53 | 8. Push your contribution branch to your fork
54 | 9. Send a pull request [http://help.github.com/send-pull-requests/](http://help.github.com/send-pull-requests/)
55 |
56 | The codebase maintainers will now be alerted about the change and at least one of the team will respond. If your change fails to meet the guidelines it will be bounced, or feedback will be provided to help you improve it.
57 |
58 | Once the maintainer handling your pull request is happy with it they will merge it into develop and your patch will be part of the next release.
59 |
60 | ### Keeping your fork up-to-date
61 |
62 | Unlike systems like Subversion, Git can have multiple remotes. A remote is the name for a URL of a Git repository. By default your fork will have a remote named "origin" which points to your fork, but you can add another remote named "codeigniter" which points to `git://github.com/codeigniter4/CodeIgniter4.git`. This is a read-only remote but you can pull from this develop branch to update your own.
63 |
64 | If you are using command-line you can do the following:
65 |
66 | 1. `git remote add upstream git://github.com/bvrignaud/ci4-admin.git`
67 | 2. `git pull upstream develop`
68 | 3. `git push origin develop`
69 |
70 | Now your fork is up to date. This should be done regularly, or before you send a pull request at least.
71 |
--------------------------------------------------------------------------------
/LICENSE:
--------------------------------------------------------------------------------
1 | MIT License
2 |
3 | Copyright (c) 2018 Benoit VRIGNAUD
4 |
5 | Permission is hereby granted, free of charge, to any person obtaining a copy
6 | of this software and associated documentation files (the "Software"), to deal
7 | in the Software without restriction, including without limitation the rights
8 | to use, copy, modify, merge, publish, distribute, sublicense, and/or sell
9 | copies of the Software, and to permit persons to whom the Software is
10 | furnished to do so, subject to the following conditions:
11 |
12 | The above copyright notice and this permission notice shall be included in all
13 | copies or substantial portions of the Software.
14 |
15 | THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
16 | IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
17 | FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE
18 | AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER
19 | LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM,
20 | OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE
21 | SOFTWARE.
22 |
--------------------------------------------------------------------------------
/README.md:
--------------------------------------------------------------------------------
1 | # ci4-admin
2 |
3 | [](https://travis-ci.com/bvrignaud/ci4-admin)
4 |
5 | Admin module for CodeIgniter 4 based on AdminLTE 3
6 |
7 | ## Installing ci-admin
8 |
9 | Before installing, please check that you are meeting the minimum server requirements.
10 |
11 | There are different ways to install this package.
12 |
13 |
14 | > 1. With composer
15 |
16 | ```shell
17 | $ composer require bvrignaud/ci4-admin
18 | ```
19 | ---
20 |
21 | > 2. With Git:
22 |
23 | ```shell
24 | my-project$ git clone https://github.com/bvrignaud/ci4-admin.git
25 | ```
26 | Then in your Config/Autoload.php, add this :
27 | ```php
28 | 'IonAuth' => ROOTPATH . 'YOUR-ION_AUTH-FOLDER',
29 | 'Admin' => ROOTPATH . 'ci4-admin',
30 | ```
31 |
32 | ---
33 |
34 | > 3. Download the archive, and move folder from this package to the root folder:
35 |
36 | ```shell
37 | CI # → Root Directory
38 | ├── application/
39 | ├── ion-auth/ # → Ion-auth directory
40 | ├── public
41 | ├──...
42 | ```
43 | Then in your Config/Autoload.php, add this :
44 | ```php
45 | 'IonAuth' => ROOTPATH . 'YOUR-ION_AUTH-FOLDER',
46 | 'Admin' => ROOTPATH . 'ci4-admin',
47 | ```
48 |
49 | ---
50 | Install css/js dependencies
51 | ```bash
52 | $ cd public/assets
53 | $ yarn add admin-lte@v3
54 | ```
55 | ---
56 |
57 | ## Use it
58 |
59 | Add routes configs in 'Config\Routes.php':
60 | ```php
61 | $routes->group('auth', ['namespace' => 'IonAuth\Controllers'], function ($routes) {
62 | $routes->get('/', 'Auth::index');
63 | $routes->add('login', 'Auth::login');
64 | $routes->get('logout', 'Auth::logout');
65 | $routes->get('forgot_password', 'Auth::forgot_password');
66 | });
67 |
68 | $routes->group('admin', ['namespace' => 'Admin\Controllers'], function ($routes) {
69 | $routes->get('/', 'Home::index');
70 |
71 | $routes->group('users', ['namespace' => 'Admin\Controllers'], function ($routes) {
72 | $routes->get('/', 'Users::index');
73 | $routes->add('create', 'Users::createUser');
74 | $routes->add('edit/(:num)', 'Users::edit/$1');
75 | $routes->add('activate/(:num)', 'Users::activate/$1');
76 | $routes->add('deactivate/(:num)', 'Users::deactivate/$1');
77 | $routes->add('edit_group/(:num)', 'Users::editGroup/$1');
78 | $routes->add('create_group', 'Users::createGroup');
79 | });
80 |
81 | $routes->group('informations', ['namespace' => 'Admin\Controllers'], function ($routes) {
82 | $routes->get('/', 'Informations::index');
83 | $routes->get('displayPhpInfo', 'Informations::displayPhpInfo');
84 | $routes->add('exportDatabase', 'Informations::exportDatabase');
85 | $routes->post('sendEmailForTest', 'Informations::sendEmailForTest');
86 | });
87 | });
88 | ```
89 |
--------------------------------------------------------------------------------
/composer.json:
--------------------------------------------------------------------------------
1 | {
2 | "name": "bvrignaud/ci4-admin",
3 | "description": "Admin module for CodeIgniter 4 based on IonAuth and AdminLTE",
4 | "keywords": ["CodeIgniter 4", "AdminLTE 3"],
5 | "type": "library",
6 | "require-dev": {
7 | "codeigniter4/codeigniter4-standard": "^1.0",
8 | "squizlabs/php_codesniffer": "^3.3"
9 | },
10 | "license": "MIT",
11 | "authors": [
12 | {
13 | "name": "Benoit VRIGNAUD",
14 | "email": "benoit.vrignaud@zaclys.net"
15 | }
16 | ],
17 | "require": {
18 | "php": ">=7.1",
19 | "codeigniter4/framework": "^4@alpha"
20 | },
21 | "autoload": {
22 | "psr-4" : {
23 | "Admin\\" : "src"
24 | }
25 | }
26 | }
27 |
--------------------------------------------------------------------------------
/env:
--------------------------------------------------------------------------------
1 | #--------------------------------------------------------------------
2 | # Example Environment Configuration file for CI-Admin
3 | #
4 | # You must add this settings to your .env file
5 | #--------------------------------------------------------------------
6 |
7 | #--------------------------------------------------------------------
8 | # Admin
9 | #--------------------------------------------------------------------
10 |
11 | appName = 'CI-Admin'
12 |
--------------------------------------------------------------------------------
/phpcs.xml:
--------------------------------------------------------------------------------
1 |
2 |
3 | CI 4 Admin coding style
4 |
5 |
6 |
7 |
8 |
9 |
10 |
11 | src
12 |
13 |
--------------------------------------------------------------------------------
/src/Controllers/AbstractAdminController.php:
--------------------------------------------------------------------------------
1 |
8 | * @license https://opensource.org/licenses/MIT MIT License
9 | * @link http://github.com/bbvrignaud/ci-admin
10 | */
11 |
12 | use CodeIgniter\Controller;
13 |
14 | /**
15 | * Admin abstract controller
16 | *
17 | * @package CI4-Admin
18 | */
19 | abstract class AbstractAdminController extends Controller
20 | {
21 | /**
22 | * IonAuth library
23 | *
24 | * @var \IonAuth\Libraries\IonAuth
25 | */
26 | protected $ionAuth;
27 |
28 | /**
29 | * Left menu
30 | *
31 | * @var array
32 | */
33 | protected $leftMenu = [
34 | 'dashboard' => [
35 | 'label' => 'Dashboard',
36 | 'title' => 'Dashboard',
37 | 'url' => 'admin',
38 | 'icon' => 'dashboard',
39 | ],
40 | 'users' => [
41 | 'label' => 'Admin.menu-users',
42 | 'title' => 'Admin.menu-users',
43 | 'url' => 'admin/users',
44 | 'icon' => 'user',
45 | ],
46 | 'informations' => [
47 | 'label' => 'Admin.menu-labelInformation',
48 | 'title' => 'Admin.menu-generalInformation',
49 | 'url' => 'admin/informations',
50 | 'icon' => 'info-circle',
51 | ],
52 | ];
53 |
54 | /**
55 | * User
56 | *
57 | * @var stdClass
58 | */
59 | protected $user;
60 |
61 | /**
62 | * Constructor
63 | *
64 | * @return void
65 | */
66 | public function __construct()
67 | {
68 | $this->ionAuth = new \IonAuth\Libraries\IonAuth();
69 | if ($this->ionAuth->loggedIn())
70 | {
71 | $this->user = $this->ionAuth->user()->row();
72 | }
73 | }
74 |
75 | /**
76 | * Check if user is logged in is admin
77 | *
78 | * @return boolean
79 | */
80 | protected function isAuthorized(): bool
81 | {
82 | return $this->ionAuth->loggedIn() && $this->ionAuth->isAdmin();
83 | }
84 |
85 | /**
86 | * Display the $body page inside the main vue
87 | *
88 | * @param string $body Body vue
89 | * @param string $pageTitle Page title
90 | * @param string $activeMenu Active menu
91 | *
92 | * @return string
93 | */
94 | protected function view(string $body, string $pageTitle = '', string $activeMenu = ''): string
95 | {
96 | $mainData = [
97 | 'appName' => env('appName', 'CI-Admin'),
98 | 'userFirstName' => $this->user->first_name,
99 | 'userLastName' => $this->user->last_name,
100 | 'pageTitle' => $pageTitle,
101 | 'leftMenu' => $this->displayLeftMenu($this->leftMenu, $activeMenu),
102 | 'body' => $body,
103 | ];
104 | return view('Admin\main', $mainData);
105 | }
106 |
107 | /**
108 | * Parse $menu and return the html menu
109 | *
110 | * @param array $menus Menu to parse
111 | * @param string $activeMenu Active menu
112 | *
113 | * @return string
114 | */
115 | private function displayLeftMenu(array $menus, string $activeMenu): string
116 | {
117 | $html = '';
118 | foreach ($menus as $keyMenu => $menu)
119 | {
120 | $active = $activeMenu === $keyMenu ? ' active' : '';
121 | $html .= '