/** * @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]); }
/** * Activates a new user's account * @param mixed $id The activation key */ public function actionActivation($id = NULL) { $this->layout = '//layouts/main'; $this->setPageTitle(Yii::t('ciims.controllers.Site', '{{app_name}} | {{label}}', array('{{app_name}}' => Cii::getConfig('name', Yii::app()->name), '{{label}}' => Yii::t('ciims.controllers.Site', 'Activate Your Account')))); $model = new ActivationForm(); $model->activationKey = $id; if (!$model->validateKey()) { throw new CHttpException(403, Yii::t('ciims.models.ActivationForm', 'The activation key you provided is invalid.')); } if (Cii::get($_POST, 'ActivationForm', false)) { $model->attributes = $_POST['ActivationForm']; if ($model->save()) { Yii::app()->user->setFlash('success', Yii::t('ciims.controllers.Site', 'Your account has successfully been activated. You may now login')); $this->redirect($this->createUrl('site/login')); } } $this->render('activation', array('model' => $model)); }