Im not sure how can I login a user right after hes creation using yii framework.

In UserController I created the actionRegister in order to allow a user to create a new acccount, here if the user is successfully saved to db I would like to preform the login for this user aswell. Heres my code:

```
    public function actionRegister()
    {
        $model=new User;

        if(isset($_POST['User']))
        {
            $model->attributes=$_POST['User'];

            if($model->save()){            

                $identity=new UserIdentity($model->email,$model->password);
                $identity->authenticate();
                Yii::app()->user->login($identity);

                $this->redirect(array('view','id'=>$model->id));                
            }
        }
        $this->render('register',array('model'=>$model));
    }

```

Thank you in advance for any help u can give me in this matter.