Site/login Problem

I have an Yii project evolving for a year or so. It happened so that all user related stuff (such as profile view and registration) is managed by UserController. So it looks strange that login action remains in SiteController so far, as it is in the standard template. Today I decided to move this action from SiteController to UserController, but have spent a couple of hours to no avail.

Just after the code movement I discovered a very strange behaviour that ‘user/login’ get redirected to ‘site/login’. It took some time to dig out that Yii’s CWebUser has public $loginUrl variable, which apparently interfere in the process. I changed its value in my decendant class to ‘array(’/user/login’)’. But now the browser complains about infinite redirection. This is bacause in responce to GET /user/login HTTP/1.1 I always receive HTTP/1.1 302 Found Location: http://localhost/user/login, which is the same.

What is going on? How to fix the problem?

Thanks in advance.

Have you try to change default login url in main config file






I don’t think this is important because I specified my WebUser class in the config, and this is the class where I redefined $loginUser. Here is my config, if you wish:

'user' => array(

			'allowAutoLogin' => true,

			'class' => 'WebUser',

      'loginUrl'=>array('user/login'), // this line was added after reading your post, and it changed nothing


I added the suggested line, but the problem remains.

The problem is solved. The login action should be added into accessRules of UserController. SiteController does not have any, so it was easy to forget about this. Here is a self-explaining stacktrace:

CHttpRequest->redirect file://www/yii/framework/web/CHttpRequest.php:761

CWebUser->loginRequired file://www/yii/framework/web/auth/CWebUser.php:374

CAccessControlFilter->accessDenied file://www/yii/framework/web/auth/CAccessControlFilter.php:168

CAccessControlFilter->preFilter file://www/yii/framework/web/auth/CAccessControlFilter.php:133

CFilter->filter file://www/yii/framework/web/filters/CFilter.php:39

CController->filterAccessControl file://www/yii/framework/web/CController.php:1146

CInlineFilter->filter file://www/yii/framework/web/filters/CInlineFilter.php:59

CFilterChain->run file://www/yii/framework/web/filters/CFilterChain.php:131

CController->runActionWithFilters file://www/yii/framework/web/CController.php:292

CController->run file://www/yii/framework/web/CController.php:266

CWebApplication->runController file://www/yii/framework/web/CWebApplication.php:287

CWebApplication->processRequest file://www/yii/framework/web/CWebApplication.php:146

CApplication->run file://www/yii/framework/base/CApplication.php:162

{main}     file://www/index.php:13