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

34
src/User/Controller/AdminController.php Normal file → Executable file
View File

@ -17,9 +17,11 @@ use Da\User\Filter\AccessRuleFilter;
use Da\User\Model\Profile;
use Da\User\Model\User;
use Da\User\Query\UserQuery;
use Da\User\Search\SessionHistorySearch;
use Da\User\Search\UserSearch;
use Da\User\Service\PasswordExpireService;
use Da\User\Service\PasswordRecoveryService;
use Da\User\Service\SessionHistory\TerminateUserSessionsService;
use Da\User\Service\SwitchIdentityService;
use Da\User\Service\UserBlockService;
use Da\User\Service\UserConfirmationService;
@ -66,7 +68,7 @@ class AdminController extends Controller
*/
public function beforeAction($action)
{
if (in_array($action->id, ['index', 'update', 'update-profile', 'info', 'assignments'], true)) {
if (in_array($action->id, ['index', 'update', 'update-profile', 'info', 'assignments', 'session-history'], true)) {
Url::remember('', 'actions-redirect');
}
@ -88,6 +90,7 @@ class AdminController extends Controller
'switch-identity' => ['post'],
'password-reset' => ['post'],
'force-password-change' => ['post'],
'terminate-sessions' => ['post'],
],
],
'access' => [
@ -346,4 +349,33 @@ class AdminController extends Controller
}
$this->redirect(['index']);
}
/**
* Display list session history
*/
public function actionSessionHistory($id)
{
$searchModel = new SessionHistorySearch([
'user_id' => $id,
]);
$dataProvider = $searchModel->search(Yii::$app->request->queryParams);
$user = $this->userQuery->where(['id' => $id])->one();
return $this->render('_session-history', [
'searchModel' => $searchModel,
'dataProvider' => $dataProvider,
'user' => $user,
]);
}
/**
* Terminate all session user
*/
public function actionTerminateSessions($id)
{
$this->make(TerminateUserSessionsService::class, [$id])->run();
return $this->redirect(Url::previous('actions-redirect'));
}
}

35
src/User/Controller/SettingsController.php Normal file → Executable file
View File

@ -26,7 +26,9 @@ use Da\User\Module;
use Da\User\Query\ProfileQuery;
use Da\User\Query\SocialNetworkAccountQuery;
use Da\User\Query\UserQuery;
use Da\User\Search\SessionHistorySearch;
use Da\User\Service\EmailChangeService;
use Da\User\Service\SessionHistory\TerminateUserSessionsService;
use Da\User\Service\TwoFactorQrCodeUriGeneratorService;
use Da\User\Traits\ContainerAwareTrait;
use Da\User\Traits\ModuleAwareTrait;
@ -91,7 +93,8 @@ class SettingsController extends Controller
'actions' => [
'disconnect' => ['post'],
'delete' => ['post'],
'two-factor-disable' => ['post']
'two-factor-disable' => ['post'],
'terminate-sessions' => ['post'],
],
],
'access' => [
@ -111,7 +114,9 @@ class SettingsController extends Controller
'delete',
'two-factor',
'two-factor-enable',
'two-factor-disable'
'two-factor-disable',
'session-history',
'terminate-sessions',
],
'roles' => ['@'],
],
@ -463,6 +468,32 @@ class SettingsController extends Controller
$this->redirect(['account']);
}
/**
* Display list session history.
*/
public function actionSessionHistory()
{
$searchModel = new SessionHistorySearch([
'user_id' => Yii::$app->user->id,
]);
$dataProvider = $searchModel->search(Yii::$app->request->queryParams);
return $this->render('session-history', [
'searchModel' => $searchModel,
'dataProvider' => $dataProvider,
]);
}
/**
* Terminate all session user
*/
public function actionTerminateSessions()
{
$this->make(TerminateUserSessionsService::class, [Yii::$app->user->id])->run();
return $this->redirect(['session-history']);
}
/**
* @param $id
* @throws ForbiddenHttpException