[split] Ion-Auth with CI4 |
(10-29-2019, 03:20 AM)orionstar Wrote: As far as I know, the IonAuth 4 lacks the documentation entirely, the docs page is for IA3! The documentation is for IonAuth 3 but also for IonAuth 4 ... The library was ported to be used in CI4 not rewriten... So, almost everything should look the same ! To install it, IT IS SUPER EASY ! Even without composer. (I dont like a script messing with my sh1t)... Basically, you just need to extract tha IonAuth folder to the root-directory and change one config ! SUPER EASY !!! Code: CI 4.x # → Root Directory Installing Ion Auth 4.x =================================== Before installing, please check that you are meeting the minimum server requirements. Ion Auth 4 needs CodeIgniter 4.x and PHP 7.1. There are different ways to install this package. > 1. With composer For an existing composer project: ```shell $ composer config minimum-stability dev $ composer config repositories.ionAuth vcs [email protected]:benedmunds/CodeIgniter-Ion-Auth.git $ composer require benedmunds/CodeIgniter-Ion-Auth:4.x-dev ``` For a new project: ```shell $ composer init $ composer config minimum-stability dev $ composer config repositories.ionAuth vcs [email protected]:benedmunds/CodeIgniter-Ion-Auth.git $ composer require benedmunds/CodeIgniter-Ion-Auth:4.x-dev ``` --- > 2. With Git: ```shell my-project$ git clone https://github.com/benedmunds/CodeIgniter-Ion-Auth.git my-project$ cd CodeIgniter-Ion-Auth CodeIgniter-Ion-Auth$ git checkout 4 ``` Then in your Config/Autoload.php, add this : ```php 'IonAuth' => ROOTPATH . 'CodeIgniter-Ion-Auth', ``` --- > 3. Download the archive, and move folder from this package to the root folder: ```shell CI 4.x # → Root Directory ├── app/ ├── ion-auth/ # → Ion-auth directory ├── public ├──... ``` Then in your Config/Autoload.php, add this : ```php 'IonAuth' => ROOTPATH . 'YOUR-ION_AUTH-FOLDER', ``` --- ### Relational DB Setup Then use the migration file (in Database/Migrations/). ``` $ php spark migrate:latest -n IonAuth ``` Don't forget to set Config\Migrations:enabled to true. You can also use the seeds file to insert default datas: Windows : ``` $ php spark db:seed IonAuth\Database\Seeds\IonAuthSeeder ``` Linux : ``` $ php spark db:seed IonAuth\\Database\\Seeds\\IonAuthSeeder ``` --- ### Use it The most convenient way is to create a new controller like this : ```php <?php namespace App\Controllers; class Auth extends \IonAuth\Controllers\Auth { /** * If you want to customize the views, * - copy the ion-auth/Views/auth folder to your Views folder, * - remove comment */ // protected $viewsFolder = 'auth'; } ``` You can also add routes configs in 'Config\Routes.php': ```php $routes->group('auth', ['namespace' => 'IonAuth\Controllers'], function ($routes) { $routes->get('/', 'Auth::index'); $routes->add('login', 'Auth::login'); $routes->get('logout', 'Auth::logout'); $routes->get('forgot_password', 'Auth::forgot_password'); }); ```
IonAuth is great, I have all respect for it. It is not a very good example of a CodeIgniter 4 module nor does it leverage a lot of the strength of CI4. It is a port of a library from CI3 so lacks support for a number of features in CI4. The docs are not valid for CI4 so its a little hard to tell but it seems like developers either need to extend the IonAuth controller (which precludes extending another Controller, like the framework resource controllers) or implement their own use of the library in filters/controllers.
I encourage everyone to check out Lonnie's Myth:Auth (https://github.com/lonnieezell/myth-auth) as both an example of a specifically-CI4 module and as an authentication/authorization library that leverages the frameworks strength, notably for authentication: filters, validation, and handles wrapped by services. But also named routes, CLI commands, toolbar collector, permissive entities, etc. There's a lot that is worth doing the "CI4 way", and while libraries port fairly easily from CI3 (see the current CI4 Email library for example) I recommend rewriting over porting whenever resources permit. (11-01-2019, 06:12 AM)MGatner Wrote: IonAuth is great, I have all respect for it. It is not a very good example of a CodeIgniter 4 module nor does it leverage a lot of the strength of CI4. It is a port of a library from CI3 so lacks support for a number of features in CI4. The docs are not valid for CI4 so its a little hard to tell but it seems like developers either need to extend the IonAuth controller (which precludes extending another Controller, like the framework resource controllers) or implement their own use of the library in filters/controllers. There is NO need to extend Ion Auth controller. Just need to load the library... PHP Code: //Pre loads the Authentication Library: ION AUTH And check for login: PHP Code: if ( $this->ionAuth->loggedIn() ) { Simple as that... Myth:Auth is awesome and Lonnie is doing a SUPERB job ! But so far I was not able to install or use the library.... ... and Ion Auth is simple as unzipping the file, changing some configs and... you are ready to go !
How work IonAuth in CI4?? WTF??
I https://github.com/benedmunds/CodeIgnite...hModel.php I see $this->db->select(... ->get($this->tables['users']);... $query->numRows()... But CI4 dont support this functions. We must use $this->db->table($this->tables['users']), $builder->getRow() and ->getFieldCount() I getting error Call to undefined method CodeIgniter\Database\MySQLi\Connection:elect() (11-12-2019, 12:51 PM)XTAZ Wrote: How work IonAuth in CI4?? WTF?? It is working here... Just followed the instructions.... |
Welcome Guest, Not a member yet? Register Sign In |