mirror of
https://github.com/elyby/accounts.git
synced 2025-05-31 14:11:46 +05:30
Добавлен внутренний API для получения информации об аккаунте
This commit is contained in:
@ -9,6 +9,7 @@ use common\models\Account;
|
||||
use common\models\OauthScope as S;
|
||||
use Yii;
|
||||
use yii\helpers\ArrayHelper;
|
||||
use yii\web\BadRequestHttpException;
|
||||
use yii\web\NotFoundHttpException;
|
||||
|
||||
class AccountsController extends Controller {
|
||||
@ -26,6 +27,11 @@ class AccountsController extends Controller {
|
||||
'allow' => true,
|
||||
'roles' => [S::ACCOUNT_BLOCK],
|
||||
],
|
||||
[
|
||||
'actions' => ['info'],
|
||||
'allow' => true,
|
||||
'roles' => [S::INTERNAL_ACCOUNT_INFO],
|
||||
],
|
||||
],
|
||||
],
|
||||
]);
|
||||
@ -34,6 +40,7 @@ class AccountsController extends Controller {
|
||||
public function verbs() {
|
||||
return [
|
||||
'ban' => ['POST', 'DELETE'],
|
||||
'info' => ['GET'],
|
||||
];
|
||||
}
|
||||
|
||||
@ -46,6 +53,29 @@ class AccountsController extends Controller {
|
||||
}
|
||||
}
|
||||
|
||||
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,
|
||||
];
|
||||
}
|
||||
|
||||
private function banAccount(Account $account) {
|
||||
$model = new BanForm($account);
|
||||
$model->load(Yii::$app->request->post());
|
||||
|
Reference in New Issue
Block a user