Welcome Guest, Not a member yet? Register   Sign In
public $filters except login page
#1

I work with filter method for check admin users authentication like this:

PHP Code:
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\Auth::class,
    ];

    
// Always applied before every request
    
public $globals = [
        
'before' => [
            
//'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 = [
        'auth' => ['before' => 'admin/*'],
    ];


public filter work for all admin uri (admin/roles  - admin/users - admin/login) but i need to except admin/login because with this method i can not see login page and see browser error:

Code:
This page isn’t working right now
ci4.local redirected you too many times.
ERR_TOO_MANY_REDIRECTS


how do fix this problem?! thanks
Reply
#2

Yep, it's called "except": https://codeigniter4.github.io/userguide...ml#globals
Reply
#3

You need to add condition inside AuthFilter, I do it like this
PHP Code:
// get the current URL path, like "auth/login"
$currentURIPath "/{$request->uri->getPath()}";

// check if the current path is auth path, just return true
// don't forget to use named routes to simplify the call
if (in_array($currentURIPath, [route_to('auth'), route_to('api.auth.login')])) {
    return;

I hope this can help.
Reply
#4

It's work fine with v4.0.4

My Default Controller is Login on global I add my authenticationfilter and add except for all Login controller 'login/*' and '/'

public $aliases = [
'csrf' => \CodeIgniter\Filters\CSRF::class,
'toolbar' => \CodeIgniter\Filters\DebugToolbar::class,
'honeypot' => \CodeIgniter\Filters\Honeypot::class,
'authenticationfilter' => \App\Filters\AuthenticationFilter::class,
];

// Always applied before every request
public $globals = [
'before' => [
'authenticationfilter'=> ['except' => ['login/*', '/']],
//'honeypot'
// 'csrf',
],
'after' => [
'toolbar',
//'honeypot'
],
];
There are those who tell lies with meaning behind them and those meaning less lies!
Reply




Theme © iAndrew 2016 - Forum software by © MyBB