I have a problem, already validate the admin user and the normal user. And I have it that if admin user is redirected to the backend (index). But when it is redirected to the index does not keep the session already started in the frontend and when it is in the backend it asks to login again.
My fontend/config/main.php
'components' => [
'request' => [
'cookieValidationKey' => '2PvWor_Yq5KViA62RaXNA3RcKqFMyL6T',
'csrfParam' => '_csrf-frontend',
],
'user' => [
'identityClass' => 'common\models\User',
'enableAutoLogin' => true,
'identityCookie' => ['name' => '_identity-frontend', 'httpOnly' => true],
],
'session' => [
// this is the name of the session cookie used for login on the frontend
'name' => 'advanced-frontend',
],
],
My backend/config/main.php
'components' => [
'request' => [
'cookieValidationKey' => '-Pv9GFzUbC0eko0_jUJ9P3raNs0T_W7W',
'csrfParam' => '_csrf-backend',
],
'user' => [
'identityClass' => 'common\models\User',
'enableAutoLogin' => true,
'identityCookie' => ['name' => '_identity-backend', 'httpOnly' => true],
],
'session' => [
// this is the name of the session cookie used for login on the backend
'name' => 'advanced-backend',
],
],
My actionLogin in Frontend
public function actionLogin(){
$this->layout="main-form";
$model = new \common\models\LoginForm();
if (!Yii::$app->user->isGuest) {
return $this->goHome();
}
if ($model->load(Yii::$app->request->post()) && $model->login()) {
if(User::isUserAdmin()){
return $this->redirect(Yii::$app->params['urlBackend'].'/site/index'); // redirect backend
}else{
return $this->render('index'); // redirect frontend
}
}else{
return $this->render('login', [
'model' => $model,
]);
}
}
Finally My actionIndex in backend
public function actionIndex()
{
if(Yii::$app->user->isGuest){
return $this->redirect(Yii::$app->params['urlFrontend'].'/site/login');
}
return $this->render('index');
}