Welcome Guest, Not a member yet? Register   Sign In
Filter config not working with routes (?)
#1

Basically, I have a filter called "sessionCheckGloba", which deals with making sure that a user is logged in prior to accessing a webpage. The config for this filter is the following:

PHP Code:
public $globals = [
    
'before' => [
        
'sessioncheckGlobal' => ['except' => ['maintenance''browseroutofdate''login''logout''website']],
    ]
]; 


Where 'website' is in the exception list, it doesn't work.
Neither does '' (a blank element) or '/' (which stops the filter running at all).


So I guess the first question is, how do you make a filter not run on the main page where the main page is configured as the default controller?

In our case, the default controller is app/Controllers/Website/Website.php and the App is configured to route in this way:

Code:
$routes->get('/', 'Website/Website::index');

Second question, why does the following config make logincheck run on /admin/login ?

Code:
public $filters = [
    'loginfilter' => ['before' => ['login']],
];

In case, some more routes:

Code:
$routes->get('/login', 'Dashboard/Login::index');
$routes->get('/admin/login', 'Admin/Login::index');

My friend has created a similar question on GitHub but I feel like a lot of people use the forums and not GitHub.

Thanks.
Reply
#2

(This post was last modified: 06-04-2019, 08:27 AM by ciadmin.)

Thanks for posting here. We do not provide support through GitHub only here, so that was the right thing to do. Smile

Does anything show up in the logs? It sounds like an error is being repressed. Does the route still display like normal or does it go to a blank screen?

I'll start with the easy one: There does appear to be a bug with the login or admin/login that is not requiring that string to be at the beginning. Should be a relatively simple fix.

As for the weird issue you're seeing with the Website controller - I'm unable to duplicate. I set things up as closely as I could, though used App\Controllers\Website\Website so that I didn't have to setup a new namespace. Played with several variations of assigning the filter and it seemed to work correctly. Both with and without the fix I found for the other issue.

Can you replicate in any other way out of the box with generic install of CodeIgniter? You may need to follow the code through a bit, which should be in either CodeIgniter.php or Filters/Filters.php.
Reply
#3

About your first question, my logs are completely empty.

As for the second question, yes, I created a clean version of CodeIgniter, and still had the same issue.
Reply
#4

(06-03-2019, 08:13 PM)kilishan Wrote: Does anything show up in the logs? It sounds like an error is being repressed. Does the route still display like normal or does it go to a blank screen?

Logs are completely empty and by that I mean that log level is set to 9 and permissions set to the writable directory, but no log file is ever created. Route still displays as normal (in our case it redirects to another part of the website because if user is not authenticated then he should login first - intended behaviour).

We tried on an empty install yesterday with just two controllers and the same behaviour still appeared.

Is 'website' the correct exception to configure? From my understanding, the except list should contain URI's, but surely if the website is configured to point to the default controller, then website.com is what shows up in the browser, the URI is actually blank bar the domain - i.e. there is nothing after website.com. But as mentioned here setting "" or "/" doesn't work either.
Reply
#5

(This post was last modified: 05-01-2020, 02:51 PM by ignitedev.)

Hi there, i have more or less the same issue, my problem is when i try to redirect after the filter execution, the code is something simple like this...

PHP Code:
public function before(RequestInterface $request)
    {
        $this->session = \Config\Services::session();
        if($this->session->get('login') == TRUE)
    {
        return redirect()->to('main/');
     }else{
        return redirect()->to('home/');
     }



If i don't especify the index method then the redirecction won't work, says temporal redirection error. But is only with the controller especified in the filter, any other will work fine.

I hope any can helpme with this issue.
Thanks a loot and great work with te 4th version of the framework.

PD: Excuse me for my english is not so good.
Reply
#6

What is the solution or fix for this. Its bugging me for few days now
Reply




Theme © iAndrew 2016 - Forum software by © MyBB