/**
  * @param $promo string     Промо код, присылаемый по Email
  *
  * @throws CHttpException
  */
 public function run($promo)
 {
     $module = Yii::app()->getModule('user');
     if ($module->registrationDisabled) {
         throw new CHttpException(404, Yii::t('UserModule.user', 'requested page was not found!'));
     }
     $user = User::getUserByPromo($promo);
     if (!$user) {
         throw new CHttpException(400, Yii::t('UserModule.user', '<h1>Bad promo code!</h1>'));
     }
     /* Повторное подтверждение  */
     if ($user->email_confirm) {
         $this->getController()->redirect(Url::redirectUrl('/cabinet'));
     }
     $form = new ActivationForm('default');
     $form->prefphone = $user->contact_phone_prefix ? $user->contact_phone_prefix : '+7';
     $form->oldphone = $form->prefphone . " " . $user->contact_phone;
     if (($data = Yii::app()->getRequest()->getPost('ActivationForm')) !== null) {
         $form->setAttributes($data);
         if ($form->validate()) {
             if ($this->saveDataAndSendEmail($user, $form)) {
                 $paramModel = Yii::app()->request->getParam('model', null);
                 $paramExternalId = Yii::app()->request->getParam('external_id', null);
                 if (!is_null($paramModel) && !is_null($paramExternalId)) {
                     $Response = Response::createResponseByOtherModelData($paramModel, $paramExternalId);
                     if (!is_null($Response)) {
                         if ($Response->save()) {
                             $this->getController()->render('successRegister', ['model' => $paramModel, 'external_id' => $paramExternalId, 'response_id' => $Response->primaryKey]);
                             Yii::app()->end();
                         } else {
                             Yii::app()->getUser()->setFlash(yupe\widgets\YFlashMessages::ERROR_MESSAGE, Yii::t('default', 'Ошибка создания заказа, errmsgcreate', ['errmsgcreate' => print_r($Response->getErrors(), true)]));
                         }
                     } else {
                         Yii::app()->getUser()->setFlash(yupe\widgets\YFlashMessages::ERROR_MESSAGE, Yii::t('default', 'Ошибка создания заказа, errmsgcreate', ['errmsgcreate' => "Can't create Response by createResponseByOtherModelData"]));
                     }
                 } else {
                     Yii::app()->getUser()->setFlash(yupe\widgets\YFlashMessages::SUCCESS_MESSAGE, Yii::t('UserModule.user', 'Аккаунт создан! По указаному адресу email Вам отправлена сслыка для активации Вашего "Личного кабинета"!'));
                     //                        Yii::app()->session['success_reg'] = true;
                     $this->getController()->redirect(Url::redirectUrl('/cabinet'));
                 }
             }
             Yii::app()->getUser()->setFlash(yupe\widgets\YFlashMessages::ERROR_MESSAGE, Yii::t('UserModule.user', 'Не удалось !'));
         }
     }
     $this->getController()->render('activation', ['model' => $form, 'module' => $module, 'user' => $user]);
 }
 public function run()
 {
     if (!in_array($this->model, $this->_aproveModels)) {
         Yii::log("ResponseWidget run unapproved model=[{$this->model}]", "info");
         return;
     }
     $view = 'index';
     if (isset($_POST['model'])) {
         //            $Response = new Response;
         //            $Response->model = $this->model;
         //            $Response->external_id = $this->external_id;
         //            $Response->from_company_id = Yii::app()->user->getProfile()->company_id;
         //            $model = new $this->model;
         //            $Response->to_company_id = $model->findByPk($this->external_id)->user->company_id;
         //            $text = trim( Yii::app()->request->getParam('text' , '') );
         //            if ( 0 == mb_strlen( $text ) ) {
         //                $text = Yii::t('default', 'first response message');
         //            }
         //            $Response->text = $text;
         $Response = Response::createResponseByOtherModelData($this->model, $this->external_id);
         if (!is_null($Response)) {
             if ($Response->hasErrors()) {
                 echo CJSON::encode(['status' => 'error', 'data' => print_r($Response->getErrors(), true)]);
             } else {
                 if ($Response->save()) {
                     //                        $user = User::model()->findBySql("company_id=:company_id",array("company_id"=>$modelCompanyId));
                     //print_r($user);exit();
                     $view = 'success';
                     echo CJSON::encode(['status' => 'success', 'data' => '/response/' . $Response->primaryKey]);
                 } else {
                     echo CJSON::encode(['status' => 'error', 'data' => print_r($Response->getErrors(), true)]);
                 }
             }
         } else {
             echo CJSON::encode(['status' => 'error', 'data' => "Can't create Response by createResponseByOtherModelData"]);
         }
         Yii::app()->end();
     }
     $model = $this->model;
     $myCompanyId = !Yii::app()->user->isGuest ? Yii::app()->user->getProfile()->company_id : '';
     $modelObj = $model::model()->findByPk($this->external_id);
     $modelCompanyId = $modelObj->user->company_id;
     $this->render($view, ['model' => $this->model, 'external_id' => $this->external_id, 'isShow' => $this->isShowCreateResponseButton(), 'myCompanyId' => $myCompanyId, 'modelCompanyId' => $modelCompanyId]);
 }
 public function run()
 {
     $module = Yii::app()->getModule('user');
     if ($module->registrationDisabled) {
         throw new CHttpException(404, Yii::t('UserModule.user', 'requested page was not found!'));
     }
     $form = new RegistrationForm('default');
     if (($data = Yii::app()->getRequest()->getPost('RegistrationForm')) !== null) {
         $form->setAttributes($data);
         if ($form->validate()) {
             if ($user = Yii::app()->userManager->createUser($form)) {
                 $paramModel = Yii::app()->request->getParam('model', null);
                 $paramExternalId = Yii::app()->request->getParam('external_id', null);
                 if (!is_null($paramModel) && !is_null($paramExternalId)) {
                     $Response = Response::createResponseByOtherModelData($paramModel, $paramExternalId);
                     if (!is_null($Response)) {
                         if ($Response->save()) {
                             $this->getController()->render('successRegister', ['model' => $paramModel, 'external_id' => $paramExternalId, 'response_id' => $Response->primaryKey]);
                             Yii::app()->end();
                         } else {
                             Yii::app()->getUser()->setFlash(yupe\widgets\YFlashMessages::ERROR_MESSAGE, Yii::t('default', 'Ошибка создания заказа, errmsgcreate', ['errmsgcreate' => print_r($Response->getErrors(), true)]));
                         }
                     } else {
                         Yii::app()->getUser()->setFlash(yupe\widgets\YFlashMessages::ERROR_MESSAGE, Yii::t('default', 'Ошибка создания заказа, errmsgcreate', ['errmsgcreate' => "Can't create Response by createResponseByOtherModelData"]));
                     }
                 } else {
                     //								Yii::app()->authenticationManager->logout(Yii::app()->getUser());
                     Yii::app()->user->setFlash(yupe\widgets\YFlashMessages::SUCCESS_MESSAGE, Yii::t('UserModule.user', 'Аккаунт создан! По указаному адресу email Вам отправлена сслыка для активации Вашего "Личного кабинета"!'));
                     Yii::app()->session['success_reg'] = true;
                     $this->getController()->redirect(Url::redirectUrl('/cabinet'));
                 }
             }
             Yii::app()->getUser()->setFlash(yupe\widgets\YFlashMessages::ERROR_MESSAGE, Yii::t('UserModule.user', 'Не удалось зарегистрировать!'));
         }
     }
     $form->prefphone = '+7';
     $this->getController()->render('registration', ['model' => $form, 'module' => $module]);
 }