I used Yii2 advanced. Everyhting is working well but only logout in my admin panel do not working correctly. When i click Logout, it is render me to index.php and do not log me out, second click ot log out it render me to login.php , but when i try to connect to admin part, actually i am still logged ... and if i wait 15-20 sek it log me out and rend me to login.php... i really dont understant wants going on ... Here is my action:
<li class="dropdown menu-merge">
<a href="#" class="dropdown-toggle fw600 p15" data-toggle="dropdown">
<span class="hidden-xs pl15"><?php echo Yii::t('app', 'Hi'); ?>, <?php echo Yii::$app->user->identity->username; ?></span>
<span class="caret caret-tp hidden-xs"></span>
</a>
<ul class="dropdown-menu list-group dropdown-persist w250" role="menu">
<li class="dropdown-footer">
<a href="/admin/user/settings/profile" class="">
<span class="glyphicons glyphicons-user"></span> <?php echo Yii::t('app', 'Profile'); ?> </a>
</li>
<li class="dropdown-footer">
<a>
<?php
echo Html::beginForm(['/site/logout'], 'post')
. Html::submitButton(
'<span class="fa fa-power-off pr5"></span>' . Yii::t('app', 'Logout'), ['class' => 'btn-link']
)
. Html::endForm()
?>
</a>
</li>
</ul>
</li>
here is the action
public function actionLogout() {
Yii::$app->user->logout();
return $this->goHome();
}
settings in my behaviors action:
public function behaviors() {
if (Yii::$app->user->identity) {
return [
'access' => [
'class' => AccessControl::className(),
'ruleConfig' => [
'class' => AccessRule::className(),
],
'rules' => [
[
'allow' => true,
'roles' => ['SuperAdmin', 'Admin'],
],
[
'actions' => ['selectaddress', 'addproductreview', 'clearallspecs', 'addincomparelist', 'makeexpressorder', 'buyproductwithqty', 'loadcolorgallery', 'drawgraph', 'addproductcomment',
'addfornewsletter', 'setspecval', 'addrating', 'deletefromwishlist', 'deletefromcomparelist', 'tbi', 'buyproduct', 'deleteproductfromcart', 'deleteallproducts',
'changeqtyfromcartup', 'changeqtyfromcartdown', 'addinwishlist'],
'allow' => true,
],
],
'denyCallback' => function ($rule, $action) {
return $this->redirect('/bg/user/logout');
},
],
'verbs' => [
'class' => VerbFilter::className(),
'actions' => [
'logout' => ['post'],
],
],
];
} else {
return [
'access' => [
'class' => AccessControl::className(),
'ruleConfig' => [
'class' => AccessRule::className(),
],
'rules' => [
[
'allow' => true,
'roles' => ['SuperAdmin', 'Admin'],
],
[
'actions' => ['selectaddress', 'addproductreview', 'clearallspecs', 'addincomparelist', 'makeexpressorder', 'buyproductwithqty', 'loadcolorgallery', 'drawgraph', 'addproductcomment',
'addfornewsletter', 'setspecval', 'addrating', 'deletefromwishlist', 'deletefromcomparelist', 'tbi', 'buyproduct', 'deleteproductfromcart', 'deleteallproducts',
'changeqtyfromcartup', 'changeqtyfromcartdown', 'addinwishlist'],
'allow' => true,
],
],
],
'verbs' => [
'class' => VerbFilter::className(),
'actions' => [
'logout' => ['post'],
],
],
];
}
}
use this array in rules
[
'allow' => true,
'action'=>['logout','index'],
'roles' => ['@'],
],
and use this for logout
Html::a(
'Sign out', ['/site/logout'], ['data-method' => 'post', 'class' => 'btn btn-default btn-flat']
)