2016-12-11 17:07:55 +05:30
|
|
|
<?php
|
|
|
|
namespace api\modules\internal\controllers;
|
|
|
|
|
|
|
|
use api\controllers\Controller;
|
2019-08-02 05:59:20 +05:30
|
|
|
use api\rbac\Permissions as P;
|
2016-12-16 14:06:21 +05:30
|
|
|
use common\models\Account;
|
2017-09-19 22:36:16 +05:30
|
|
|
use yii\filters\AccessControl;
|
2016-12-11 17:07:55 +05:30
|
|
|
use yii\helpers\ArrayHelper;
|
2017-04-03 17:24:33 +05:30
|
|
|
use yii\web\BadRequestHttpException;
|
2016-12-16 14:06:21 +05:30
|
|
|
use yii\web\NotFoundHttpException;
|
2016-12-11 17:07:55 +05:30
|
|
|
|
|
|
|
class AccountsController extends Controller {
|
|
|
|
|
2017-09-19 22:36:16 +05:30
|
|
|
public function behaviors(): array {
|
2016-12-11 17:07:55 +05:30
|
|
|
return ArrayHelper::merge(parent::behaviors(), [
|
|
|
|
'access' => [
|
|
|
|
'class' => AccessControl::class,
|
|
|
|
'rules' => [
|
2017-04-03 17:24:33 +05:30
|
|
|
[
|
|
|
|
'actions' => ['info'],
|
|
|
|
'allow' => true,
|
2017-09-19 22:36:16 +05:30
|
|
|
'roles' => [P::OBTAIN_EXTENDED_ACCOUNT_INFO],
|
|
|
|
'roleParams' => function() {
|
|
|
|
return [
|
|
|
|
'accountId' => 0,
|
|
|
|
];
|
|
|
|
},
|
2017-04-03 17:24:33 +05:30
|
|
|
],
|
2016-12-11 17:07:55 +05:30
|
|
|
],
|
|
|
|
],
|
|
|
|
]);
|
|
|
|
}
|
|
|
|
|
2017-09-19 22:36:16 +05:30
|
|
|
public function verbs(): array {
|
2017-01-05 03:27:04 +05:30
|
|
|
return [
|
2017-04-03 17:24:33 +05:30
|
|
|
'info' => ['GET'],
|
2017-01-05 03:27:04 +05:30
|
|
|
];
|
|
|
|
}
|
|
|
|
|
2017-04-03 17:24:33 +05:30
|
|
|
public function actionInfo(int $id = null, string $username = null, string $uuid = null) {
|
|
|
|
if ($id !== null) {
|
|
|
|
$account = Account::findOne($id);
|
|
|
|
} elseif ($username !== null) {
|
|
|
|
$account = Account::findOne(['username' => $username]);
|
|
|
|
} elseif ($uuid !== null) {
|
|
|
|
$account = Account::findOne(['uuid' => $uuid]);
|
|
|
|
} else {
|
|
|
|
throw new BadRequestHttpException('One of the required get params must be presented.');
|
|
|
|
}
|
|
|
|
|
|
|
|
if ($account === null) {
|
|
|
|
throw new NotFoundHttpException('User by provided param not found.');
|
|
|
|
}
|
|
|
|
|
|
|
|
return [
|
|
|
|
'id' => $account->id,
|
|
|
|
'uuid' => $account->uuid,
|
|
|
|
'email' => $account->email,
|
|
|
|
'username' => $account->username,
|
|
|
|
];
|
|
|
|
}
|
|
|
|
|
2016-12-11 17:07:55 +05:30
|
|
|
}
|