This commit is contained in:
Lorenzo Milesi
2022-08-11 09:08:25 +02:00
51 changed files with 2004 additions and 40 deletions

39
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' => [
@ -101,6 +104,11 @@ class AdminController extends Controller
'actions' => ['switch-identity'],
'roles' => ['@'],
],
[
'allow' => $this->getModule()->enableSessionHistory,
'actions' => ['session-history', 'terminate-sessions'],
'roles' => ['admin'],
],
[
'allow' => true,
'roles' => ['admin'],
@ -346,4 +354,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'));
}
}

93
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,7 @@ class SettingsController extends Controller
'delete',
'two-factor',
'two-factor-enable',
'two-factor-disable'
'two-factor-disable',
],
'roles' => ['@'],
],
@ -119,7 +122,12 @@ class SettingsController extends Controller
'allow' => true,
'actions' => ['confirm'],
'roles' => ['?', '@'],
]
],
[
'allow' => $this->getModule()->enableSessionHistory,
'actions' => ['session-history', 'terminate-sessions'],
'roles' => ['@'],
],
],
],
];
@ -139,9 +147,9 @@ class SettingsController extends Controller
}
/**
*
*
* @var ProfileEvent $event
*
* @var ProfileEvent $event
*/
$event = $this->make(ProfileEvent::class, [$profile]);
@ -175,7 +183,8 @@ class SettingsController extends Controller
throw new NotFoundHttpException();
}
return $this->render(
'privacy', [
'privacy',
[
'module' => $this->module
]
);
@ -196,9 +205,9 @@ class SettingsController extends Controller
throw new NotFoundHttpException();
}
/**
*
*
* @var GdprDeleteForm $form
*
* @var GdprDeleteForm $form
*/
$form = $this->make(GdprDeleteForm::class);
@ -249,7 +258,8 @@ class SettingsController extends Controller
}
return $this->render(
'gdpr-delete', [
'gdpr-delete',
[
'model' => $form,
]
);
@ -258,9 +268,9 @@ class SettingsController extends Controller
public function actionGdprConsent()
{
/**
*
*
* @var User $user
*
* @var User $user
*/
$user = Yii::$app->user->identity;
if ($user->gdpr_consent) {
@ -270,7 +280,9 @@ class SettingsController extends Controller
$model->addRule('gdpr_consent', 'boolean');
$model->addRule('gdpr_consent', 'default', ['value' => 0, 'skipOnEmpty' => false]);
$model->addRule(
'gdpr_consent', 'compare', [
'gdpr_consent',
'compare',
[
'compareValue' => true,
'message' => Yii::t('usuario', 'Your consent is required to work with this site'),
'when' => function () {
@ -289,7 +301,8 @@ class SettingsController extends Controller
}
return $this->render(
'gdpr-consent', [
'gdpr-consent',
[
'model' => $model,
'gdpr_consent_hint' => $this->module->getConsentMessage(),
]
@ -345,9 +358,9 @@ class SettingsController extends Controller
public function actionAccount()
{
/**
*
*
*
* @var SettingsForm $form
* @var SettingsForm $form
*/
$form = $this->make(SettingsForm::class);
$event = $this->make(UserEvent::class, [$form->getUser()]);
@ -416,9 +429,9 @@ class SettingsController extends Controller
}
/**
*
*
* @var User $user
*
* @var User $user
*/
$user = Yii::$app->user->identity;
$event = $this->make(UserEvent::class, [$user]);
@ -436,9 +449,9 @@ class SettingsController extends Controller
public function actionTwoFactor($id)
{
/**
*
*
* @var User $user
*
* @var User $user
*/
$user = $this->userQuery->whereId($id)->one();
@ -456,9 +469,9 @@ class SettingsController extends Controller
Yii::$app->response->format = Response::FORMAT_JSON;
/**
*
*
* @var User $user
*
* @var User $user
*/
$user = $this->userQuery->whereId($id)->one();
@ -487,12 +500,12 @@ class SettingsController extends Controller
public function actionTwoFactorDisable($id)
{
/**
*
*
* @var User $user
*
* @var User $user
*/
$user = $this->userQuery->whereId($id)->one();
if (null === $user) {
throw new NotFoundHttpException();
}
@ -511,7 +524,33 @@ class SettingsController extends Controller
}
/**
* @param $id
* 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
* @throws NotFoundHttpException
* @throws \Exception
@ -521,9 +560,9 @@ class SettingsController extends Controller
protected function disconnectSocialNetwork($id)
{
/**
*
*
* @var SocialNetworkAccount $account
*
* @var SocialNetworkAccount $account
*/
$account = $this->socialNetworkAccountQuery->whereId($id)->one();