├── .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 | [![Build Status](https://travis-ci.com/bvrignaud/ci4-admin.svg?branch=master)](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 .= ''; 136 | } 137 | return $html; 138 | } 139 | } 140 | -------------------------------------------------------------------------------- /src/Controllers/Home.php: -------------------------------------------------------------------------------- 1 | 8 | * @license https://opensource.org/licenses/MIT MIT License 9 | * @link http://github.com/bbvrignaud/ci-admin 10 | */ 11 | 12 | class Home extends AbstractAdminController 13 | { 14 | /** 15 | * Affiche la page d'entrée du site en fonction du statut de l'utilisateur (non connecté, gamer ou leader) 16 | * 17 | * @return \CodeIgniter\HTTP\RedirectResponse|string 18 | */ 19 | public function index() 20 | { 21 | if (! $this->isAuthorized()) 22 | { 23 | return redirect()->to('/'); 24 | } 25 | return $this->view('home', lang('Admin.home-title')); 26 | } 27 | } 28 | -------------------------------------------------------------------------------- /src/Controllers/Informations.php: -------------------------------------------------------------------------------- 1 | 8 | * @license https://opensource.org/licenses/MIT MIT License 9 | * @link http://github.com/bbvrignaud/ci-admin 10 | */ 11 | 12 | /** 13 | * Admin/Informations controller 14 | * 15 | * @package CI4-Admin 16 | */ 17 | class Informations extends AbstractAdminController 18 | { 19 | use \CodeIgniter\API\ResponseTrait; 20 | 21 | /** 22 | * Display informations page 23 | * 24 | * @return \CodeIgniter\HTTP\RedirectResponse|string 25 | */ 26 | public function index() 27 | { 28 | if (! $this->isAuthorized()) 29 | { 30 | return redirect()->to('/'); 31 | } 32 | 33 | helper('form'); 34 | 35 | $data = [ 36 | 'dbVersion' => \Config\Database::connect()->getVersion(), 37 | 'ciVersion' => \CodeIgniter\CodeIgniter::CI_VERSION, 38 | ]; 39 | $body = view ('Admin\informations', $data); 40 | 41 | return $this->view($body, lang('Admin.informations-title'), 'informations'); 42 | } 43 | 44 | /** 45 | * Display phpinfo 46 | * 47 | * @return \CodeIgniter\HTTP\RedirectResponse|string 48 | */ 49 | public function displayPhpInfo() 50 | { 51 | if (! $this->isAuthorized()) 52 | { 53 | return redirect()->to('/'); 54 | } 55 | 56 | return phpinfo(); 57 | } 58 | 59 | /** 60 | * Download database 61 | * 62 | * @return \CodeIgniter\HTTP\RedirectResponse|string 63 | */ 64 | public function exportDatabase() 65 | { 66 | if (! $this->isAuthorized()) 67 | { 68 | return redirect()->to('/'); 69 | } 70 | 71 | $dbUtil = \Config\Database::utils(); 72 | $backup = $dbUtil->backup(['format' => 'gzip']); 73 | 74 | return $this->response->download(date('Y-m-d') . '-backup.gz', $backup); 75 | 76 | /* 77 | // Load the DB utility class 78 | $this->load->dbutil(); 79 | 80 | // Backup your entire database and assign it to a variable 81 | $backup = $this->dbutil->backup(['format' => 'gzip']); 82 | 83 | // Load the download helper and send the file to your desktop 84 | $this->load->helper('download'); 85 | force_download(date('Y-m-d') . '-backup.gz', $backup); 86 | */ 87 | } 88 | 89 | /** 90 | * Test if e-mail are correctly configured 91 | */ 92 | public function sendEmailForTest() 93 | { 94 | if (isset($_POST['email'])) 95 | { 96 | $email = \Config\Services::email(); 97 | //$email->setFrom($this->config->item('contact_email')); 98 | $email->setFrom('test@free.fr'); 99 | $email->setTo($this->request->getPost('email')); 100 | $email->setSubject('Test'); 101 | $email->setMessage('Test d\'envoi de mail.'); 102 | 103 | /* 104 | if ($this->email->send()) { 105 | $this->sendAjaxJSONReponse(true, 'Email envoyé avec succès. Contrôler votre boite mail.'); 106 | } else { 107 | $reponse = [ 108 | 'success' => false, 109 | 'msg' => 'Erreur durant l\'envoi du mail !', 110 | 'logs' => $this->email->print_debugger(), 111 | ]; 112 | echo json_encode($reponse); 113 | } 114 | */ 115 | if ($email->send()) 116 | { 117 | return $this->respondCreated([]); 118 | } 119 | else 120 | { 121 | return $this->fail('Une erreur est survenue durant l\'envoi du mail'); 122 | } 123 | } 124 | } 125 | } 126 | -------------------------------------------------------------------------------- /src/Controllers/Users.php: -------------------------------------------------------------------------------- 1 | 8 | * @license https://opensource.org/licenses/MIT MIT License 9 | * @link http://github.com/bvrignaud/ci-admin 10 | */ 11 | 12 | class Users extends AbstractAdminController 13 | { 14 | /** 15 | * Configuration 16 | * 17 | * @var \IonAuth\Config\IonAuth 18 | */ 19 | private $configIonAuth; 20 | 21 | /** 22 | * Constructor 23 | * 24 | * @return void 25 | */ 26 | public function __construct() 27 | { 28 | parent::__construct(); 29 | $this->configIonAuth = config('IonAuth'); 30 | } 31 | 32 | /** 33 | * Display informations page 34 | * 35 | * @return \CodeIgniter\HTTP\RedirectResponse|string 36 | */ 37 | public function index() 38 | { 39 | if (! $this->isAuthorized()) 40 | { 41 | return redirect()->to('/'); 42 | } 43 | 44 | $data = [ 45 | 'message' => session()->getFlashdata('message'), 46 | 'users' => $this->ionAuth->users()->result(), 47 | ]; 48 | 49 | foreach ($data['users'] as $k => $user) 50 | { 51 | $data['users'][$k]->groups = $this->ionAuth->getUsersGroups($user->id)->getResult(); 52 | } 53 | 54 | $body = view('Admin\users\users', $data); 55 | 56 | return $this->view($body, lang('Auth.index_heading'), 'users'); 57 | } 58 | 59 | /** 60 | * Create a new user 61 | * 62 | * @return string|\CodeIgniter\HTTP\RedirectResponse 63 | */ 64 | public function createUser() 65 | { 66 | if (! $this->isAuthorized()) 67 | { 68 | return redirect()->to('/'); 69 | } 70 | 71 | $data['title'] = lang('Auth.create_user_heading'); 72 | 73 | $tables = $this->configIonAuth->tables; 74 | $identityColumn = $this->configIonAuth->identity; 75 | $data['identityColumn'] = $identityColumn; 76 | 77 | // validate form input 78 | $validation = \Config\Services::validation(); 79 | $validation->setRule('first_name', lang('Auth.create_user_validation_fname_label'), 'trim|required'); 80 | $validation->setRule('last_name', lang('Auth.create_user_validation_lname_label'), 'trim|required'); 81 | if ($identityColumn !== 'email') 82 | { 83 | $validation->setRule( 84 | 'identity', 85 | lang('Auth.create_user_validation_identity_label'), 86 | 'trim|required|is_unique[' . $tables['users'] . '.' . $identityColumn . ']'); 87 | $validation->setRule( 88 | 'email', lang('Auth.create_user_validation_email_label'), 'trim|required|valid_email'); 89 | } 90 | else 91 | { 92 | $validation->setRule( 93 | 'email', 94 | lang('Auth.create_user_validation_email_label'), 95 | 'trim|required|valid_email|is_unique[' . $tables['users'] . '.email]'); 96 | } 97 | $validation->setRule('phone', lang('Auth.create_user_validation_phone_label'), 'trim'); 98 | $validation->setRule('company', lang('Auth.create_user_validation_company_label'), 'trim'); 99 | $validation->setRule( 100 | 'password', 101 | lang('Auth.create_user_validation_password_label'), 102 | 'required|min_length[' . $this->configIonAuth->minPasswordLength . ']|matches[password_confirm]'); 103 | $validation->setRule( 104 | 'password_confirm', lang('Auth.create_user_validation_password_confirm_label'), 'required'); 105 | 106 | if ($this->request->getPost() && $validation->withRequest($this->request)->run()) 107 | { 108 | $email = strtolower($this->request->getPost('email')); 109 | $identity = ($identityColumn === 'email') ? $email : $this->request->getPost('identity'); 110 | $password = $this->request->getPost('password'); 111 | 112 | $additionalData = [ 113 | 'first_name' => $this->request->getPost('first_name'), 114 | 'last_name' => $this->request->getPost('last_name'), 115 | 'company' => $this->request->getPost('company'), 116 | 'phone' => $this->request->getPost('phone'), 117 | ]; 118 | } 119 | if ( 120 | $this->request->getPost() 121 | && $validation->withRequest($this->request)->run() 122 | && $this->ionAuth->register($identity, $password, $email, $additionalData) 123 | ) 124 | { 125 | // check to see if we are creating the user 126 | // redirect them back to the admin page 127 | session()->setFlashdata('message', $this->ionAuth->messages()); 128 | return redirect()->to('/admin/users'); 129 | } 130 | else 131 | { 132 | // display the create user form 133 | helper(['form']); 134 | // set the flash data error message if there is one 135 | $data['message'] = $validation->getErrors() ? 136 | $validation->listErrors() : 137 | ($this->ionAuth->errors() ? $this->ionAuth->errors() : session()->getFlashdata('message')); 138 | 139 | $data['firstName'] = [ 140 | 'name' => 'first_name', 141 | 'id' => 'first_name', 142 | 'type' => 'text', 143 | 'value' => set_value('first_name'), 144 | ]; 145 | $data['lastName'] = [ 146 | 'name' => 'last_name', 147 | 'id' => 'last_name', 148 | 'type' => 'text', 149 | 'value' => set_value('last_name'), 150 | ]; 151 | $data['identity'] = [ 152 | 'name' => 'identity', 153 | 'id' => 'identity', 154 | 'type' => 'text', 155 | 'value' => set_value('identity'), 156 | ]; 157 | $data['email'] = [ 158 | 'name' => 'email', 159 | 'id' => 'email', 160 | 'type' => 'email', 161 | 'value' => set_value('email'), 162 | ]; 163 | $data['company'] = [ 164 | 'name' => 'company', 165 | 'id' => 'company', 166 | 'type' => 'text', 167 | 'value' => set_value('company'), 168 | ]; 169 | $data['phone'] = [ 170 | 'name' => 'phone', 171 | 'id' => 'phone', 172 | 'type' => 'text', 173 | 'value' => set_value('phone'), 174 | ]; 175 | $data['password'] = [ 176 | 'name' => 'password', 177 | 'id' => 'password', 178 | 'type' => 'password', 179 | 'value' => set_value('password'), 180 | ]; 181 | $data['passwordConfirm'] = [ 182 | 'name' => 'password_confirm', 183 | 'id' => 'password_confirm', 184 | 'type' => 'password', 185 | 'value' => set_value('password_confirm'), 186 | ]; 187 | 188 | $body = view('Admin\users\create_user', $data); 189 | return $this->view($body, lang('Auth.create_user_heading'), 'users'); 190 | } 191 | } 192 | 193 | /** 194 | * Edit a user 195 | * 196 | * @param integer $id User id 197 | * 198 | * @return string string|\CodeIgniter\HTTP\RedirectResponse 199 | */ 200 | public function edit(int $id) 201 | { 202 | if (! $this->isAuthorized() && ! ((int)$this->ionAuth->user()->row()->id === $id)) 203 | { 204 | return redirect()->to('/admin/users'); 205 | } 206 | 207 | $validation = \Config\Services::validation(); 208 | 209 | $data['title'] = lang('Auth.edit_user_heading'); 210 | 211 | $user = $this->ionAuth->user($id)->row(); 212 | $groups = $this->ionAuth->groups()->resultArray(); 213 | $currentGroups = $this->ionAuth->getUsersGroups($id)->getResult(); 214 | 215 | if (! empty($_POST)) 216 | { 217 | // validate form input 218 | $validation->setRule('first_name', lang('Auth.edit_user_validation_fname_label'), 'trim|required'); 219 | $validation->setRule('last_name', lang('Auth.edit_user_validation_lname_label'), 'trim|required'); 220 | $validation->setRule('phone', lang('Auth.edit_user_validation_phone_label'), 'trim|required'); 221 | $validation->setRule('company', lang('Auth.edit_user_validation_company_label'), 'trim|required'); 222 | 223 | // do we have a valid request? 224 | if ($id !== $this->request->getPost('id', FILTER_VALIDATE_INT)) 225 | { 226 | throw new \Exception(lang('Auth.error_security')); 227 | } 228 | 229 | // update the password if it was posted 230 | if ($this->request->getPost('password')) 231 | { 232 | $validation->setRule( 233 | 'password', 234 | lang('Auth.edit_user_validation_password_label'), 235 | 'required|min_length[' . $this->configIonAuth->minPasswordLength . ']|matches[password_confirm]'); 236 | $validation->setRule( 237 | 'password_confirm', 238 | lang('Auth.edit_user_validation_password_confirm_label'), 239 | 'required'); 240 | } 241 | 242 | if ($this->request->getPost() && $validation->withRequest($this->request)->run()) 243 | { 244 | $data = [ 245 | 'first_name' => $this->request->getPost('first_name'), 246 | 'last_name' => $this->request->getPost('last_name'), 247 | 'company' => $this->request->getPost('company'), 248 | 'phone' => $this->request->getPost('phone'), 249 | ]; 250 | 251 | // update the password if it was posted 252 | if ($this->request->getPost('password')) 253 | { 254 | $data['password'] = $this->request->getPost('password'); 255 | } 256 | 257 | // Only allow updating groups if user is admin 258 | if ($this->ionAuth->isAdmin()) 259 | { 260 | // Update the groups user belongs to 261 | $groupData = $this->request->getPost('groups'); 262 | 263 | if (! empty($groupData)) 264 | { 265 | $this->ionAuth->removeFromGroup('', $id); 266 | 267 | foreach ($groupData as $grp) 268 | { 269 | $this->ionAuth->addToGroup($grp, $id); 270 | } 271 | } 272 | } 273 | 274 | // check to see if we are updating the user 275 | if ($this->ionAuth->update($user->id, $data)) 276 | { 277 | session()->setFlashdata('message', $this->ionAuth->messages()); 278 | } 279 | else 280 | { 281 | session()->setFlashdata('message', $this->ionAuth->errors($validationListTemplate)); 282 | } 283 | return redirect()->to('/admin/users'); 284 | } 285 | } 286 | 287 | // display the edit user form 288 | helper(['form']); 289 | 290 | // set the flash data error message if there is one 291 | $data['message'] = $validation->getErrors() ? $validation->listErrors() : ($this->ionAuth->errors() ? $this->ionAuth->errors() : $session->getFlashdata('message')); 292 | 293 | // pass the user to the view 294 | $data['user'] = $user; 295 | $data['groups'] = $groups; 296 | $data['currentGroups'] = $currentGroups; 297 | 298 | $data['firstName'] = [ 299 | 'name' => 'first_name', 300 | 'id' => 'first_name', 301 | 'type' => 'text', 302 | 'value' => set_value('first_name', $user->first_name ?: ''), 303 | ]; 304 | $data['lastName'] = [ 305 | 'name' => 'last_name', 306 | 'id' => 'last_name', 307 | 'type' => 'text', 308 | 'value' => set_value('last_name', $user->last_name ?: ''), 309 | ]; 310 | $data['company'] = [ 311 | 'name' => 'company', 312 | 'id' => 'company', 313 | 'type' => 'text', 314 | 'value' => set_value('company', empty($user->company) ? '' : $user->company), 315 | ]; 316 | $data['phone'] = [ 317 | 'name' => 'phone', 318 | 'id' => 'phone', 319 | 'type' => 'text', 320 | 'value' => set_value('phone', empty($user->phone) ? '' : $user->phone), 321 | ]; 322 | $data['password'] = [ 323 | 'name' => 'password', 324 | 'id' => 'password', 325 | 'type' => 'password', 326 | ]; 327 | $data['passwordConfirm'] = [ 328 | 'name' => 'password_confirm', 329 | 'id' => 'password_confirm', 330 | 'type' => 'password', 331 | ]; 332 | $data['ionAuth'] = $this->ionAuth; 333 | 334 | $body = view('Admin\users\edit_user', $data); 335 | return $this->view($body, lang('Auth.edit_user_heading'), 'users'); 336 | } 337 | 338 | /** 339 | * Activate the user 340 | * 341 | * @param integer $id The user ID 342 | * 343 | * @return \CodeIgniter\HTTP\RedirectResponse 344 | */ 345 | public function activate(int $id): \CodeIgniter\HTTP\RedirectResponse 346 | { 347 | $this->ionAuth->activate($id); 348 | session()->setFlashdata('message', $this->ionAuth->messages()); 349 | return redirect()->to('/admin/users'); 350 | } 351 | 352 | /** 353 | * Deactivate the user 354 | * 355 | * @param integer $id The user ID 356 | * 357 | * @throw Exception 358 | * 359 | * @return string|\CodeIgniter\HTTP\RedirectResponse 360 | */ 361 | public function deactivate(int $id = 0) 362 | { 363 | if (! $this->isAuthorized()) 364 | { 365 | // redirect them to the home page because they must be an administrator to view this 366 | throw new \Exception('You must be an administrator to view this page.'); 367 | } 368 | 369 | $validation = \Config\Services::validation(); 370 | 371 | $validation->setRule('confirm', lang('Auth.deactivate_validation_confirm_label'), 'required'); 372 | $validation->setRule('id', lang('Auth.deactivate_validation_user_id_label'), 'required|integer'); 373 | 374 | if (! $validation->withRequest($this->request)->run()) 375 | { 376 | helper(['form']); 377 | $data['user'] = $this->ionAuth->user($id)->row(); 378 | $body = view('Admin\users\deactivate_user', $data); 379 | return $this->view($body, lang('Auth.deactivate_heading'), 'users'); 380 | } 381 | else 382 | { 383 | // do we really want to deactivate? 384 | if ($this->request->getPost('confirm') === 'yes') 385 | { 386 | // do we have a valid request? 387 | if ($id !== $this->request->getPost('id', FILTER_VALIDATE_INT)) 388 | { 389 | throw new \Exception(lang('Auth.error_security')); 390 | } 391 | 392 | // do we have the right userlevel? 393 | if ($this->ionAuth->loggedIn() && $this->ionAuth->isAdmin()) 394 | { 395 | $message = $this->ionAuth->deactivate($id) ? $this->ionAuth->messages() : $this->ionAuth->errors(); 396 | session()->setFlashdata('message', $message); 397 | } 398 | } 399 | 400 | // redirect them back to the auth page 401 | return redirect()->to('/admin/users'); 402 | } 403 | } 404 | 405 | /** 406 | * Edit a group 407 | * 408 | * @param integer $id Group id 409 | * 410 | * @return string|CodeIgniter\Http\Response 411 | */ 412 | public function editGroup(int $id = 0) 413 | { 414 | // bail if no group id given 415 | if (! $this->isAuthorized() || ! $id) 416 | { 417 | return redirect()->to('/admin/users'); 418 | } 419 | 420 | $validation = \Config\Services::validation(); 421 | 422 | $data['title'] = lang('Auth.edit_group_title'); 423 | 424 | $group = $this->ionAuth->group($id)->row(); 425 | 426 | // validate form input 427 | $validation->setRule('group_name', lang('Auth.edit_group_validation_name_label'), 'required|alpha_dash'); 428 | 429 | if ($this->request->getPost()) 430 | { 431 | if ($validation->withRequest($this->request)->run()) 432 | { 433 | $groupUpdate = $this->ionAuth->updateGroup( 434 | $id, 435 | $this->request->getPost('group_name'), 436 | ['description' => $this->request->getPost('group_description')]); 437 | 438 | if ($groupUpdate) 439 | { 440 | session()->setFlashdata('message', lang('Auth.edit_group_saved')); 441 | } 442 | else 443 | { 444 | session()->setFlashdata('message', $this->ionAuth->errors()); 445 | } 446 | return redirect()->to('/admin/users'); 447 | } 448 | } 449 | 450 | helper(['form']); 451 | 452 | // set the flash data error message if there is one 453 | $data['message'] = $validation->listErrors() ?: ($this->ionAuth->errors() ?: session()->getFlashdata('message')); 454 | 455 | // pass the user to the view 456 | $data['group'] = $group; 457 | 458 | $readonly = $this->configIonAuth->adminGroup === $group->name ? 'readonly' : ''; 459 | 460 | $data['groupName'] = [ 461 | 'name' => 'group_name', 462 | 'id' => 'group_name', 463 | 'type' => 'text', 464 | 'value' => set_value('group_name', $group->name), 465 | $readonly => $readonly, 466 | ]; 467 | $data['groupDescription'] = [ 468 | 'name' => 'group_description', 469 | 'id' => 'group_description', 470 | 'type' => 'text', 471 | 'value' => set_value('group_description', $group->description), 472 | ]; 473 | 474 | $body = view('Admin\users\edit_group', $data); 475 | return $this->view($body, lang('Auth.edit_group_title'), 'users'); 476 | } 477 | 478 | /** 479 | * Create a new group 480 | * 481 | * @return string string|\CodeIgniter\HTTP\RedirectResponse 482 | */ 483 | public function createGroup() 484 | { 485 | if (! $this->isAuthorized()) 486 | { 487 | return redirect()->to('/auth'); 488 | } 489 | 490 | $data['title'] = lang('Auth.create_group_title'); 491 | 492 | $validation = \Config\Services::validation(); 493 | 494 | // validate form input 495 | $validation->setRule('group_name', lang('Auth.create_group_validation_name_label'), 'trim|required|alpha_dash'); 496 | 497 | if ($this->request->getPost() && $validation->withRequest($this->request)->run()) 498 | { 499 | $newGroupId = $this->ionAuth->createGroup($this->request->getPost('group_name'), $this->request->getPost('description')); 500 | if ($newGroupId) 501 | { 502 | // check to see if we are creating the group 503 | // redirect them back to the admin page 504 | session()->setFlashdata('message', $this->ionAuth->messages()); 505 | return redirect()->to('/admin/users'); 506 | } 507 | } 508 | else 509 | { 510 | // display the create group form 511 | helper(['form']); 512 | // set the flash data error message if there is one 513 | $data['message'] = $validation->getErrors() ? $validation->listErrors() : ($this->ionAuth->errors() ? $this->ionAuth->errors() : session()->getFlashdata('message')); 514 | 515 | $data['groupName'] = [ 516 | 'name' => 'group_name', 517 | 'id' => 'group_name', 518 | 'type' => 'text', 519 | 'value' => set_value('group_name'), 520 | ]; 521 | $data['description'] = [ 522 | 'name' => 'description', 523 | 'id' => 'description', 524 | 'type' => 'text', 525 | 'value' => set_value('description'), 526 | ]; 527 | 528 | $body = view('Admin\users\create_group', $data); 529 | return $this->view($body, lang('Auth.create_group_title'), 'users'); 530 | } 531 | } 532 | } 533 | -------------------------------------------------------------------------------- /src/Language/en/Admin.php: -------------------------------------------------------------------------------- 1 | 7 | * @license https://opensource.org/licenses/MIT MIT License 8 | * @link https://github.com/bvrignaud/ci-admin 9 | */ 10 | 11 | return [ 12 | 'home-title' => 'Home', 13 | 'informations-title' => 'Informations', 14 | 15 | // menu 16 | 'menu-users' => 'Users', 17 | 'menu-labelInformation' => 'Informations', 18 | 'menu-generalInformation' => 'General informations', 19 | 20 | // Generic 21 | 'yes' => 'yes', 22 | 'no' => 'no', 23 | 24 | // Informations pages 25 | 'display_phpinfo' => 'Show phpinfo', 26 | 'download_database' => 'Download database', 27 | 'email_params' => 'E-mail parametres', 28 | 'send_test_email' => 'Send test email', 29 | ]; 30 | -------------------------------------------------------------------------------- /src/Language/fr/Admin.php: -------------------------------------------------------------------------------- 1 | 7 | * @license https://opensource.org/licenses/MIT MIT License 8 | * @link https://github.com/bvrignaud/ci-admin 9 | */ 10 | 11 | return [ 12 | 'home-title' => 'Accueil', 13 | 'informations-title' => 'Informations', 14 | 15 | // menu 16 | 'menu-users' => 'Utilisateurs', 17 | 'menu-labelInformation' => 'Informations', 18 | 'menu-generalInformation' => 'Informations générales', 19 | 20 | // Generic 21 | 'yes' => 'oui', 22 | 'no' => 'non', 23 | 24 | // Informations pages 25 | 'display_phpinfo' => 'Afficher le phpinfo', 26 | 'download_database' => 'Sauvegarder la base de données', 27 | 'email_params' => 'Paramètres e-mail', 28 | 'send_test_email' => 'Envoyer un email de test', 29 | ]; 30 | -------------------------------------------------------------------------------- /src/Views/home.php: -------------------------------------------------------------------------------- 1 | home page 2 | -------------------------------------------------------------------------------- /src/Views/informations.php: -------------------------------------------------------------------------------- 1 | '; 15 | $html .= $module . ' : '; 16 | $class = in_array($module, apache_get_modules()) ? 'success' : 'error'; 17 | $html .= ''; 18 | $html .= ''; 19 | } 20 | return $html; 21 | } 22 | ?> 23 |
24 | 25 |
26 |
27 |

CodeIgniter

28 |
29 |
30 |

CodeIgniter ()

31 |
32 |
33 | 34 |
35 |
36 |

Configuration php

37 |
38 |
39 |

40 | php : -> 50600 ? 'OK' : 'NOK (php > 5.6 requis)'?> 41 |

42 |

Timezone :

43 |

Modules

44 |
    45 | 55 |
56 | 57 |

Extensions

58 |

intl actif : (préconisé)

59 |

xdebug :

60 |

phpinfo

61 | 62 |
63 |
64 | 65 |
66 |
67 |

MySQL

68 |
69 |
70 |

Seveur MySQL :

71 | 73 | 74 | 75 |
76 |
77 | 78 |
79 |

80 |
81 | 'formSendMail'])?> 82 |
83 | 84 | 85 |
86 | 87 |
88 | 90 |
91 | 92 | 94 |
95 |
96 | 97 |
98 | 99 | 157 | -------------------------------------------------------------------------------- /src/Views/main.php: -------------------------------------------------------------------------------- 1 | 2 | 3 | 4 | 5 | 6 | 7 | 8 | 9 | 10 | <?= $appName ?> | Admin 11 | 12 | 13 | 14 | 15 | 16 | 17 | 18 | 19 | 20 |
21 | 22 | 23 | 34 | 35 | 36 | 37 | 70 | 71 | 72 |
73 | 74 |
75 |
76 |
77 |
78 |

79 |
80 |
81 | 85 |
86 |
87 |
88 |
89 | 90 | 91 | 92 |
93 |
94 | 95 |
96 |
97 | 98 |
99 | 100 | 101 | 102 | 109 | 110 | 111 |
112 | 113 | 114 | 115 | 116 | 117 | 118 | 119 | 120 | 121 | 122 | 123 | 124 | -------------------------------------------------------------------------------- /src/Views/users/create_group.php: -------------------------------------------------------------------------------- 1 |

2 |

3 | 4 |
5 | 6 | 7 | 8 |

9 |
10 | 11 |

12 | 13 |

14 |
15 | 16 |

17 | 18 |

19 | 20 | 21 | -------------------------------------------------------------------------------- /src/Views/users/create_user.php: -------------------------------------------------------------------------------- 1 |

2 |

3 | 4 |
5 | 6 | 7 | 8 |

9 |
10 | 11 |

12 | 13 |

14 |
15 | 16 |

17 | 18 | '; 22 | echo form_label(lang('Auth.create_user_identity_label'), 'identity'); 23 | echo '
'; 24 | echo form_error('identity'); 25 | echo form_input($identity); 26 | echo '

'; 27 | } 28 | ?> 29 | 30 |

31 |
32 | 33 |

34 | 35 |

36 |
37 | 38 |

39 | 40 |

41 |
42 | 43 |

44 | 45 |

46 |
47 | 48 |

49 | 50 |

51 |
52 | 53 |

54 | 55 | 56 |

57 | 58 | 59 | -------------------------------------------------------------------------------- /src/Views/users/deactivate_user.php: -------------------------------------------------------------------------------- 1 |

2 |

username);?>

3 | 4 | id);?> 5 | 6 |

7 | 8 | 9 | 10 | 11 |

12 | 13 | id); ?> 14 | 15 |

16 | 17 | 18 | -------------------------------------------------------------------------------- /src/Views/users/edit_group.php: -------------------------------------------------------------------------------- 1 |

2 |

3 | 4 |
5 | 6 | 7 | 8 |

9 |
10 | 11 |

12 | 13 |

14 |
15 | 16 |

17 | 18 |

19 | 20 | 21 | -------------------------------------------------------------------------------- /src/Views/users/edit_user.php: -------------------------------------------------------------------------------- 1 |

2 |

3 | 4 |
5 | 6 | 7 | 8 |

9 |
10 | 11 |

12 | 13 |

14 |
15 | 16 |

17 | 18 |

19 |
20 | 21 |

22 | 23 |

24 |
25 | 26 |

27 | 28 |

29 |
30 | 31 |

32 | 33 |

34 |
35 | 36 |

37 | 38 | isAdmin()): ?> 39 | 40 |

41 | 42 | 59 | 60 | 61 | 62 | 63 | id);?> 64 | 65 |

66 | 67 | 68 | -------------------------------------------------------------------------------- /src/Views/users/users.php: -------------------------------------------------------------------------------- 1 |

2 | 3 |
4 | 5 | 6 | 7 | 8 | 9 | 10 | 11 | 12 | 13 | 14 | 15 | 16 | 17 | 18 | 19 | 24 | 31 | 32 | 33 | 34 |
first_name);?>last_name);?>email);?> 20 | groups as $group):?> 21 | id, esc($group->name)); ?>
22 | 23 |
25 | active) ? 27 | anchor('admin/users/deactivate/' . $user->id, lang('Auth.index_active_link')) : 28 | anchor('admin/users/activate/' . $user->id, lang('Auth.index_inactive_link')); 29 | ?> 30 | id, 'Edit') ;?>
35 | 36 |

37 | 38 | | 39 | 40 |

41 | --------------------------------------------------------------------------------