<?php 
namespace App\Filters;

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

class RoleFilter implements FilterInterface {
	
	public function before(RequestInterface $request, $arguments = null) {
		if (!session()->get('username')) {
			return redirect()->to('/auth/login');
		}
		
		$userRole = session()->get('userrole');
		if ($arguments && !in_array($userRole, $arguments)) {
			return redirect()->to('/no-access');
		}
	}

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