Way to redirect login page if user not login
<p>I want to redirect user to login page if he is not logged on page. But i have actionLogin in my  registrationController</p>
<p>So when I use in my common/main:</p>
<pre><code>'as beforeRequest' =&gt; [  //if guest user access site so, redirect to login page.
    'class' =&gt; 'yii\filters\AccessControl',
    'rules' =&gt; [
        [
            'actions' =&gt; ['login', 'error'],
            'allow' =&gt; true,
        ],
        [
            'allow' =&gt; true,
            'roles' =&gt; ['@'],
        ],
    ],
],
</code></pre>
<p>It always redirect me to <code>index.php?r=site%2Flogin</code></p>
<p>Is it possible to change main login redirect to <code>index.php?r=registration%2Flogin</code>?</p>
<p>If it possible where I should overwrite code or change something..</p>
<p><code>'user' =&gt; [ 'loginUrl' =&gt; ['registration/login'], ],</code></p>
<p>resolve problem but when I want to go to registration/index to signup user it redirect me to registration/login.</p>
<p>Is it possible to rule out this url from being enforced? I Want to make <code>index.php?r=registration</code> the only available path.</p>
<p>And here is my facebook login; I want to enable this too</p>
<pre><code>public function oAuthSuccess($client) {
        // get user data from client
        $userAttributes = $client-&gt;getUserAttributes();

        $user = User::find()-&gt;where(['Email' =&gt; $userAttributes['email']])-&gt;one();

        if (!$user) {
            $newuser = New SignupForm();
            $newuser-&gt;oAuthSuccess($client);
            $user = User::find()-&gt;where(['Email' =&gt; $userAttributes['email']])-&gt;one();
            if ($newuser-&gt;validate() &amp;&amp; Yii::$app-&gt;getUser()-&gt;login($user)) {
                Yii::$app-&gt;session-&gt;setFlash('success', Yii::t('app', 'Udało się poprawnie zalogować. Prosimy dokonać zmian w ustawianiach profilu.'));
                return $this-&gt;redirect('index.php?r=content/news');
                }
        }
        
        Yii::$app-&gt;user-&gt;login($user);
    }
</code></pre>