2016-08-04 03:37:21 +05:30
|
|
|
<?php
|
2019-12-02 23:44:40 +05:30
|
|
|
declare(strict_types=1);
|
|
|
|
|
2018-02-28 03:57:35 +05:30
|
|
|
namespace api\modules\oauth\controllers;
|
2016-08-04 03:37:21 +05:30
|
|
|
|
2018-02-28 03:57:35 +05:30
|
|
|
use api\controllers\Controller;
|
|
|
|
use api\modules\oauth\models\IdentityInfo;
|
2019-08-02 05:59:20 +05:30
|
|
|
use api\rbac\Permissions as P;
|
2016-08-04 03:37:21 +05:30
|
|
|
use Yii;
|
2017-09-19 22:36:16 +05:30
|
|
|
use yii\filters\AccessControl;
|
2016-08-04 03:37:21 +05:30
|
|
|
use yii\helpers\ArrayHelper;
|
|
|
|
|
2018-02-28 03:57:35 +05:30
|
|
|
class IdentityController extends Controller {
|
2016-08-04 03:37:21 +05:30
|
|
|
|
2017-09-19 22:36:16 +05:30
|
|
|
public function behaviors(): array {
|
2018-02-28 03:57:35 +05:30
|
|
|
return ArrayHelper::merge(Controller::behaviors(), [
|
2016-08-04 03:37:21 +05:30
|
|
|
'access' => [
|
|
|
|
'class' => AccessControl::class,
|
|
|
|
'rules' => [
|
|
|
|
[
|
|
|
|
'actions' => ['index'],
|
|
|
|
'allow' => true,
|
2017-09-19 22:36:16 +05:30
|
|
|
'roles' => [P::OBTAIN_ACCOUNT_INFO],
|
2019-12-02 23:44:40 +05:30
|
|
|
'roleParams' => function(): array {
|
|
|
|
/** @var \api\components\User\IdentityInterface $identity */
|
|
|
|
$identity = Yii::$app->user->getIdentity();
|
|
|
|
$account = $identity->getAccount();
|
|
|
|
if ($account === null) {
|
|
|
|
Yii::$app->sentry->captureMessage('Unexpected lack of account', [
|
|
|
|
'identityType' => get_class($identity),
|
|
|
|
'userId' => $identity->getId(),
|
|
|
|
'assignedPermissions' => $identity->getAssignedPermissions(),
|
|
|
|
], [
|
|
|
|
'level' => 'warning',
|
|
|
|
]);
|
|
|
|
|
|
|
|
return ['accountId' => 0];
|
|
|
|
}
|
|
|
|
|
|
|
|
return ['accountId' => $account->id];
|
2017-09-19 22:36:16 +05:30
|
|
|
},
|
2016-08-04 03:37:21 +05:30
|
|
|
],
|
|
|
|
],
|
|
|
|
],
|
|
|
|
]);
|
|
|
|
}
|
|
|
|
|
2017-09-19 22:36:16 +05:30
|
|
|
public function actionIndex(): array {
|
|
|
|
/** @noinspection NullPointerExceptionInspection */
|
2018-02-28 03:57:35 +05:30
|
|
|
return (new IdentityInfo(Yii::$app->user->getIdentity()->getAccount()))->info();
|
2016-08-04 03:37:21 +05:30
|
|
|
}
|
|
|
|
|
|
|
|
}
|