-
Notifications
You must be signed in to change notification settings - Fork 142
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
How to permit backend only to administrators? #442
Comments
What I've done to have the same:
Maybe there is a better approach and will be glad to see another solutions. P.S. the code does not formats well, but you could figure out. |
Thank you @EndErr for that. Seems to work. Just the Little optimization that hopefully is the same as your suggestion: 'controllerMap' => [
'security' => [
'class' => SecurityController::class,
'on ' . FormEvent::EVENT_AFTER_LOGIN => function (FormEvent $event) {
$roles = Yii::$app->authManager->getRolesByUser(Yii::$app->user->getId());
if (array_key_exists(Yii::$app->modules['user']->administratorPermissionName, $roles)) {
Yii::$app->controller->redirect(Yii::$app->urlManager->createUrl(''));
Yii::$app->end();
}
Yii::$app->user->logout(true);
Yii::$app->controller->redirect(Yii::$app->urlManager->createUrl('/user/security/login'));
Yii::$app->end();
}
],
], btw: In order to format code, using syntax highlighting for php, use this in your postings (first and last line are essential):
|
for some days after a update any thoughts? |
What update? Is it related to this bug? |
not sure, just did a |
Using the yii2-app-advanced application template, I'd like to allow the whole backend only to administrators. I have secured the backend now, so that only the login is possible (no password reset, no registration, ...). For that I'm using the this application configuration (backend/config/main.php), so I don't have to declare the rules in each controller:
Changing the last rule to
'roles' => ['administrator']
should do it. However, other users are still able to to log in though, but each page shows a 403 error page.How can I do it the right way, so that only administrators can log in. Is it necessary to override the default SecurityController? Is there a better approach than the global access control configuration?
The text was updated successfully, but these errors were encountered: