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.
Ok, seems like I’m answering my own question…
Turns out that
$this->redirect(array('view','id'=>$model->id));was not letting the login happen for some obscure reason… I can’t answer to that since I started learning yii yesterday, but would appreciate if anyone with the knowledge could justify it.So the solution is just remove the redirect and we got a user logged in user right after the account creation.
Thank you for trying to help John and Jay =)