Answer the question
In order to leave comments, you need to log in
How to prevent a user from logging into the admin panel?
Such a question, if I close the user's access to the admin panel like this in the Site controller
'access' => [
'class' => AccessControl::className(),
'rules' => [
[
'actions' => ['login', 'error'],
'allow' => true,
],
[
'actions' => ['logout', 'index'],
'allow' => true,
'roles' => ['admin'],
],
],
],
'as access' => [
'class' => 'yii\filters\AccessControl',
'except' => ['site/login', 'site/error'],
'rules' => [
[
'allow' => true,
'roles' => ['admin'],
],
],
],
Answer the question
In order to leave comments, you need to log in
In the controller that will check the authorization, immediately add a condition for checking the access level.
An example of a possible implementation on the first Yii
public function actionLogin()
{
if (!Yii::app()->user->isGuest)
{
$role = Yii::app()->user->role;
if ($role)
{
$this->redirect(Yii::app()->params['modules_default_pages'][$role]);
}
}
$model = new LoginForm;
// if it is ajax validation request
if (isset($_POST['ajax']) && $_POST['ajax'] === 'login-form')
{
echo CActiveForm::validate($model);
Yii::app()->end();
}
// collect user input data
if (isset($_POST['LoginForm']))
{
$model->attributes = $_POST['LoginForm'];
if ($model->validate() && $model->login())
$this->redirect(Yii::app()->user->returnUrl);
}
$this->render('login', array('model' => $model));
}
will see the main and menus of the admin panel,
Didn't find what you were looking for?
Ask your questionAsk a Question
731 491 924 answers to any question