0

Is it a way to customize the authError URL on CakePHP? If I look into the Auth component I've placed in the AppController i have a redirect action loginRedirect and logoutRedirect but i don't know if is it possible to set something like authErrorRedirect:

<?php
class AppController extends Controller {

    public $components = array(
        'Session',
        'Auth' => array(
            'loginRedirect' => array('controller' => 'users', 'action' => 'index'),
            'logoutRedirect' => array('controller' => 'users', 'action' => 'index'),
            'authError' => 'You don\'t have the right to go there.',
            // something like this
            'authErrorRedirect' => array('controller' => 'users', 'action' => 'login'),
            'authorize' => array(
                'Controller',
                'Actions' => array(
                    'actionPath' => 'controllers'
                )
            ),
            'authenticate' => array(
                'Form' => array(
                    'fields' => array('username' => 'email')
                )
            )
        ),
        'Acl'
    );

Can I set an authError redirect action?

vitto
  • 19,094
  • 31
  • 91
  • 130

1 Answers1

0

No. If you follow the Simple Authentication and Authorization Application Example @ CakePHP Cookbook v2.x documentation you should redirect in the login action where the login fails for 'Invalid username or password...'. These only makes sense if you want to redirect for a different action, in the following example login2

public function login() {
    if ($this->request->is('post')) {
        if ($this->Auth->login()) {
            $this->redirect($this->Auth->redirect());
        } else {
            $this->Session->setFlash(__('Invalid username or password, try again'));
            $this->redirect(array('controller' => 'users', 'action' => 'login2'));
        }
    }
}
jplfl
  • 82
  • 11
  • I got it, if an user goes to a resource he can't access he have to login, simple and clear. – vitto Sep 25 '12 at 08:50