mirror of
https://github.com/elyby/accounts.git
synced 2024-12-27 07:30:18 +05:30
79bbc12206
Добавлен client_credentials grant для oAuth Рефакторинг структуры OauthScopes чтобы можно было разделить владельца прав на пользовательские и общие (машинные) Исправлена стилистика кода, внедряются фишки PHP 7.1
59 lines
1.5 KiB
PHP
59 lines
1.5 KiB
PHP
<?php
|
|
namespace api\modules\internal\controllers;
|
|
|
|
use api\components\ApiUser\AccessControl;
|
|
use api\controllers\Controller;
|
|
use api\modules\internal\models\BanForm;
|
|
use common\models\Account;
|
|
use common\models\OauthScope as S;
|
|
use Yii;
|
|
use yii\helpers\ArrayHelper;
|
|
use yii\web\NotFoundHttpException;
|
|
|
|
class AccountsController extends Controller {
|
|
|
|
public function behaviors() {
|
|
return ArrayHelper::merge(parent::behaviors(), [
|
|
'authenticator' => [
|
|
'user' => Yii::$app->apiUser,
|
|
],
|
|
'access' => [
|
|
'class' => AccessControl::class,
|
|
'rules' => [
|
|
[
|
|
'actions' => ['ban'],
|
|
'allow' => true,
|
|
'roles' => [S::ACCOUNT_BLOCK],
|
|
],
|
|
],
|
|
],
|
|
]);
|
|
}
|
|
|
|
public function actionBan(int $accountId) {
|
|
$account = $this->findAccount($accountId);
|
|
$model = new BanForm($account);
|
|
$model->load(Yii::$app->request->post());
|
|
if (!$model->ban()) {
|
|
return [
|
|
'success' => false,
|
|
'errors' => $model->getFirstErrors(),
|
|
];
|
|
}
|
|
|
|
return [
|
|
'success' => true,
|
|
];
|
|
}
|
|
|
|
private function findAccount(int $accountId): Account {
|
|
$account = Account::findOne($accountId);
|
|
if ($account === null) {
|
|
throw new NotFoundHttpException();
|
|
}
|
|
|
|
return $account;
|
|
}
|
|
|
|
}
|