yii-user - auto-login after registration problems

Hi

I’m having problems with the auto-login for the yii-user module. If I set the parameter “$activeAfterRegister=true;” in UserModule.php and in main config:

                    'sendActivationMail' => false,


                    'loginNotActiv' => false,


                    'autoLogin' => true,

I have made a small change to the yii-user module, so that username is auto-generated rather than input in the registration form, but I don’t think this is relevant to my problems.

The error I see in the browser is "too many redirects".

This is caused by the UserIdentity class thinking that I have been authenticated but the framework core class not.

So in the RegistrationController where you find the code:




		$identity=new UserIdentity($model->username,$soucePassword);

				$identity->authenticate();

				Yii::app()->user->login($identity,0);

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

				if (Yii::app()->user->isGuest) {

					//$this->redirect(Yii::app()->controller->module->logoutUrl);

					echo "GUEST";

				} else {

					//$this->redirect(Yii::app()->controller->module->returnUrl);

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

					echo "LOGGED IN";

				}

			

In the UserIdentity class I placed some traces which show that the authentication has been successful. But when I var_dump the Yii::app()->user it shows that I have not been authenticated and am registered as "Guest", therefore the redirect to the profile page gets bounced to the login and then back to the profile.

I’ve been doing my nut in trying to figure out why the User Module UserIdentity class has a different result to the core User class.

Any hints?

Thanks

Chris

Thanks to "smug", who suggested I checkout SESSION timeout. So, I changed the line


Yii::app()->user->login($identity,0);

to


Yii::app()->user->login($identity,60 * 20);

so final version of changes to RegistrationController are:


		

        $identity=new UserIdentity($model->username,$soucePassword);

	$identity->authenticate();

        // set SESSION timeout to 20mins

	Yii::app()->user->login($identity,60*20);

	// add a check that the login worked

        if (Yii::app()->user->isGuest) {

	   $this->redirect(Yii::app()->controller->module->logoutUrl); // no, it didn't, so clear session by logging out

	} else {

	   $this->redirect(Yii::app()->controller->module->returnUrl);

	}



and it seems to work fine now!