Module Authentication

Is it possible to specify general authentication rules for a whole module? (instead of separately in each controller)

For example only authenticated (@) users should be able to access any actions within the module.

You can simply create base module controller with defaults. All your module controllers should extend it.

Actually this seems to work (in module):


public function beforeControllerAction($controller, $action)

{

	if(parent::beforeControllerAction($controller, $action))

	{

		if(Yii::app()->getModule('dashboard')->user->isGuest)

		{

			Yii::app()->user->loginRequired();

		}

			

		return true;

	}

	else

		return false;

}

Any problems with this approach?

You’ll not be able to create unprotected module actions (for example, login)

You can:

http://www.yiiframework.com/wiki/89/module-based-login

Yes, but I was talking about your piece of code.

So don’t forget about


!in_array($route, $publicPages)

(this is an example from your link) or something similar.