/** * Creates a new model. * If creation is successful, the browser will be redirected to the 'view' page. */ public function actionCreate() { if (Yii::app()->user->checkAccess('createValidations')) { $model = new Validations(); $cases = Cases::model()->findByPk($_GET['owner']); $returnMessage = null; if (isset($_POST['Validations'])) { $model->attributes = $_POST['Validations']; if ($model->save()) { // Guardar log $attributes = array('log_date' => date("Y-m-d G:i:s"), 'log_activity' => 'ValidationCreated', 'log_resourceid' => $model->case_id, 'log_type' => Logs::LOG_CREATED, 'user_id' => Yii::app()->user->id, 'module_id' => 'cases', 'project_id' => $model->Cases->project_id); Logs::model()->saveLog($attributes); //$this->redirect(Yii::app()->createUrl('secuences/create', array('owner'=>$cases->case_id))); $returnMessage = "Validation was succefully created."; $model = new Validations(); } } $this->render('create', array('model' => $model, 'cases' => $cases, 'returnMessage' => $returnMessage)); } else { throw new CHttpException(403, Yii::t('site', '403_Error')); } }
public function actionPassRequest() { if (!isset($_POST['PassRequestForm'])) { //new request $requestForm = new PassRequestForm(); $this->render('passrequest', array('model' => $requestForm)); } else { //requst form has been filled $requestForm = new PassRequestForm(); $requestForm->attributes = $_POST['PassRequestForm']; if (!$requestForm->validate()) { yii::app()->user->setFlash('error', Yii::t('AuthModule.main', 'Restore form validation failed')); $this->render('passrequest', array('model' => $requestForm)); return; } //for is correct so, prepare and send request email $email = $_POST['PassRequestForm']['email']; //create new guid and sent it to user $guid = AuthCommon::getGUID(); $userModel = new Users(); $user = $userModel->getByEmail($email); if ($user == null) { yii::app()->user->setFlash('warning', sprintf(Yii::t('AuthModule.main', 'Email address was not found'), $email)); $this->redirect(array('user/passrequest')); return; } $user_id = $user->id; $validations = new Validations(); $validations->guid = $guid; $validations->user_id = $user_id; $validations->email = $email; $validations->type = self::VALIDATOR_RESTORE; $date = new DateTime(); $date->modify("+24 hours"); $exp_time = $date->format(AuthCommon::getParam('dateFormat')); $validations->exp_datetime = $exp_time; $validations->comments = 'Restore user password'; if (!$validations->validate()) { yii::app()->user->setFlash('error', Yii::t('AuthModule.main', 'Password restore not complited')); $this->render('passrequest', array('model' => $requestForm)); return; } if (!$validations->save()) { yii::app()->user->setFlash('error', Yii::t('AuthModule.main', 'Password restore not complited')); $this->render('passrequest', array('model' => $requestForm)); return; } //send email with restore link if (!$requestForm->validate()) { yii::app()->user->setFlash('error', Yii::t('AuthModule.main', 'Restore form validation failed')); $this->render('passrequest', array('model' => $requestForm)); return; } $result = AuthCommon::sendPassRequestEmail($email, $guid, $user->username); if ($result) { Yii::app()->user->setFlash('success', sprintf(Yii::t('AuthModule.main', 'Password restore link has been sent'), $email)); $this->redirect(array('user/passchange')); } else { Yii::app()->user->setFlash('error', Yii::t('AuthModule.main', 'Error sending email message')); $this->redirect(array('user/passrequest')); } } }