Additional feature for access rules

I am doing an app that requires authentication. In the index page of the app, I specified access rules like this


	public function accessRules()

	{

		return array(


			array('deny',

				'actions'=>array('index','register','login','password'),

				'users'=>array('@'),

			),

			array('allow',

				'users'=>array('*'),

			),

		);

	}

At the first rule, the actions ‘index’,‘register’,‘login’ and ‘password’ are made unaccessible to authenticated users. However, I do not want to show this message


Unauthorized

You are not authorized to perform this action.


You do not have the proper credential to access this page. 


If you think this is a server error, please contact the webmaster.

to the authenticated users when they try to access those actions. Instead, I want to redirect them to another page. It would be useful if i could do something like this at the first rule


			array('redirect',

				'actions'=>array('index','register','login','password'),

				'users'=>array('@'),

                                'url'=>array('home/index'),

			),

in order to redirect the authenticated users who try to access those actions to another Controller or action.

Perhaps this will be considered for the core, but otherwise you can extend CAccessControlFilter::accessDenied(). You will also need to change CController::filterAccessControl()

Subclass CAccessControlFilter like so:




class MyAccessControlFilter extends CAccessControlFilter

{

  protected function accessDenied($user)

  {

    if($user->getIsGuest())

      $user->loginRequired();

    else {

      // Do what you want here


      // This is the default behaviour, comment out if not wanted

      throw new CHttpException(403,Yii::t('yii','You are not authorized to perform this action.'));

    }

  }

}



To use this instead of the std filter, do the following:




public function filters()

{

  return array(

    array('path.to.MyAccessControlFilter'),

  );

}