Welcome Guest, Not a member yet? Register   Sign In
About IonAuth 4 auth System
#5

You have to create a filter in App -> Filters, something like :
PHP Code:
<?php

namespace App\Filters;

use 
CodeIgniter\HTTP\RequestInterface;
use 
CodeIgniter\HTTP\ResponseInterface;
use 
CodeIgniter\Filters\FilterInterface;
use 
IonAuth\Libraries\IonAuth;

/**
* Description of AuthFilter
*
* @author christian
*/
class AuthFilter implements FilterInterface {

    public function before(RequestInterface $request) {
        $this->ionAuth = new IonAuth();
        if (!($this->ionAuth->loggedIn()) || !($this->ionAuth->isAdmin())) {
            session()->set('redirect_url'current_url());
            return redirect()->to('auth/login');            
        
}
    }

    //--------------------------------------------------------------------

    public function after(RequestInterface $requestResponseInterface $response) {
        // Do something here
    }



Then to apply it, modify the config in App -> Config -> Filters like this :
PHP Code:
[quote pid='369076' dateline='1572757201']
<?
php namespace Config;

use 
CodeIgniter\Config\BaseConfig;

class 
Filters extends BaseConfig
{
// Makes reading things below nicer,
// and simpler to change out script that's used.
public $aliases = [
 
'csrf'    => \CodeIgniter\Filters\CSRF::class,
 
'toolbar'  => \CodeIgniter\Filters\DebugToolbar::class,
 
'honeypot' => \CodeIgniter\Filters\Honeypot::class,
 'auth'    => \App\Filters\AuthFilter::class
 ];

// Always applied before every request
public $globals = [
'before' => [
   'auth' => ['except'=>['auth/login']],
//'honeypot'
// 'csrf',
],
'after'  => [
 
'toolbar',
 
//'honeypot'
 
],
];

// Works on all of a particular HTTP method
// (GET, POST, etc) as BEFORE filters only
//    like: 'post' => ['CSRF', 'throttle'],
public $methods = [];

// List filter aliases and any before/after uri patterns
// that they should run on, like:
//    'isLoggedIn' => ['before' => ['account/*', 'profiles/*']],
public $filters = [];
}
[/
quote
Reply


Messages In This Thread
About IonAuth 4 auth System - by adelbak - 11-02-2019, 10:00 PM
RE: About IonAuth 4 auth System - by Poetawd - 11-09-2019, 02:08 PM
RE: About IonAuth 4 auth System - by macruzgi - 11-13-2019, 10:55 AM
RE: About IonAuth 4 auth System - by XTAZ - 11-12-2019, 01:16 PM
RE: About IonAuth 4 auth System - by cseon - 11-27-2019, 12:59 AM



Theme © iAndrew 2016 - Forum software by © MyBB