Redirect 如果用户未登录,则重定向登录页面的方法

Redirect 如果用户未登录,则重定向登录页面的方法,redirect,yii2,logged,Redirect,Yii2,Logged,我想重定向用户到登录页面,若他并没有登录页面。但我的账户上有actionLogin 注册控制器 因此,当我在我的common/main中使用时: 'as beforeRequest' => [ //if guest user access site so, redirect to login page. 'class' => 'yii\filters\AccessControl', 'rules' => [ [ 'act

我想重定向用户到登录页面,若他并没有登录页面。但我的账户上有actionLogin

注册控制器

因此,当我在我的common/main中使用时:

'as beforeRequest' => [  //if guest user access site so, redirect to login page.
    'class' => 'yii\filters\AccessControl',
    'rules' => [
        [
            'actions' => ['login', 'error'],
            'allow' => true,
        ],
        [
            'allow' => true,
            'roles' => ['@'],
        ],
    ],
],
它总是把我引向

index.php?r=站点%2Flogin

可以将主登录重定向更改为

index.php?r=注册%2f登录

如果可能的话,我应该在哪里重写代码或更改某些内容。。 !编辑 嗯

'用户'=>['登录'=>['注册/登录'],]

解决问题,但当我想去注册/索引注册用户时,它会将我重定向到注册/登录。可以排除强制执行此url。我想提出:

php?r=注册

唯一可用的路径

这是我的facebook登录,我也要启用它

public function oAuthSuccess($client) {
        // get user data from client
        $userAttributes = $client->getUserAttributes();

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

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

        Yii::$app->user->login($user);
    }

在您的
app/config/web.php
(用于基本模板)或
app/frontend/config/main.php
(用于高级模板)——

在你的控制器中,例如
RegistrationController.php

// ...
class RegistrationController extends Controller
{    
    public function behaviors()
    {
        return [
            'access' => [
                'class' => AccessControl::className(),                
                'rules' => [
                    [
                        'actions' => ['login', 'signup'], // those action only which guest (?) user can access
                        'allow' => true,
                        'roles' => ['?'],                        
                    ],
                    [
                        'actions' => ['home', 'update'],  // those action only which authorized (@) user can access
                        'allow' => true,
                        'roles' => ['@'],
                    ],
                ],
            ],
            'verbs' => [
                'class' => VerbFilter::className(),
                'actions' => [
                    'logout' => ['post'],
                ],
            ],
        ];
    }

    // ...

在您的
app/config/web.php
(用于基本模板)或
app/frontend/config/main.php
(用于高级模板)——

在你的控制器中,例如
RegistrationController.php

// ...
class RegistrationController extends Controller
{    
    public function behaviors()
    {
        return [
            'access' => [
                'class' => AccessControl::className(),                
                'rules' => [
                    [
                        'actions' => ['login', 'signup'], // those action only which guest (?) user can access
                        'allow' => true,
                        'roles' => ['?'],                        
                    ],
                    [
                        'actions' => ['home', 'update'],  // those action only which authorized (@) user can access
                        'allow' => true,
                        'roles' => ['@'],
                    ],
                ],
            ],
            'verbs' => [
                'class' => VerbFilter::className(),
                'actions' => [
                    'logout' => ['post'],
                ],
            ],
        ];
    }

    // ...

好的,我解决了,但是facebook登录怎么办?我编辑了我的帖子,在那里我显示了Yuo功能,使用facebook登录不起作用facebook登录有什么问题,请提供详细信息OK我解决了,但是facebook登录怎么办?我编辑了我的帖子,在那里我显示了Yuo功能,用facebook登录不起作用facebook登录有什么问题,请提供详细信息