I am using the Auth component and ACL to give permission to roles and redirect them to /login if they don't have the proper rights.
That works fine for all existing controller/action. But when ever I enter a none existing controller action http://www.mypage.de/fake/bla I get a notFoundExeption.
My issue with that is, that the user sees my admin layout, because the 404 is rendered within the admin layout template.
Is there a way to say that admin (or any prefix) is always restricted and users that are not logged in get redirected to the login page?
What I came up with is this, but I don't like it, because I would have to do the same for all other prefixes.
/**
* AppController::afterFilter()
*
* @return void
*/
function afterFilter() {
if ($this->response->statusCode() === 404 && !empty($this->request->params['admin'])) {
$url = Router::url(
array(
'admin' => false,
'plugin' => false,
'controller' => 'users',
'action' => 'login'
)
);
$this->Common->flashMessage(__('You are not authorized to access that location.'), 'error');
return $this->redirect($url);
}
}