Log In After Accept Invitation

I’ve got a system where people are invited to join under various scenarios. In one scenario everything works fine, the invited user fills out the form, submits, gets a confirm email and on confirming they are logged in and ready to go.

In the other scenario, they don’t need to confirm. The code is very similar, however in the second scenario, the user is not logged in after completing the form. The account is valid and they can log in by the normal means, but its a bit silly to just join up and then have to log in with the credentials you just created.

I cannot figure out why the same bit of code works in the first scenario but not the second.

This is the controller action for scenario 2:

      public function actionAccept($id)



        //check the uuencoded password string.

        $salt = urldecode($id); 

        $model = User::model()->find("salt = '".$salt."'");

        if (!isset($model->id))  $this->redirect(array('site/fail/nomatch'));

        // there is a matching user.

        // model loads the existing user



            // if the form has been submitted


        if ($_POST['User']['password']==$_POST['User']['password2']){

            $model->scenario = 'update';





            $model->salt = $model->generateSalt();




            $identity = new UserIdentity($model->email, $model->password);


            $identity->errorCode = UserIdentity::ERROR_NONE;

            Yii::app()->user->login($identity, (Yii::app()->params['loggedInDays'] * 60 * 60 * 24 ));














This is driving me crazy - can anyone see what the issue is?