accessFilter for not authentificated users..

I want to set filter accessControll like that:

Only not-authentificated users can reach actions: captcha, register, recovery, activate;

Only authentificated users can reach actions: logout, settings;

How to set filter accessControl to do that?

I tried:




		return array(

			array('allow',

				'actions'=>array('captcha','register','recovery', 'activate'),

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

			),		

			array('allow', 

				'actions'=>array('logout','settings'),

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

			),

			array('allow',

				'actions'=>array('login'),

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

			),

			array('deny', 

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

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

			),

		);


and:


		return array(

			array('deny',

				'actions'=>array('captcha','register','recovery', 'activate'),

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

			),		

			array('allow', 

				'actions'=>array('logout','settings'),

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

			),

			array('allow',

				'actions'=>array('login'),

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

			),

			array('deny', 

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

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

			),

		);




First example doesn’t work.

In second one I saw strange behaviour…

Even I have configured errorAction in main.php Yii was trying to reach default errorAction, stack:

#0 E:\PHP\kodinocms\yii\web\CController.php(262): CController->missingAction(‘error’)

#1 E:\PHP\kodinocms\yii\web\CWebApplication.php(328): CController->run(‘error’)

#2 E:\PHP\kodinocms\yii\base\CErrorHandler.php(279): CWebApplication->runController(’/site/index/err…’)

#3 E:\PHP\kodinocms\yii\base\CErrorHandler.php(178): CErrorHandler->render(‘error’, Array)

#4 E:\PHP\kodinocms\yii\base\CErrorHandler.php(103): CErrorHandler->handleException(Object(CHttpException))

#5 E:\PHP\kodinocms\yii\base\CApplication.php(631): CErrorHandler->handle(Object(CExceptionEvent))

#6 [internal function]: CApplication::handleException(Object(CHttpException))

#7 {main}

I don’t understand it.

Any advices? Or should I do it manually by checking Yii::app()->user->isGuest in every action?

in the first one replace




array(

   'allow','actions'=>array('captcha','register','recovery', 'activate'),

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

   ),          



for




array('allow',

   'actions'=>array('captcha','register','recovery', 'activate'),

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

),          




the error that its thrown is becase it cant find the errorAction

This setting allow ALL users to reach that actions, but it’s not my goal.

I asked is this possible to set this actions as reachable ONLY for non-authificated users ?

Yes, I know that but look (line #2):

#0 E:\PHP\kodinocms\yii\web\CController.php(262): CController->missingAction(‘error’)

#1 E:\PHP\kodinocms\yii\web\CWebApplication.php(328): CController->run(‘error’)

#2 E:\PHP\kodinocms\yii\base\CErrorHandler.php(279): CWebApplication->runController(’/site/index/err…’)

#3 E:\PHP\kodinocms\yii\base\CErrorHandler.php(178): CErrorHandler->render(‘error’, Array)

I don’t know why Yii not find ‘site/index/error’ - because that action is in code and it works in every other places…

because you must allow error action to all users

The first code you posted seens fine to do what you want, cant help you more there, sorry

Yes its possible , but i dont know why you won`t to set this actions as reachable ONLY for non-authificated users ?????

Hire is

Access control filter

And guide

Athentication guide

and you get error because you deny all actions including a error action

I think that a token ONLY unauthenticated user doesn’t exist.

You have to do the check manually in the action:




if (!Yii::app()->user->IsGuest())

    throw new excepion();



he can




array('deny', 

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

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

 ),