{ $ret = $this->student->validate(); if (!$ret) { $this->addErrors($this->student->getErrors()); } } public function save() { //start a transaction $transaction = Yii::app()->db->beginTransaction(); try { if ($this->user->isNewRecord) { $this->user->is_verified = 0; $verification = new UserVerification(); } //try to save the data to db $ret = parent::save(); if ($ret) { $ret = $this->student->save(true, null, $this->user); if (isset($verification)) { Yii::log("Verification is set"); $verification->user_id = $this->user->user_id; $this->hash = $verification->generateHash(); if (!$verification->save()) { throw new Exception(); } if (!Emailer::emailStudentActivation($this->user, $this->hash)) { throw new Exception(); } } } $transaction->commit(); //Yii::app()->user->setFlash('success',sprintf(Constants::SUCCESS_SURVEY_SUBMITTED,$model->getSurvey()->title)); return $ret; } catch (Exception $e) {
public function actionSendActivation($user_id) { /** @var $user User */ /** @var $uv UserVerification */ $user = User::model()->findByPk($user_id); switch ($user->user_group_id) { case Student::USER_GROUP_ID: $uv = UserVerification::model()->findByPk($user_id); if (!empty($uv)) { $mailed = Emailer::emailStudentActivation($user, $uv->hash); } break; case Employer::USER_GROUP_ID: $mailed = Emailer::emailEmployerVerified($user); break; default: throw new CHttpException(404, 'Invalid user group.'); } if (isset($mailed) && $mailed) { Yii::app()->user->setFlash('success', 'Activation Email sent to ' . CHtml::tag('strong', array(), $user->email)); } else { Yii::app()->user->setFlash('error', 'Error occurred while sending email to ' . CHtml::tag('strong', array(), $user->email)); } $this->redirect(array('admin')); }