-1

My access control code is not working on the modules default controller, but on all other pages it is working fine. Any idea what i am doing wrong?

EDIT: What is happening is : ../web/mymodule does not redirect but ../web/mymodule/mycontroller does. Also if o try ../web/mymodule/default it does not work also.

EDIT 2: Solved. The problem was with the public function beforeAction($action)

public function behaviors()
{
    return [
        'verbs' => [
            'class' => VerbFilter::className(),
            'actions' => [
                'delete' => ['post'],
            ],
        ],
        'access' => [
            'class' => AccessControl::className(),
            'rules' => [
                [
                    'allow' => true,
                    'roles' => ['@'],
                ],
            ],
        ],
    ];
}
rob180
  • 901
  • 1
  • 9
  • 29
  • 1
    What happens? Is there an error? Simply not doing anything? – Blizz Jun 02 '15 at 08:44
  • Any one can access the page. it does not redirect to login. – rob180 Jun 02 '15 at 09:36
  • And you are sure that you actually have logged out right? A `@` means: the current user is not a guest. And `guest` means: `\Yii::$app->user->identity === null;`, so not a user with ID = 0 – Blizz Jun 02 '15 at 09:41
  • i went to private navigation and only module default controller can be seen, all other redirect correctly. so i don't understand what you mean @Blizz – rob180 Jun 02 '15 at 09:47
  • You should share specifictly how you solved the problem, you come here for help to at least you can is provide a answer, this way the community help someone else. – Alejandro Mar 04 '20 at 04:45

1 Answers1

0

Seems you don't control the action. Try this in SiteController:

    return [
        'access' => [
            'class' => AccessControl::className(),
            'only' => ['logout', 'signup'],
            'rules' => [
                [
                    'actions' => ['signup'],
                    'allow' => true,
                    'roles' => ['?'],
                ],
                [
                    'actions' => ['logout'],
                    'allow' => true,
                    'roles' => ['@'],
                ],
            ],
        ],
        ],
        'verbs' => [
            ..............
        ],
    ];
ScaisEdge
  • 131,976
  • 10
  • 91
  • 107
  • Still does not work. All other indexes are redirect i just don't understand why the `defaultController index` does not. – rob180 Jun 02 '15 at 11:01
  • I already found the issue. Was in the `public function beforeAction($action)`. Thank you for the help anyway. – rob180 Jun 02 '15 at 11:17