Add session history

This commit is contained in:
maranqz
2019-11-14 20:55:18 +03:00
parent 8dea2d8078
commit be2b495c9e
26 changed files with 1639 additions and 4 deletions

View File

@ -0,0 +1,68 @@
<?php
/*
* This file is part of the 2amigos/yii2-usuario project.
*
* (c) 2amigOS! <http://2amigos.us/>
*
* For the full copyright and license information, please view
* the LICENSE file that was distributed with this source code.
*/
use Da\User\Widget\SessionStatusWidget;
use yii\helpers\Html;
use yii\grid\GridView;
use yii\widgets\Pjax;
use Da\User\Model\SessionHistory;
use Da\User\Search\SessionHistorySearch;
use yii\web\View;
use yii\data\ActiveDataProvider;
/**
* @var $this View
* @var $searchModel SessionHistorySearch
* @var $dataProvider ActiveDataProvider
*/
?>
<?php $this->beginContent('@Da/User/resources/views/admin/update.php', ['user' => $user]) ?>
<div class="row">
<div class="col-xs-12">
<?= Html::a(
Yii::t('usuario', 'Terminate all sessions'),
['/user/admin/terminate-sessions', 'id' => $user->id],
[
'class' => 'btn btn-danger btn-xs pull-right',
'data-method' => 'post'
]
) ?>
</div>
</div>
<hr>
<?php Pjax::begin(); ?>
<?= GridView::widget([
'dataProvider' => $dataProvider,
'filterModel' => $searchModel,
'columns' => [
'user_agent',
'ip',
[
'contentOptions' => [
'class' => 'text-nowrap',
],
'label' => Yii::t('usuario', 'Status'),
'value' => function (SessionHistory $model) {
return SessionStatusWidget::widget(['model' => $model]);
},
],
[
'attribute' => 'updated_at',
'format' => 'datetime'
],
],
]); ?>
<?php Pjax::end(); ?>
<?php $this->endContent() ?>

4
src/User/resources/views/admin/update.php Normal file → Executable file
View File

@ -67,6 +67,10 @@ $this->params['breadcrumbs'][] = $this->title;
'label' => Yii::t('usuario', 'Assignments'),
'url' => ['/user/admin/assignments', 'id' => $user->id],
],
[
'label' => Yii::t('usuario', 'Session history'),
'url' => ['/user/admin/session-history', 'id' => $user->id],
],
'<hr>',
[
'label' => Yii::t('usuario', 'Confirm'),

4
src/User/resources/views/settings/_menu.php Normal file → Executable file
View File

@ -41,6 +41,10 @@ $networksVisible = count(Yii::$app->authClientCollection->clients) > 0;
'items' => [
['label' => Yii::t('usuario', 'Profile'), 'url' => ['/user/settings/profile']],
['label' => Yii::t('usuario', 'Account'), 'url' => ['/user/settings/account']],
[
'label' => Yii::t('usuario', 'Session history'),
'url' => ['/user/settings/session-history']
],
['label' => Yii::t('usuario', 'Privacy'),
'url' => ['/user/settings/privacy'],
'visible' => $module->enableGdprCompliance

View File

@ -0,0 +1,79 @@
<?php
/*
* This file is part of the 2amigos/yii2-usuario project.
*
* (c) 2amigOS! <http://2amigos.us/>
*
* For the full copyright and license information, please view
* the LICENSE file that was distributed with this source code.
*/
use yii\helpers\Html;
use yii\grid\GridView;
use yii\widgets\Pjax;
use Da\User\Model\SessionHistory;
use Da\User\Search\SessionHistorySearch;
use yii\web\View;
use yii\data\ActiveDataProvider;
use Da\User\Widget\SessionStatusWidget;
/**
* @var $this View
* @var $searchModel SessionHistorySearch
* @var $dataProvider ActiveDataProvider
*/
$this->title = Yii::t('usuario', 'Session history');
$this->params['breadcrumbs'][] = $this->title;
?>
<?= $this->render('/shared/_alert', ['module' => Yii::$app->getModule('user')]) ?>
<div class="row">
<div class="col-md-3">
<?= $this->render('/settings/_menu') ?>
</div>
<div class="col-md-9">
<div class="panel panel-default">
<div class="panel-heading">
<?= Html::encode($this->title) ?>
<?= Html::a(
Yii::t('usuario', 'Terminate all sessions'),
['/user/settings/terminate-sessions'],
[
'class' => 'btn btn-danger btn-xs pull-right',
'data-method' => 'post'
]
) ?>
</div>
<div class="panel-body">
<?php Pjax::begin(); ?>
<?= GridView::widget([
'dataProvider' => $dataProvider,
'filterModel' => $searchModel,
'columns' => [
'user_agent',
'ip',
[
'contentOptions' => [
'class' => 'text-nowrap',
],
'label' => Yii::t('usuario', 'Status'),
'value' => function (SessionHistory $model) {
return SessionStatusWidget::widget(['model' => $model]);
},
],
[
'attribute' => 'updated_at',
'format' => 'datetime'
],
],
]); ?>
<?php Pjax::end(); ?>
</div>
</div>
</div>
</div>