1

An Error occurred while handling another error:

exception 'yii\web\ForbiddenHttpException' with message 'Login Required' in C:\wamp\www\k\kometonline\vendor\yiisoft\yii2\web\User.php:431

Am getting this error after installing RBAC in backend admin login page (site.com/backend/web/site/login). Whats the main cause of this problem. I don't know what code to post. Please comment below If you need any code. Thanks in advance.

Insane Skull
  • 9,220
  • 9
  • 44
  • 63
Kartz
  • 533
  • 3
  • 8
  • 22

2 Answers2

1

I encountered the same error while installing RBAC in backend admin login page while following this tutorial: RBAC Super Simple with Admin and User

You may try doing the changes you made at the frontend login SiteController and see if works. The difference between these two SiteControllers is that the frontend already uses access rules in its behavior method.

From there you can compare the SiteControllers at backend and frontend and see what makes it work. In my case I simply added one line

'only' => ['logout'],

just below

'class' => AccessControl::className(),

and it worked!

rob006
  • 21,383
  • 5
  • 53
  • 74
0

While I know the solution worked for the OP and is a few years old, I wanted to post how I solved this for myself, in the hope of offering an alternate solution.

In my case, I specified the following actions

'rules' => [
    [
        'actions' => ['logout', 'index',],
        'allow' => true,
        'roles' => ['@'],
    ],
        

This specified that the index and logout was protected by a password, The

*"'roles' => ['@']"* 

say that only authenticated users can invoke these actions.

Therefore, when my application restarted, it tried to direct to the login action and error presented. I solved this by specifying a rule for non logged in users (a.k.a guests) by specifying the role

*"'roles' => ['?']"* 

My behavior method therefore changed to

public function behaviors()
{
    return [
        'access' => [
            'class' => AccessControl::className(),
            'rules' => [
                [
                    'actions' => ['logout', 'index',],
                    'allow' => true,
                    'roles' => ['@'],
                ],
                [
                    'actions' => ['login'],
                    'allow' => true,
                    'roles' => ['?'],
                ],
            ],
        ],
    ];
}
crafter
  • 6,246
  • 1
  • 34
  • 46