yii2-usuario
yii2-usuario copied to clipboard
usuario advanced template don't allow users to view backend
What steps will reproduce the problem?
Create user, without required access right to backend pages. Use backend login.
What is the expected result?
Show error that you're not allowed to login and go back to frontend home
What do you get instead?
Backend template with menu, just none of the pages are accessible due to missing access rights.
'access' => [
'class' => AccessControl::class,
'rules' => [
[
'allow' => true,
'roles' => ['Admin'],
],
],
],
Solution can be something like.
'user' => [
'on ' . FormEvent::EVENT_BEFORE_LOGIN => function ($e) {
$e->isValid = \Da\User\Model::findByUsername($e->identity->username)->isAdmin;
if(!$e->isValid)
{
$homeUrl = \Yii::$app->urlManagerFrontend->createAbsoluteUrl(['']);
Yii::$app->session->setFlash('error', Yii::t("login","Access forbidden! Click <a href='$homeUrl'>here</a> to return to the home page."));
}
},
],
thx to @Eseperio ;) https://github.com/dektrium/yii2-user/issues/967