Exemplo n.º 1
0
 /**
  * @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]);
 }
Exemplo n.º 2
0
 public function run()
 {
     if (Yii::app()->user->isAuthenticated()) {
         $this->controller->redirect(Url::redirectUrl(Yii::app()->getUser()->getReturnUrl()));
     }
     /**
      * Если было совершено больше 3х попыток входа
      * в систему, используем сценарий с капчей:
      **/
     $badLoginCount = Yii::app()->authenticationManager->getBadLoginCount(Yii::app()->getUser());
     $module = Yii::app()->getModule('user');
     $scenario = $badLoginCount > (int) $module->badLoginCount ? LoginForm::LOGIN_LIMIT_SCENARIO : '';
     $form = new LoginForm($scenario);
     if (Yii::app()->getRequest()->getIsPostRequest() && !empty($_POST['LoginForm'])) {
         $form->setAttributes(Yii::app()->getRequest()->getPost('LoginForm'));
         if ($form->validate() && Yii::app()->authenticationManager->login($form, Yii::app()->getUser(), Yii::app()->getRequest())) {
             Yii::app()->user->setFlash(yupe\widgets\YFlashMessages::SUCCESS_MESSAGE, Yii::t('UserModule.user', 'You authorized successfully!'));
             if (Yii::app()->getUser()->isSuperUser() && $module->loginAdminSuccess) {
                 $redirect = $module->loginAdminSuccess;
             } else {
                 $redirect = empty($module->loginSuccess) ? Yii::app()->getBaseUrl() : $module->loginSuccess;
             }
             $redirect = Yii::app()->getUser()->getReturnUrl($redirect);
             Yii::app()->authenticationManager->setBadLoginCount(Yii::app()->getUser(), 0);
             $this->controller->redirect(Url::redirectUrl($redirect));
         } else {
             $form->addError('email', Yii::t('UserModule.user', 'Email or password was typed wrong!'));
             Yii::app()->authenticationManager->setBadLoginCount(Yii::app()->getUser(), $badLoginCount + 1);
         }
     }
     $this->controller->render($this->id, array('model' => $form));
 }
Exemplo n.º 3
0
 /**
  *
  */
 public function run()
 {
     $module = Yii::app()->getModule('user');
     if (false === Yii::app()->getUser()->getIsGuest()) {
         $this->getController()->redirect(\yupe\helpers\Url::redirectUrl($module->loginSuccess));
     }
     $badLoginCount = Yii::app()->authenticationManager->getBadLoginCount(Yii::app()->getUser());
     $scenario = $badLoginCount >= (int) $module->badLoginCount ? LoginForm::LOGIN_LIMIT_SCENARIO : '';
     $form = new LoginForm($scenario);
     if (Yii::app()->getRequest()->getIsPostRequest() && !empty($_POST['LoginForm'])) {
         $form->setAttributes(Yii::app()->getRequest()->getPost('LoginForm'));
         if (Yii::app()->authenticationManager->login($form, Yii::app()->getUser(), Yii::app()->getRequest())) {
             Yii::app()->getUser()->setFlash(yupe\widgets\YFlashMessages::SUCCESS_MESSAGE, Yii::t('UserModule.user', 'You authorized successfully!'));
             if (Yii::app()->getUser()->isSuperUser() && $module->loginAdminSuccess) {
                 $redirect = [$module->loginAdminSuccess];
             } else {
                 $redirect = empty($module->loginSuccess) ? Yii::app()->getBaseUrl() : [$module->loginSuccess];
             }
             $redirect = Yii::app()->getUser()->getReturnUrl($redirect);
             Yii::app()->authenticationManager->setBadLoginCount(Yii::app()->getUser(), 0);
             $this->getController()->redirect($redirect);
         } else {
             $form->addError('email', Yii::t('UserModule.user', 'Email or password was typed wrong!'));
             Yii::app()->authenticationManager->setBadLoginCount(Yii::app()->getUser(), $badLoginCount + 1);
         }
     }
     $this->getController()->render($this->id, ['model' => $form]);
 }
Exemplo n.º 4
0
 /**
  * @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->recoveryDisabled) {
         throw new CHttpException(404, Yii::t('UserModule.user', 'requested page was not found!'));
     }
     // Новая форма восстановления пароля:
     $form = new RecoveryForm();
     if (($data = Yii::app()->getRequest()->getPost('RecoveryForm')) !== null) {
         $form->setAttributes($data);
         if ($form->validate()) {
             if (Yii::app()->userManager->passwordRecovery($form->email)) {
                 Yii::app()->getUser()->setFlash(YFlashMessages::SUCCESS_MESSAGE, Yii::t('UserModule.user', 'Letter with password recovery instructions was sent on email which you choose during register'));
                 $this->getController()->redirect(['/user/account/login']);
             }
             Yii::app()->getUser()->setFlash(YFlashMessages::ERROR_MESSAGE, Yii::t('UserModule.user', 'Password recovery error.'));
             $this->getController()->redirect(['/user/account/recovery']);
         }
     }
     $this->getController()->render('recovery', ['model' => $form]);
 }
Exemplo n.º 5
0
 /**
  *
  */
 public function run()
 {
     if (Yii::app()->getUser()->getIsGuest()) {
         $this->getController()->redirect(['/user/account/login']);
     }
     Yii::app()->authenticationManager->logout(Yii::app()->getUser());
     $this->getController()->redirect(Url::redirectUrl(Yii::app()->getModule('user')->logoutSuccess));
 }
Exemplo n.º 6
0
 public function run()
 {
     $module = Yii::app()->getModule('user');
     $user = Yii::app()->getUser();
     $isSuperUser = $user->isSuperUser();
     Yii::app()->authenticationManager->logout($user);
     if ($isSuperUser && $module->logoutAdminSuccess) {
         $redirect = $module->logoutAdminSuccess;
     } else {
         $redirect = empty($module->logoutSuccess) ? Yii::app()->baseUrl : $module->logoutSuccess;
     }
     $this->getController()->redirect(Url::redirectUrl($redirect));
 }
Exemplo n.º 7
0
 public function run($token)
 {
     $module = Yii::app()->getModule('user');
     // Пытаемся найти пользователя по токену,
     // в противном случае - ошибка:
     if (Yii::app()->userManager->activateUser($token)) {
         // Сообщаем пользователю:
         Yii::app()->getUser()->setFlash(yupe\widgets\YFlashMessages::SUCCESS_MESSAGE, Yii::t('UserModule.user', 'Аккаунт успешно активирован!'));
         // Выполняем переадресацию на соответствующую страницу:
         $this->getController()->redirect(Url::redirectUrl($module->accountActivationSuccess));
     }
     // Сообщаем об ошибке:
     Yii::app()->getUser()->setFlash(yupe\widgets\YFlashMessages::ERROR_MESSAGE, Yii::t('UserModule.user', 'There was a problem with the activation of the account. Please refer to the site\'s administration.'));
     // Переадресовываем на соответствующую ошибку:
     $this->getController()->redirect(Url::redirectUrl($module->accountActivationFailure));
 }
Exemplo n.º 8
0
 /**
  * @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]);
 }
Exemplo n.º 9
0
 public function run()
 {
     $module = Yii::app()->getModule('user');
     if (Yii::app()->getUser()->isAuthenticated()) {
         $this->controller->redirect(Yii::app()->getUser()->getReturnUrl());
     }
     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)) {
                 Yii::app()->user->setFlash(yupe\widgets\YFlashMessages::SUCCESS_MESSAGE, Yii::t('UserModule.user', 'Account was created! Check your email!'));
                 $this->controller->redirect(Url::redirectUrl($module->registrationSuccess));
             }
             Yii::app()->user->setFlash(yupe\widgets\YFlashMessages::ERROR_MESSAGE, Yii::t('UserModule.user', 'Error creating account!'));
         }
     }
     $this->controller->render('registration', array('model' => $form, 'module' => $module));
 }
Exemplo n.º 10
0
 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]);
 }
Exemplo n.º 11
0
 public function run()
 {
     Yii::app()->authenticationManager->logout(Yii::app()->getUser());
     $this->getController()->redirect(Url::redirectUrl(Yii::app()->getModule('user')->logoutSuccess));
 }