<?php namespace App\Filters;

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

class Authentication implements FilterInterface
{
    public function before(RequestInterface $request, $arguments = null)
    {
                $session = session();
                $project = config('Config\\Project');
                //echo 'sdfads';
                //exit();
                if (strpos(strtolower(uri_string()), strtolower($project->admin_dir."/")) !== false) {
                        // Check user logged in
                        if(is_null($session->get($project->session_admin_user_id))){                        
                                return redirect()->to(base_url(strtolower($project->admin_dir)."/secure"));                        
                        }
                }
    }

    public function after(RequestInterface $request, ResponseInterface $response, $arguments = null)
    {
        // Do something here
    }
}