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.
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: