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)

    {

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

        //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

        //$model=$this->loadModel($newaccount->id);


        if(isset($_POST['User']))

            // if the form has been submitted

        {   

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

            $model->scenario = 'update';

            $model->type=1;

            $model->firstname=$_POST['User']['firstname'];

            $model->lastname=$_POST['User']['lastname'];

            $model->password=$_POST['User']['password'];

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

                        

            if($model->save()){

         

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

            $identity->setId($model->id);

            $identity->errorCode = UserIdentity::ERROR_NONE;

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

            

            $this->redirect(array('/company/mycompany'));      

        }

        

            }

        

               

        } 

         

              $this->render('accept',array(

            'model'=>$model,

        ));

    }






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

thanks

JMB