public function actionJoin() { // Auth users shouldn't be able to register if (!Yii::app()->user->isGuest) { $this->redirect($this->createUrl('timeline/index')); } $form = new JoinForm(); if (isset($_POST['JoinForm'])) { $form->attributes = $_POST['JoinForm']; // Attempt to save user's info if ($form->save()) { // Try to automagically log the user in, if we fail // trough just redirect them to the login page $model = new LoginForm(); $model->attributes = array('username' => $form->email, 'password' => $form->password); if ($model->login()) { // Set a success flash Yii::app()->user->setFlash('success', 'You successfully registered an account'); $this->redirect($this->createUrl('timeline/index')); } else { $this->redirect($this->createUrl('site/index')); } } } $this->render('join', array('user' => $form)); }