/** * @throws CHttpException */ public function run() { if (false === Yii::app()->getUser()->getIsGuest()) { $this->getController()->redirect(\yupe\helpers\Url::redirectUrl(Yii::app()->getModule('user')->loginSuccess)); } $module = Yii::app()->getModule('user'); if ($module->registrationDisabled) { throw new CHttpException(404, Yii::t('UserModule.user', 'requested page was not found!')); } $form = new RegistrationForm(); if (($data = Yii::app()->getRequest()->getPost('RegistrationForm')) !== null) { $form->setAttributes($data); if ($form->validate()) { if ($user = Yii::app()->userManager->createUser($form)) { if (!$module->emailAccountVerification) { $this->autoLoginUser($form); } Yii::app()->getUser()->setFlash(yupe\widgets\YFlashMessages::SUCCESS_MESSAGE, Yii::t('UserModule.user', 'Account was created! Check your email!')); $this->getController()->redirect(Url::redirectUrl($module->registrationSuccess)); } Yii::app()->getUser()->setFlash(yupe\widgets\YFlashMessages::ERROR_MESSAGE, Yii::t('UserModule.user', 'Error creating account!')); } } $this->getController()->render('registration', ['model' => $form, 'module' => $module]); }
public function run() { if (Yii::app()->user->isAuthenticated()) { $this->controller->redirect(Yii::app()->user->returnUrl); } $module = Yii::app()->getModule('user'); if ($module->registrationDisabled) { throw new CHttpException(404, Yii::t('UserModule.user', 'requested page was not found!')); } $form = new RegistrationForm(); $event = new CModelEvent($this->controller, array("registrationForm" => $form)); $module->onBeginRegistration($event); if (($data = Yii::app()->getRequest()->getPost('RegistrationForm')) !== null) { $form->setAttributes($data); if ($form->validate()) { if ($user = Yii::app()->userManager->createUser($form)) { Yii::app()->user->setFlash(yupe\widgets\YFlashMessages::SUCCESS_MESSAGE, Yii::t('UserModule.user', 'Account was created! Check your email!')); $module->onSuccessRegistration(new CModelEvent($this->controller, array("user" => $user))); $this->controller->redirect(array($module->registrationSuccess)); } $module->onErrorRegistration(new CModelEvent($this->controller, array("registrationForm" => $form))); Yii::app()->user->setFlash(yupe\widgets\YFlashMessages::ERROR_MESSAGE, Yii::t('UserModule.user', 'Error creating account!')); } $module->onErrorRegistration(new CModelEvent($this->controller, array("registrationForm" => $form))); } $this->controller->render('registration', array('model' => $form, 'module' => $module)); }
public function run() { $form = new RegistrationForm(); if (Yii::app()->request->isPostRequest && !empty($_POST['RegistrationForm'])) { $module = Yii::app()->getModule('user'); $form->setAttributes($_POST['RegistrationForm']); // проверка по "черным спискам" // проверить на email if (!$module->isAllowedEmail($form->email)) { // перенаправить на экшн для фиксации невалидных email-адресов $this->controller->redirect(array(Yii::app()->getModule('user')->invalidEmailAction)); } if (!$module->isAllowedIp(Yii::app()->request->userHostAddress)) { // перенаправить на экшн для фиксации невалидных ip-адресов $this->controller->redirect(array(Yii::app()->getModule('user')->invalidIpAction)); } if ($form->validate()) { // если требуется активация по email if ($module->emailAccountVerification) { $registration = new Registration(); // скопируем данные формы $registration->setAttributes($form->getAttributes()); if ($registration->save()) { // отправка email с просьбой активировать аккаунт $mailBody = $this->controller->renderPartial('application.modules.user.views.email.needAccountActivationEmail', array('model' => $registration), true); Yii::app()->mail->send($module->notifyEmailFrom, $registration->email, Yii::t('user', 'Регистрация на сайте {site} !', array('{site}' => Yii::app()->name)), $mailBody); // запись в лог о создании учетной записи Yii::log(Yii::t('user', "Создана учетная запись {nick_name}!", array('{nick_name}' => $registration->nick_name)), CLogger::LEVEL_INFO, UserModule::$logCategory); Yii::app()->user->setFlash(YFlashMessages::NOTICE_MESSAGE, Yii::t('user', 'Учетная запись создана! Инструкции по активации аккаунта отправлены Вам на email!')); $this->controller->refresh(); } else { $form->addErrors($registration->getErrors()); Yii::log(Yii::t('user', "Ошибка при создании учетной записи!"), CLogger::LEVEL_ERROR, UserModule::$logCategory); } } else { // если активации не требуется - сразу создаем аккаунт $user = new User(); $user->createAccount($form->nick_name, $form->email, $form->password); if ($user && !$user->hasErrors()) { Yii::log(Yii::t('user', "Создана учетная запись {nick_name} без активации!", array('{nick_name}' => $user->nick_name)), CLogger::LEVEL_INFO, UserModule::$logCategory); // отправить email с сообщением о успешной регистрации $emailBody = $this->controller->renderPartial('application.modules.user.views.email.accountCreatedEmail', array('model' => $user), true); Yii::app()->mail->send($module->notifyEmailFrom, $user->email, Yii::t('user', 'Регистрация на сайте {site} !', array('{site}' => Yii::app()->name)), $emailBody); Yii::app()->user->setFlash(YFlashMessages::NOTICE_MESSAGE, Yii::t('user', 'Учетная запись создана! Пожалуйста, авторизуйтесь!')); $this->controller->redirect(array('/user/account/login/')); } else { $form->addErrors($user->getErrors()); Yii::log(Yii::t('user', "Ошибка при создании учетной записи без активации!"), CLogger::LEVEL_ERROR, UserModule::$logCategory); } } } } $this->controller->render('registration', array('model' => $form)); }
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]); }
public function actionPromo($cat = null) { $link = ''; Yii::import('application.modules.user.forms.*'); $model = new \RegistrationForm('promoReg'); $category = \StoreCategory::model()->findByPk($cat); if ($category) { $link = '/store' . \Product::model()->linkBuilder($category, $link); } else { $link = '#'; } if (Yii::app()->getRequest()->getPost('RegistrationForm')) { $model->setAttributes(Yii::app()->getRequest()->getPost('RegistrationForm')); if ($model->validate()) { if ($user = Yii::app()->userManager->createUser($model)) { \Yii::app()->getUser()->setFlash(\yupe\widgets\YFlashMessages::SUCCESS_MESSAGE, \Yii::t('UserModule.user', 'Аккаунт создан! Проверьте свой email!')); Yii::app()->session['success_reg'] = true; } $this->redirect('/site/index'); } } $this->layout = 'promo'; $this->render('promo', ['category' => $category, 'link' => $link, 'model' => $model]); }