R
R
romany42014-06-07 10:59:40
Yii
romany4, 2014-06-07 10:59:40

Yii2. Redirect user to previous page after authorization

There is a main controller from which all others will inherit. The controller code has the following:

public function init()
    {
        $this->on('beforeAction', function ($event) {
            ...
            // запоминаем страницу неавторизованного пользователя, чтобы потом отредиректить его обратно с помощью  goBack()
            if (Yii::$app->getUser()->isGuest) {
                $request = Yii::$app->getRequest();
                // исключаем страницу авторизации или ajax-запросы
                if (!($request->getIsAjax() || strpos($request->getUrl(), 'login') !== false)) {
                   Yii::$app->getUser()->setReturnUrl($request->getUrl());
                  }
               }
            }
            ...
        });
    }

For all pages this works correctly, except for pages with captcha. For captcha pages, the redirect goes to something like /captcha/?v=xxxxxxxxxxxxxx
If you pledge the Yii::$app->getRequest() object, it turns out that for pages with captcha it is called twice. For the first time, just the object I need, the second time - the object with captcha.
With the help of yii2 tools, is it possible to solve this issue, namely, to receive the request I need? (is it possible to somehow remove the request for captcha?)

Answer the question

In order to leave comments, you need to log in

1 answer(s)
A
Alexander Makarov, 2014-06-07
@SamDark

Do not write setReturnUrl for /captcha/?v=xxxxxxxxxxxxxx.

Didn't find what you were looking for?

Ask your question

Ask a Question

731 491 924 answers to any question