getCurrent() public static method

public static getCurrent ( ) : static
return static
Example #1
0
 /**
  * Запрос пришел на валидацию ajax формы?
  * @return bool
  */
 public function isRequestOnValidateAjaxForm()
 {
     if (\Yii::$app->request->isAjax && !\Yii::$app->request->isPjax && UrlHelper::getCurrent()->issetSystemParam(static::VALIDATION_AJAX_FORM_SYSTEM_NAME)) {
         return true;
     }
     return false;
 }
Example #2
0
 /**
  * @return static
  */
 public function run()
 {
     Yii::$app->user->logout();
     if ($ref = UrlHelper::getCurrent()->getRef()) {
         return Yii::$app->getResponse()->redirect($ref);
     } else {
         return Yii::$app->getResponse()->redirect(Yii::$app->getUser()->getReturnUrl());
     }
 }
Example #3
0
 /**
  * Восстановлеине пароля
  * @return string|Response
  */
 public function actionRegister()
 {
     if (!\Yii::$app->user->isGuest) {
         return $this->goHome();
     }
     $rr = new RequestResponse();
     $model = new SignupForm();
     $model->scenario = SignupForm::SCENARION_FULLINFO;
     //Запрос на валидацию ajax формы
     if ($rr->isRequestOnValidateAjaxForm()) {
         return $rr->ajaxValidateForm($model);
     }
     //Запрос ajax post
     if ($rr->isRequestAjaxPost()) {
         if ($model->load(\Yii::$app->request->post()) && ($registeredUser = $model->signup())) {
             $rr->success = true;
             $rr->message = 'Вы успешно зарегистрированны';
             \Yii::$app->user->login($registeredUser, 0);
             return $this->redirect($registeredUser->getPageUrl());
         } else {
             $rr->message = 'Не удалось зарегистрироваться';
         }
         return (array) $rr;
     } else {
         if (\Yii::$app->request->isPost) {
             if ($model->load(\Yii::$app->request->post()) && $model->sendEmail()) {
                 if ($ref = UrlHelper::getCurrent()->getRef()) {
                     return $this->redirect($ref);
                 } else {
                     return $this->goBack();
                 }
             }
         }
     }
     return $this->render('register', ['model' => $model]);
 }
Example #4
0
 public function actionAuth()
 {
     $this->view->title = \Yii::t('app', 'Authorization');
     $this->layout = '@skeeks/cms/modules/admin/views/layouts/unauthorized.php';
     $goUrl = "";
     $loginModel = new LoginFormUsernameOrEmail();
     $passwordResetModel = new PasswordResetRequestFormEmailOrLogin();
     if ($ref = UrlHelper::getCurrent()->getRef()) {
         $goUrl = $ref;
     }
     $rr = new RequestResponse();
     if (!\Yii::$app->user->isGuest) {
         return $goUrl ? $this->redirect($goUrl) : $this->goHome();
     }
     //Авторизация
     if (\Yii::$app->request->post('do') == 'login') {
         if ($rr->isRequestOnValidateAjaxForm()) {
             return $rr->ajaxValidateForm($loginModel);
         }
         if ($rr->isRequestAjaxPost()) {
             if ($loginModel->load(\Yii::$app->request->post()) && $loginModel->login()) {
                 if (!$goUrl) {
                     $goUrl = Yii::$app->getUser()->getReturnUrl($defaultUrl);
                 }
                 $rr->redirect = $goUrl;
                 $rr->success = true;
                 $rr->message = "";
                 $rr->message = "";
                 return (array) $rr;
             } else {
                 $rr->success = false;
                 $rr->message = \Yii::t('app', "Unsuccessful attempt authorization");
                 return (array) $rr;
             }
         }
     }
     //Запрос на сброс пароля
     if (\Yii::$app->request->post('do') == 'password-reset') {
         if ($rr->isRequestOnValidateAjaxForm()) {
             return $rr->ajaxValidateForm($passwordResetModel);
         }
         if ($rr->isRequestAjaxPost()) {
             if ($passwordResetModel->load(\Yii::$app->request->post()) && $passwordResetModel->sendEmail()) {
                 $rr->success = true;
                 $rr->message = \Yii::t('app', "Check your email address");
                 return (array) $rr;
             } else {
                 $rr->success = false;
                 $rr->message = \Yii::t('app', "Failed send email");
                 return (array) $rr;
             }
         }
     }
     return $this->render('auth', ['loginModel' => $loginModel, 'passwordResetModel' => $passwordResetModel, 'goUrl' => $goUrl]);
 }